monotone

monotone Mtn Source Tree

Root/monotone-server.monotone.init

1#! /bin/sh
2#
3# monotone Monotone server init script.
4#
5# Author: Matthew A. Nicholson <matt@matt-land.com>.
6#
7### BEGIN INIT INFO
8# Provides: monotone
9# Required-Start: $network $remote_fs
10# Required-Stop: $network $remote_fs
11# Default-Start: 2 3 4 5
12# Default-Stop: 0 1 6
13# Short-Description: Monotone server.
14### END INIT INFO
15
16set -e
17
18PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
19DESC="Monotone Server"
20NAME=monotone
21EXECNAME=mtn
22DAEMON=/usr/bin/$EXECNAME
23PIDDIR=/var/run/$NAME
24SCRIPTNAME=/etc/init.d/$NAME
25MAINLOG=/var/log/$NAME/$EXECNAME.log
26ERRORLOG=/var/log/$NAME/error.log
27
28# defaults for /etc/default/monotone
29START=1
30ADDRESS=0.0.0.0
31MTN_HOME=/var/lib/monotone
32MTN_CONFDIR=/etc/monotone
33MTN_KEYDIR=$MTN_HOME/keys
34MTN_DB=$MTN_HOME/default.mtn
35
36# Gracefully exit if the package has been removed.
37test -x $DAEMON || exit 0
38
39# Get the logging helpers.
40. /lib/lsb/init-functions
41
42# Read config file
43if [ -r /etc/default/$NAME ]; then
44. /etc/default/$NAME
45fi
46
47PIDFILE=$PIDDIR/$EXECNAME.pid
48
49# Function that starts the daemon.
50d_start()
51{
52 if [ "$START" -ne 1 ]; then
53log_action_msg "$NAME configured in /etc/default/$NAME not to start"
54 return 0
55 fi
56
57 log_daemon_msg "Starting $DESC" "$NAME"
58
59 # If /var/run is created in tmpfs, it will be wiped of previous data
60 if [ ! -d "$PIDDIR" ]; then
61mkdir -p "$PIDDIR" && chown monotone:monotone "$PIDDIR"
62 fi
63
64 if start-stop-daemon --start --quiet --oknodo --background \
65 --pidfile $PIDFILE --exec $DAEMON --chuid monotone --chdir $MTN_HOME \
66-- \
67 --confdir=$MTN_CONFDIR --db=$MTN_DB --no-standard-rcfiles \
68--pid-file=$PIDFILE --log=$MAINLOG --dump=$ERRORLOG --timestamps \
69 --rcfile=$MTN_CONFDIR/serverrc --keydir=$MTN_KEYDIR --quiet \
70 --bind=$ADDRESS serve
71
72 then log_end_msg 0
73 else log_end_msg 1
74 fi
75}
76
77# Function that stops the daemon.
78d_stop()
79{
80 if [ "$START" -ne 1 ]; then
81 return 0
82 fi
83
84 log_daemon_msg "Stopping $DESC" "$NAME"
85 if start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE \
86 --name $EXECNAME --user monotone
87
88 then
89rm -f $PIDFILE
90log_end_msg 0
91 else
92log_end_msg 1
93 fi
94}
95
96case "$1" in
97 start)
98d_start
99;;
100 stop)
101d_stop
102;;
103 restart|force-reload)
104d_stop
105d_start
106;;
107 *)
108echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
109exit 1
110;;
111esac

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status