4
# Required-Start: $remote_fs $network
5
# Required-Stop: $remote_fs $network
6
# Default-Start: 2 3 4 5
8
# Short-Description: Collaborative IRC helper
9
# Description: KGB is an IRC bot, helping people work together by
10
# notifying an IRC channel when a commit occures.
13
# Author: Damyan Ivanov <dmn@debian.org>
17
# PATH should only include /usr/* if it runs after the mountnfs.sh script
18
PATH=/sbin:/usr/sbin:/bin:/usr/bin
19
DESC="Collaborative IRC helper"
21
DAEMON=/usr/sbin/$NAME
22
DAEMON_ARGS="--config /etc/kgb-bot/kgb.conf"
23
PIDFILE=/var/run/kgb-bot/$NAME.pid
24
SCRIPTNAME=/etc/init.d/$NAME
26
# Exit if the package is not installed
27
[ -x "$DAEMON" ] || exit 0
30
# Read configuration variable file if it is present
31
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
33
# Load the VERBOSE setting and other rcS variables
36
# Define LSB log_* functions.
37
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
38
. /lib/lsb/init-functions
41
# create /var/run/kgb-bot and ensure right permissions
45
RUN_DIR="/var/run/$NAME"
46
[ -d "$RUN_DIR" ] || mkdir "$RUN_DIR" || return 1
48
chown "$RUN_AS":root "$RUN_DIR"
55
# create /var/log/kgb-bot.log and ensure right permissions
58
LOG=/var/log/kgb-bot.log
60
if ! test -e $LOG; then
62
chown "$RUN_AS":root $LOG
69
# Function that starts the daemon/service
74
# 0 if daemon has been started
75
# 1 if daemon was already running
76
# 2 if daemon could not be started
77
init_run_dir || return 2
78
init_log_file || return 2
79
start-stop-daemon --start --quiet --chuid $RUN_AS --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
81
start-stop-daemon --start --quiet --chuid $RUN_AS --pidfile $PIDFILE --exec $DAEMON -- \
84
# Add code here, if necessary, that waits for the process to be ready
85
# to handle requests from services started subsequently which depend
86
# on this one. As a last resort, sleep for some time.
90
# Function that stops the daemon/service
95
# 0 if daemon has been stopped
96
# 1 if daemon was already stopped
97
# 2 if daemon could not be stopped
98
# other if a failure occurred
99
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
101
[ "$RETVAL" = 2 ] && return 2
102
# Wait for children to finish too if this is a daemon that forks
103
# and if the daemon is only ever run from this initscript.
104
# If the above conditions are not satisfied then add some other code
105
# that waits for the process to drop all resources that could be
106
# needed by services started subsequently. A last resort is to
107
# sleep for some time.
108
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
109
[ "$?" = 2 ] && return 2
110
# Many daemons don't delete their pidfiles when they exit.
116
# Function that sends a SIGHUP to the daemon/service
119
init_log_file || return 2
120
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
125
# Function that sends a SIGQUIT to the daemon/service
128
init_log_file || return 2
129
start-stop-daemon --stop --signal 3 --quiet --pidfile $PIDFILE --name $NAME
135
[ "$BOT_ENABLED" != "1" ] && \
136
echo $DAEMON disabled in /etc/default/$NAME>&2 && exit 0
138
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
141
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
142
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
146
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
149
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
150
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
154
status_of_proc -p "$PIDFILE" "$DAEMON" "$NAME" && exit 0 || exit $?
157
log_daemon_msg "Reloading $DESC" "$NAME"
162
log_daemon_msg "Reloading $DESC" "$NAME"
167
log_daemon_msg "Restarting $DESC" "$NAME"
171
[ "$BOT_ENABLED" != "1" ] && \
172
echo $DAEMON disabled in /etc/default/$NAME>&2 && exit 0
176
1) log_end_msg 1 ;; # Old process is still running
177
*) log_end_msg 1 ;; # Failed to start
187
echo "Usage: $SCRIPTNAME {start|stop|restart|force-restart|reload|force-reload}" >&2
188
#echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2