1
0
mirror of https://github.com/osmarks/ngircd.git synced 2024-12-15 11:20:26 +00:00
ngircd/contrib/Debian/ngircd.init

176 lines
3.6 KiB
Bash
Executable File

#!/bin/sh
#
# ngIRCd start and stop script for Debian-based systems
# Copyright 2008-2010 Alexander Barton <alex@barton.de>
#
### BEGIN INIT INFO
# Provides: ngircd
# Required-Start: $network $remote_fs
# Required-Stop: $network $remote_fs
# Should-Start: $syslog $named
# Should-Stop: $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Next Generation IRC Server
# Description: IRC daemon written from scratch
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/ngircd
NAME=ngIRCd
DESC="IRC daemon"
PARAMS=""
STARTTIME=1
DIETIME=10
test -x $DAEMON || exit 5
test -h "$0" && me=`readlink $0` || me="$0"
BASENAME=`basename $me`
test -r /etc/default/$BASENAME && . /etc/default/$BASENAME
# LSB compatibility functions that become used if there is no local
# include file available.
log_daemon_msg() {
echo -n "$*"
}
log_end_msg() {
[ "$1" == "0" ] && echo "." || echo " failed!"
}
log_failure_msg() {
echo "$*"
}
log_warning_msg() {
log_failure_msg "$*"
}
# Include LSB functions, if available:
test -r /lib/lsb/init-functions && . /lib/lsb/init-functions
PIDFILE=`$DAEMON $PARAMS -t | tr -d ' ' | grep "^PidFile=" | cut -d'=' -f2`
[ -n "$PIDFILE" ] || PIDFILE="/var/run/ircd/ngircd.pid"
r=3
Check_Config()
{
# Make sure that the configuration of ngIRCd is valid:
$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() {
# Make sure the PID file directory exists and is writable:
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
fi
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 $?
}
case "$1" in
start)
log_daemon_msg "Starting $DESC" "$NAME"
Check_Config
Prepare
Do_Start; r=$?
log_end_msg $r
;;
stop)
log_daemon_msg "Stopping $DESC" "$NAME"
Do_Stop; r=$?
log_end_msg $r
;;
reload|force-reload)
log_daemon_msg "Reloading $DESC" "$NAME"
Check_Config
Do_Reload; r=$?
log_end_msg $r
;;
restart)
log_daemon_msg "Restarting $DESC" "$NAME"
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
;;
*)
N=/etc/init.d/$NAME; r=2
echo "Usage: $N {start|stop|restart|reload|force-reload|status|test}" >&2
;;
esac
exit $r
# -eof-