2003-07-09 20:23:35 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# ngIRCd start and stop script for Debian-based systems
|
2013-08-19 21:31:10 +00:00
|
|
|
# Copyright 2008-2013 Alexander Barton <alex@barton.de>
|
2003-07-09 20:23:35 +00:00
|
|
|
#
|
|
|
|
|
2006-12-26 14:43:46 +00:00
|
|
|
### BEGIN INIT INFO
|
2009-08-29 21:57:39 +00:00
|
|
|
# Provides: ngircd
|
|
|
|
# Required-Start: $network $remote_fs
|
2010-06-24 22:10:56 +00:00
|
|
|
# Required-Stop: $network $remote_fs
|
2009-03-29 14:37:06 +00:00
|
|
|
# Should-Start: $syslog $named
|
2008-05-27 23:50:18 +00:00
|
|
|
# Should-Stop: $syslog
|
2006-12-26 14:43:46 +00:00
|
|
|
# Default-Start: 2 3 4 5
|
|
|
|
# Default-Stop: 0 1 6
|
|
|
|
# Short-Description: Next Generation IRC Server
|
2009-03-29 14:37:06 +00:00
|
|
|
# Description: IRC daemon written from scratch
|
2006-12-26 14:43:46 +00:00
|
|
|
### END INIT INFO
|
|
|
|
|
2003-07-09 20:23:35 +00:00
|
|
|
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
|
|
|
|
DAEMON=/usr/sbin/ngircd
|
|
|
|
NAME=ngIRCd
|
|
|
|
DESC="IRC daemon"
|
|
|
|
PARAMS=""
|
2009-03-29 14:37:06 +00:00
|
|
|
STARTTIME=1
|
|
|
|
DIETIME=10
|
|
|
|
|
2005-07-26 19:37:18 +00:00
|
|
|
test -h "$0" && me=`readlink $0` || me="$0"
|
|
|
|
BASENAME=`basename $me`
|
2005-06-01 21:51:11 +00:00
|
|
|
|
2008-05-27 23:50:18 +00:00
|
|
|
test -r /etc/default/$BASENAME && . /etc/default/$BASENAME
|
2003-07-09 20:23:35 +00:00
|
|
|
|
2013-08-19 21:31:10 +00:00
|
|
|
test -x $DAEMON || exit 5
|
|
|
|
|
2008-10-03 14:43:54 +00:00
|
|
|
# LSB compatibility functions that become used if there is no local
|
|
|
|
# include file available.
|
2008-05-27 23:50:18 +00:00
|
|
|
log_daemon_msg() {
|
|
|
|
echo -n "$*"
|
|
|
|
}
|
|
|
|
log_end_msg() {
|
|
|
|
[ "$1" == "0" ] && echo "." || echo " failed!"
|
|
|
|
}
|
|
|
|
log_failure_msg() {
|
|
|
|
echo "$*"
|
|
|
|
}
|
2009-03-29 14:37:06 +00:00
|
|
|
log_warning_msg() {
|
|
|
|
log_failure_msg "$*"
|
|
|
|
}
|
2008-05-27 23:50:18 +00:00
|
|
|
|
2008-10-03 14:43:54 +00:00
|
|
|
# Include LSB functions, if available:
|
2008-05-27 23:50:18 +00:00
|
|
|
test -r /lib/lsb/init-functions && . /lib/lsb/init-functions
|
|
|
|
|
2009-03-29 14:37:06 +00:00
|
|
|
PIDFILE=`$DAEMON $PARAMS -t | tr -d ' ' | grep "^PidFile=" | cut -d'=' -f2`
|
|
|
|
[ -n "$PIDFILE" ] || PIDFILE="/var/run/ircd/ngircd.pid"
|
|
|
|
|
|
|
|
r=3
|
|
|
|
|
2003-07-09 20:23:35 +00:00
|
|
|
Check_Config()
|
|
|
|
{
|
2008-10-03 14:43:54 +00:00
|
|
|
# Make sure that the configuration of ngIRCd is valid:
|
2009-03-29 14:37:06 +00:00
|
|
|
$DAEMON $PARAMS --configtest >/dev/null 2>&1
|
|
|
|
[ $? -eq 0 ] && return 0
|
|
|
|
log_end_msg 1
|
|
|
|
log_failure_msg "Configuration of $NAME is not valid, won't (re)start!"
|
|
|
|
log_failure_msg "Run \"$DAEMON --configtest\" and fix it up ..."
|
|
|
|
exit 6
|
|
|
|
}
|
|
|
|
|
|
|
|
Prepare() {
|
2008-10-03 14:43:54 +00:00
|
|
|
# Make sure the PID file directory exists and is writable:
|
2009-03-29 14:37:06 +00:00
|
|
|
user=`$DAEMON $PARAMS -t|tr -d ' '|grep "^ServerUID="|cut -d'=' -f2`
|
|
|
|
group=`$DAEMON $PARAMS -t|tr -d ' '|grep "^ServerGID="|cut -d'=' -f2`
|
|
|
|
piddir=`dirname "$PIDFILE"`
|
|
|
|
[ -d "$piddir" ] || mkdir -p "$piddir" 2>/dev/null
|
|
|
|
chown "$user:$group" "$piddir" 2>/dev/null
|
|
|
|
[ $? -eq 0 ] && return 0
|
|
|
|
log_end_msg 1
|
|
|
|
log_failure_msg "Failed to prepare '$piddir' for user '$user'!"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
Do_Start() {
|
|
|
|
if Do_Status; then
|
|
|
|
log_end_msg 0
|
|
|
|
log_warning_msg "$NAME seems to be already running, nothing to do."
|
|
|
|
exit 0
|
2003-07-09 20:23:35 +00:00
|
|
|
fi
|
2009-03-29 14:37:06 +00:00
|
|
|
start-stop-daemon --start \
|
|
|
|
--quiet --exec $DAEMON -- $PARAMS
|
|
|
|
sleep $STARTTIME
|
|
|
|
Do_Status || return 7
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
Do_Stop() {
|
|
|
|
if ! Do_Status; then
|
|
|
|
log_end_msg 0
|
|
|
|
log_warning_msg "$NAME seems not to be running, nothing to do."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
Do_ForceStop
|
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
|
|
|
Do_ForceStop() {
|
|
|
|
[ -e $PIDFILE ] \
|
|
|
|
&& pidfile="--pidfile $PIDFILE" \
|
|
|
|
|| pidfile=""
|
|
|
|
start-stop-daemon --stop \
|
|
|
|
--quiet --oknodo --exec $DAEMON $pidfile
|
|
|
|
for i in `seq 1 $DIETIME`; do
|
|
|
|
Do_Status || return 0
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
Do_Reload() {
|
|
|
|
start-stop-daemon --stop --signal 1 --quiet --exec $DAEMON
|
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
|
|
|
Do_Status() {
|
|
|
|
[ -e $PIDFILE ] \
|
|
|
|
&& pidfile="--pidfile $PIDFILE" \
|
|
|
|
|| pidfile=""
|
|
|
|
start-stop-daemon --stop \
|
|
|
|
--quiet --signal 0 --exec $DAEMON $pidfile >/dev/null
|
|
|
|
return $?
|
2003-07-09 20:23:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
start)
|
2008-05-27 23:50:18 +00:00
|
|
|
log_daemon_msg "Starting $DESC" "$NAME"
|
2009-03-29 14:37:06 +00:00
|
|
|
Check_Config
|
|
|
|
Prepare
|
|
|
|
Do_Start; r=$?
|
|
|
|
log_end_msg $r
|
2003-07-09 20:23:35 +00:00
|
|
|
;;
|
|
|
|
stop)
|
2008-05-27 23:50:18 +00:00
|
|
|
log_daemon_msg "Stopping $DESC" "$NAME"
|
2009-03-29 14:37:06 +00:00
|
|
|
Do_Stop; r=$?
|
|
|
|
log_end_msg $r
|
2003-07-09 20:23:35 +00:00
|
|
|
;;
|
|
|
|
reload|force-reload)
|
2008-05-27 23:50:18 +00:00
|
|
|
log_daemon_msg "Reloading $DESC" "$NAME"
|
2009-03-29 14:37:06 +00:00
|
|
|
Check_Config
|
|
|
|
Do_Reload; r=$?
|
|
|
|
log_end_msg $r
|
2003-07-09 20:23:35 +00:00
|
|
|
;;
|
|
|
|
restart)
|
2008-05-27 23:50:18 +00:00
|
|
|
log_daemon_msg "Restarting $DESC" "$NAME"
|
2009-03-29 14:37:06 +00:00
|
|
|
Check_Config
|
|
|
|
Prepare
|
|
|
|
Do_ForceStop
|
|
|
|
Do_Start; r=$?
|
|
|
|
log_end_msg $r
|
|
|
|
;;
|
|
|
|
status)
|
|
|
|
log_daemon_msg "Checking for $DESC" "$NAME"
|
|
|
|
Do_Status; r=$?
|
|
|
|
log_end_msg $r
|
|
|
|
;;
|
|
|
|
test)
|
|
|
|
Check_Config
|
|
|
|
echo "Configuration of $DAEMON seems to be ok."; r=0
|
2003-07-09 20:23:35 +00:00
|
|
|
;;
|
|
|
|
*)
|
2009-03-29 14:37:06 +00:00
|
|
|
N=/etc/init.d/$NAME; r=2
|
|
|
|
echo "Usage: $N {start|stop|restart|reload|force-reload|status|test}" >&2
|
2003-07-09 20:23:35 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2009-03-29 14:37:06 +00:00
|
|
|
exit $r
|
2003-07-09 20:23:35 +00:00
|
|
|
|
|
|
|
# -eof-
|