mirror of
https://github.com/osmarks/ngircd.git
synced 2025-06-07 00:44:09 +00:00
Updated Debian/Linux init script
- PidFile, ServerUID and ServerGID are read from actual server configuration - Exit code and behaviour is more LSB compliant - New "status" and "test" sub-functions
This commit is contained in:
parent
3a7d59c1ac
commit
c3a8d6a73e
@ -1,18 +1,19 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
#
|
#
|
||||||
# ngIRCd start and stop script for Debian-based systems
|
# ngIRCd start and stop script for Debian-based systems
|
||||||
# Copyright 2008 Alexander Barton <alex@barton.de>
|
# Copyright 2008,2009 Alexander Barton <alex@barton.de>
|
||||||
#
|
#
|
||||||
|
|
||||||
### BEGIN INIT INFO
|
### BEGIN INIT INFO
|
||||||
# Provides: ircd
|
# Provides: ngircd ircd
|
||||||
# Required-Start: $remote_fs
|
# Required-Start: $network $local_fs
|
||||||
# Required-Stop: $remote_fs
|
# Required-Stop:
|
||||||
# Should-Start: $syslog
|
# Should-Start: $syslog $named
|
||||||
# Should-Stop: $syslog
|
# Should-Stop: $syslog
|
||||||
# Default-Start: 2 3 4 5
|
# Default-Start: 2 3 4 5
|
||||||
# Default-Stop: 0 1 6
|
# Default-Stop: 0 1 6
|
||||||
# Short-Description: Next Generation IRC Server
|
# Short-Description: Next Generation IRC Server
|
||||||
|
# Description: IRC daemon written from scratch
|
||||||
### END INIT INFO
|
### END INIT INFO
|
||||||
|
|
||||||
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
|
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
|
||||||
@ -20,14 +21,16 @@ DAEMON=/usr/sbin/ngircd
|
|||||||
NAME=ngIRCd
|
NAME=ngIRCd
|
||||||
DESC="IRC daemon"
|
DESC="IRC daemon"
|
||||||
PARAMS=""
|
PARAMS=""
|
||||||
|
STARTTIME=1
|
||||||
|
DIETIME=10
|
||||||
|
|
||||||
|
test -x $DAEMON || exit 5
|
||||||
|
|
||||||
test -h "$0" && me=`readlink $0` || me="$0"
|
test -h "$0" && me=`readlink $0` || me="$0"
|
||||||
BASENAME=`basename $me`
|
BASENAME=`basename $me`
|
||||||
|
|
||||||
test -r /etc/default/$BASENAME && . /etc/default/$BASENAME
|
test -r /etc/default/$BASENAME && . /etc/default/$BASENAME
|
||||||
|
|
||||||
test -x $DAEMON || exit 0
|
|
||||||
|
|
||||||
# LSB compatibility functions that become used if there is no local
|
# LSB compatibility functions that become used if there is no local
|
||||||
# include file available.
|
# include file available.
|
||||||
log_daemon_msg() {
|
log_daemon_msg() {
|
||||||
@ -39,69 +42,134 @@ log_end_msg() {
|
|||||||
log_failure_msg() {
|
log_failure_msg() {
|
||||||
echo "$*"
|
echo "$*"
|
||||||
}
|
}
|
||||||
|
log_warning_msg() {
|
||||||
|
log_failure_msg "$*"
|
||||||
|
}
|
||||||
|
|
||||||
# Include LSB functions, if available:
|
# Include LSB functions, if available:
|
||||||
test -r /lib/lsb/init-functions && . /lib/lsb/init-functions
|
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()
|
Check_Config()
|
||||||
{
|
{
|
||||||
# Make sure that the configuration of ngIRCd is valid:
|
# Make sure that the configuration of ngIRCd is valid:
|
||||||
$DAEMON --configtest >/dev/null 2>&1
|
$DAEMON $PARAMS --configtest >/dev/null 2>&1
|
||||||
if [ $? -ne 0 ]; then
|
[ $? -eq 0 ] && return 0
|
||||||
log_failure_msg "Configuration of $NAME is not valid, won't (re)start!"
|
log_end_msg 1
|
||||||
log_failure_msg "Run \"$DAEMON --configtest\" and fix it up ..."
|
log_failure_msg "Configuration of $NAME is not valid, won't (re)start!"
|
||||||
exit 1
|
log_failure_msg "Run \"$DAEMON --configtest\" and fix it up ..."
|
||||||
fi
|
exit 6
|
||||||
|
}
|
||||||
|
|
||||||
|
Prepare() {
|
||||||
# Make sure the PID file directory exists and is writable:
|
# Make sure the PID file directory exists and is writable:
|
||||||
if [ ! -d /var/run/ircd ]; then
|
user=`$DAEMON $PARAMS -t|tr -d ' '|grep "^ServerUID="|cut -d'=' -f2`
|
||||||
mkdir -p /var/run/ircd
|
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
|
fi
|
||||||
chown irc:irc /var/run/ircd
|
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
|
case "$1" in
|
||||||
start)
|
start)
|
||||||
Check_Config
|
|
||||||
log_daemon_msg "Starting $DESC" "$NAME"
|
log_daemon_msg "Starting $DESC" "$NAME"
|
||||||
start-stop-daemon --start \
|
Check_Config
|
||||||
--quiet --exec $DAEMON -- $PARAMS
|
Prepare
|
||||||
log_end_msg $?
|
Do_Start; r=$?
|
||||||
|
log_end_msg $r
|
||||||
;;
|
;;
|
||||||
stop)
|
stop)
|
||||||
log_daemon_msg "Stopping $DESC" "$NAME"
|
log_daemon_msg "Stopping $DESC" "$NAME"
|
||||||
[ -r /var/run/ircd/ngircd.pid ] \
|
Do_Stop; r=$?
|
||||||
&& PIDFILE="--pidfile /var/run/ircd/ngircd.pid" \
|
log_end_msg $r
|
||||||
|| PIDFILE=""
|
|
||||||
start-stop-daemon --stop \
|
|
||||||
--quiet --oknodo --exec $DAEMON $PIDFILE
|
|
||||||
log_end_msg $?
|
|
||||||
;;
|
;;
|
||||||
reload|force-reload)
|
reload|force-reload)
|
||||||
Check_Config
|
|
||||||
log_daemon_msg "Reloading $DESC" "$NAME"
|
log_daemon_msg "Reloading $DESC" "$NAME"
|
||||||
start-stop-daemon --stop --signal 1 --quiet --exec $DAEMON
|
Check_Config
|
||||||
log_end_msg $?
|
Do_Reload; r=$?
|
||||||
|
log_end_msg $r
|
||||||
;;
|
;;
|
||||||
restart)
|
restart)
|
||||||
Check_Config
|
|
||||||
log_daemon_msg "Restarting $DESC" "$NAME"
|
log_daemon_msg "Restarting $DESC" "$NAME"
|
||||||
[ -r /var/run/ircd/ngircd.pid ] \
|
Check_Config
|
||||||
&& PIDFILE="--pidfile /var/run/ircd/ngircd.pid" \
|
Prepare
|
||||||
|| PIDFILE=""
|
Do_ForceStop
|
||||||
start-stop-daemon --stop \
|
Do_Start; r=$?
|
||||||
--quiet --oknodo --exec $DAEMON $PIDFILE
|
log_end_msg $r
|
||||||
sleep 1
|
;;
|
||||||
start-stop-daemon --start \
|
status)
|
||||||
--quiet --exec $DAEMON -- $PARAMS
|
log_daemon_msg "Checking for $DESC" "$NAME"
|
||||||
log_end_msg $?
|
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
|
N=/etc/init.d/$NAME; r=2
|
||||||
echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
|
echo "Usage: $N {start|stop|restart|reload|force-reload|status|test}" >&2
|
||||||
exit 1
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
exit 0
|
exit $r
|
||||||
|
|
||||||
# -eof-
|
# -eof-
|
||||||
|
Loading…
x
Reference in New Issue
Block a user