Annotation of ircnowd/contrib/Debian/ngircd.init, Revision 1.1.1.1
1.1 tomglok 1: #!/bin/sh
2: #
3: # ngIRCd start and stop script for Debian-based systems
4: # Copyright 2008-2015 Alexander Barton <alex@barton.de>
5: #
6:
7: ### BEGIN INIT INFO
8: # Provides: ngircd
9: # Required-Start: $network $remote_fs
10: # Required-Stop: $network $remote_fs
11: # Should-Start: $syslog $named
12: # Should-Stop: $syslog
13: # Default-Start: 2 3 4 5
14: # Default-Stop: 0 1 6
15: # Short-Description: Next Generation IRC Server
16: # Description: IRC daemon written from scratch
17: ### END INIT INFO
18:
19: PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
20: DAEMON=/usr/sbin/ngircd
21: NAME=ngIRCd
22: DESC="IRC daemon"
23: PARAMS=""
24: STARTTIME=1
25: DIETIME=10
26:
27: test -h "$0" && me=`readlink $0` || me="$0"
28: BASENAME=`basename $me`
29:
30: test -r /etc/default/$BASENAME && . /etc/default/$BASENAME
31:
32: test -x $DAEMON || exit 5
33:
34: # LSB compatibility functions that become used if there is no local
35: # include file available.
36: log_daemon_msg() {
37: echo -n "$*"
38: }
39: log_end_msg() {
40: [ "$1" = "0" ] && echo "." || echo " failed!"
41: }
42: log_failure_msg() {
43: echo "$*"
44: }
45: log_warning_msg() {
46: log_failure_msg "$*"
47: }
48:
49: # Include LSB functions, if available:
50: test -r /lib/lsb/init-functions && . /lib/lsb/init-functions
51:
52: PIDFILE=`$DAEMON $PARAMS -t | tr -d ' ' | grep "^PidFile=" | cut -d'=' -f2`
53: [ -n "$PIDFILE" ] || PIDFILE="/var/run/ircd/ngircd.pid"
54:
55: r=3
56:
57: Check_Config()
58: {
59: # Make sure that the configuration of ngIRCd is valid:
60: $DAEMON $PARAMS --configtest >/dev/null 2>&1
61: [ $? -eq 0 ] && return 0
62: log_end_msg 1
63: log_failure_msg "Configuration of $NAME is not valid, won't (re)start!"
64: log_failure_msg "Run \"$DAEMON --configtest\" and fix it up ..."
65: exit 6
66: }
67:
68: Prepare() {
69: # Make sure the PID file directory exists and is writable:
70: user=`$DAEMON $PARAMS -t|tr -d ' '|grep "^ServerUID="|cut -d'=' -f2`
71: group=`$DAEMON $PARAMS -t|tr -d ' '|grep "^ServerGID="|cut -d'=' -f2`
72: piddir=`dirname "$PIDFILE"`
73: [ -d "$piddir" ] || mkdir -p "$piddir" 2>/dev/null
74: chown "$user:$group" "$piddir" 2>/dev/null
75: [ $? -eq 0 ] && return 0
76: log_end_msg 1
77: log_failure_msg "Failed to prepare '$piddir' for user '$user'!"
78: exit 1
79: }
80:
81: Do_Start() {
82: if Do_Status; then
83: log_end_msg 0
84: log_warning_msg "$NAME seems to be already running, nothing to do."
85: exit 0
86: fi
87: rm -f "$PIDFILE"
88: start-stop-daemon --start \
89: --quiet --exec $DAEMON -- $PARAMS
90: sleep $STARTTIME
91: Do_Status || return 7
92: return 0
93: }
94:
95: Do_Stop() {
96: if ! Do_Status; then
97: log_end_msg 0
98: log_warning_msg "$NAME seems not to be running, nothing to do."
99: exit 0
100: fi
101: Do_ForceStop
102: return $?
103: }
104:
105: Do_ForceStop() {
106: [ -e $PIDFILE ] \
107: && pidfile="--pidfile $PIDFILE" \
108: || pidfile=""
109: start-stop-daemon --stop \
110: --quiet --oknodo --exec $DAEMON $pidfile
111: for i in `seq 1 $DIETIME`; do
112: Do_Status || return 0
113: sleep 1
114: done
115: return 1
116: }
117:
118: Do_Reload() {
119: start-stop-daemon --stop --signal 1 --quiet --exec $DAEMON
120: return $?
121: }
122:
123: Do_Status() {
124: [ -e $PIDFILE ] \
125: && pidfile="--pidfile $PIDFILE" \
126: || pidfile=""
127: start-stop-daemon --stop \
128: --quiet --signal 0 --exec $DAEMON $pidfile >/dev/null
129: return $?
130: }
131:
132: case "$1" in
133: start)
134: log_daemon_msg "Starting $DESC" "$NAME"
135: Check_Config
136: Prepare
137: Do_Start; r=$?
138: log_end_msg $r
139: ;;
140: stop)
141: log_daemon_msg "Stopping $DESC" "$NAME"
142: Do_Stop; r=$?
143: log_end_msg $r
144: ;;
145: reload|force-reload)
146: log_daemon_msg "Reloading $DESC" "$NAME"
147: Check_Config
148: Do_Reload; r=$?
149: log_end_msg $r
150: ;;
151: restart)
152: log_daemon_msg "Restarting $DESC" "$NAME"
153: Check_Config
154: Prepare
155: Do_ForceStop
156: Do_Start; r=$?
157: log_end_msg $r
158: ;;
159: status)
160: log_daemon_msg "Checking for $DESC" "$NAME"
161: Do_Status; r=$?
162: log_end_msg $r
163: ;;
164: test)
165: Check_Config
166: echo "Configuration of $DAEMON seems to be ok."; r=0
167: ;;
168: *)
169: N=/etc/init.d/$NAME; r=2
170: echo "Usage: $N {start|stop|restart|reload|force-reload|status|test}" >&2
171: ;;
172: esac
173:
174: exit $r
175:
176: # -eof-
CVSweb