Commit 25735cc0 authored by anarcat's avatar anarcat

make init script OS-agnostic, POSIX-sh compatible

we do not rely on LSB functions because Fedora doesn't support them

we can do this because the more reliable Debian init script is now
part of the Debian package itself
parent ee587122
......@@ -3,8 +3,9 @@ Hosting queue daemon
Simple Drupal module intended to make it easy to run the Aegir tasks
queue with near-instant execution times. The daemon is designed to run
standalone, and started through regular services (e.g. there's an
init.d script available).
standalone, and started through regular services: there's an init.d
script available, which is installed with the Debian package, but that
you will need to manually install in other platforms.
Note that before the service is setup and the daemon can be started,
it needs to be enabled as a module in the frontend.
......
......@@ -19,7 +19,7 @@
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="Aegir queue daemon" # Introduce a short description here
NAME="hosting-queued" # Introduce the short server's name here
DAEMON=/usr/bin/drush # Introduce the server's location here
DAEMON=/usr/local/bin/drush # Introduce the server's location here
DAEMON_ARGS="@hostmaster $NAME" # Arguments to run the daemon with
USER="aegir"
PIDFILE=/var/run/$NAME.pid
......@@ -32,30 +32,20 @@ NICE=10
# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh
# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions
# Define LSB functions.
# XXX: unfortunately not supported by all platforms so we ignore this
# for now, see http://fedoraproject.org/wiki/FCNewInit/Initscripts#Init_Script_Functions
#. /lib/lsb/init-functions
#
# Function that starts the daemon/service
#
do_start()
{
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
start-stop-daemon --start --quiet -c $USER --background \
--make-pidfile --pidfile $PIDFILE --startas $DAEMON \
--test > /dev/null \
|| return 1
start-stop-daemon --nice $NICE --start --quiet -c $USER --background \
--make-pidfile --pidfile $PIDFILE --startas $DAEMON -- \
$DAEMON_ARGS \
|| return 2
su - $USER $DAEMON $DAEMON_ARGS &
ret=$?
echo $! > $PIDFILE
return $ret
}
#
......@@ -63,58 +53,46 @@ do_start()
#
do_stop()
{
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
# Many daemons don't delete their pidfiles when they exit.
rm -f $PIDFILE
return "$RETVAL"
if [ -e $PIDFILE ]; then
kill `cat $PIDFILE`
ret=$?
rm -f $PIDFILE
else
ret=1
echo "no pid file found"
fi
return $ret
}
#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {
#
# If the daemon can reload its configuration without
# restarting (for example, when it is sent a SIGHUP),
# then implement that here.
#
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE
return 0
kill -HUP `cat $PIDFILE`
}
case "$1" in
start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC " "$NAME"
[ "$VERBOSE" != no ] && echo "Starting $DESC " "$NAME"
do_start
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
0|1) [ "$VERBOSE" != no ] && echo "ok" ;;
2) [ "$VERBOSE" != no ] && echo "FAIL" ;;
esac
;;
stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
do_stop
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
[ "$VERBOSE" != no ] && echo "Stopping $DESC" "$NAME"
do_stop
case "$?" in
0|1) [ "$VERBOSE" != no ] && echo ok ;;
2) [ "$VERBOSE" != no ] && echo FAIL ;;
esac
;;
status)
status_of_proc -p $PIDFILE "$DAEMON" "$NAME" && exit 0 || exit $?
;;
reload|force-reload)
#
# If do_reload() is not implemented then leave this commented out
# and leave 'force-reload' as an alias for 'restart'.
#
log_daemon_msg "Reloading $DESC" "$NAME"
echo "Reloading $DESC"
do_reload
log_end_msg $?
;;
......@@ -123,7 +101,7 @@ case "$1" in
# If the "reload" option is implemented then remove the
# 'force-reload' alias
#
log_daemon_msg "Restarting $DESC" "$NAME"
echo "Restarting $DESC"
do_stop
case "$?" in
0|1)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment