4665.6.1
by John Ferlito
Add a debian init script for bzr --serve |
1 |
#! /bin/sh |
2 |
### BEGIN INIT INFO |
|
3 |
# Provides: bzr |
|
4 |
# Required-Start: $local_fs $remote_fs |
|
5 |
# Required-Stop: $local_fs $remote_fs |
|
6 |
# Default-Start: 2 3 4 5 |
|
7 |
# Default-Stop: S 0 1 6 |
|
8 |
# Short-Description: bazaar Smart Server |
|
9 |
# Description: bazaar Smart Server |
|
10 |
### END INIT INFO |
|
11 |
||
12 |
# Author: John Ferlito <johnf@inodes.org> |
|
13 |
||
14 |
# PATH should only include /usr/* if it runs after the mountnfs.sh script |
|
15 |
PATH=/usr/sbin:/usr/bin:/sbin:/bin |
|
16 |
DESC="Bazaar Smart Server" |
|
17 |
NAME=bzr |
|
18 |
DAEMON=/usr/bin/$NAME |
|
19 |
DAEMON_ARGS="" |
|
20 |
PIDFILE=/var/run/$NAME.pid |
|
21 |
SCRIPTNAME=/etc/init.d/$NAME |
|
22 |
||
23 |
USER=bzr |
|
24 |
GROUP=bzr |
|
25 |
REPO=/srv/bzr |
|
4665.7.2
by John Ferlito
init.d scrip for bzr --serve shouldn't run by default |
26 |
ENABLED=0 |
4665.6.1
by John Ferlito
Add a debian init script for bzr --serve |
27 |
|
28 |
# Exit if the package is not installed |
|
29 |
[ -x "$DAEMON" ] || exit 0 |
|
30 |
||
31 |
# Read configuration variable file if it is present |
|
32 |
[ -r /etc/default/$NAME ] && . /etc/default/$NAME |
|
33 |
||
34 |
# Load the VERBOSE setting and other rcS variables |
|
35 |
[ -f /etc/default/rcS ] && . /etc/default/rcS |
|
36 |
||
4665.7.2
by John Ferlito
init.d scrip for bzr --serve shouldn't run by default |
37 |
test "$ENABLED" != "0" || exit 0 |
38 |
||
4665.6.1
by John Ferlito
Add a debian init script for bzr --serve |
39 |
# Define LSB log_* functions. |
40 |
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present. |
|
41 |
. /lib/lsb/init-functions |
|
42 |
||
43 |
#
|
|
44 |
# Function that starts the daemon/service |
|
45 |
#
|
|
46 |
do_start() |
|
47 |
{
|
|
48 |
# Return |
|
49 |
# 0 if daemon has been started |
|
50 |
# 1 if daemon was already running |
|
51 |
# 2 if daemon could not be started |
|
52 |
start-stop-daemon --start --quiet --make-pidfile --pidfile $PIDFILE \ |
|
53 |
--chuid $USER:$GROUP --background --exec $DAEMON --test > /dev/null \ |
|
54 |
|| return 1 |
|
55 |
start-stop-daemon --start --quiet --make-pidfile --pidfile $PIDFILE \ |
|
56 |
--chuid $USER:$GROUP --background --exec $DAEMON -- \ |
|
57 |
serve $DAEMON_ARGS --directory $REPO \ |
|
58 |
|| return 2 |
|
59 |
# Add code here, if necessary, that waits for the process to be ready |
|
60 |
# to handle requests from services started subsequently which depend |
|
61 |
# on this one. As a last resort, sleep for some time. |
|
62 |
}
|
|
63 |
||
64 |
#
|
|
65 |
# Function that stops the daemon/service |
|
66 |
#
|
|
67 |
do_stop() |
|
68 |
{
|
|
69 |
# Return |
|
70 |
# 0 if daemon has been stopped |
|
71 |
# 1 if daemon was already stopped |
|
72 |
# 2 if daemon could not be stopped |
|
73 |
# other if a failure occurred |
|
74 |
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME |
|
75 |
RETVAL="$?" |
|
76 |
[ "$RETVAL" = 2 ] && return 2 |
|
77 |
# Wait for children to finish too if this is a daemon that forks |
|
78 |
# and if the daemon is only ever run from this initscript. |
|
79 |
# If the above conditions are not satisfied then add some other code |
|
80 |
# that waits for the process to drop all resources that could be |
|
81 |
# needed by services started subsequently. A last resort is to |
|
82 |
# sleep for some time. |
|
83 |
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON |
|
84 |
[ "$?" = 2 ] && return 2 |
|
85 |
# Many daemons don't delete their pidfiles when they exit. |
|
86 |
rm -f $PIDFILE |
|
87 |
return "$RETVAL" |
|
88 |
}
|
|
89 |
||
90 |
case "$1" in |
|
91 |
start) |
|
92 |
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" |
|
93 |
do_start
|
|
94 |
case "$?" in |
|
95 |
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; |
|
96 |
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; |
|
97 |
esac
|
|
98 |
;;
|
|
99 |
stop) |
|
100 |
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" |
|
101 |
do_stop
|
|
102 |
case "$?" in |
|
103 |
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; |
|
104 |
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; |
|
105 |
esac
|
|
106 |
;;
|
|
107 |
restart|force-reload) |
|
108 |
#
|
|
109 |
# If the "reload" option is implemented then remove the |
|
110 |
# 'force-reload' alias |
|
111 |
#
|
|
112 |
log_daemon_msg "Restarting $DESC" "$NAME" |
|
113 |
do_stop
|
|
114 |
case "$?" in |
|
115 |
0|1) |
|
116 |
do_start
|
|
117 |
case "$?" in |
|
118 |
0) log_end_msg 0 ;; |
|
119 |
1) log_end_msg 1 ;; # Old process is still running |
|
120 |
*) log_end_msg 1 ;; # Failed to start |
|
121 |
esac
|
|
122 |
;;
|
|
123 |
*)
|
|
124 |
# Failed to stop |
|
125 |
log_end_msg 1 |
|
126 |
;;
|
|
127 |
esac
|
|
128 |
;;
|
|
129 |
*)
|
|
130 |
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2 |
|
131 |
exit 3 |
|
132 |
;;
|
|
133 |
esac
|
|
134 |
||
135 |
:
|