init.d.example 3.16 KB
Newer Older
1 2
#!/bin/sh
### BEGIN INIT INFO
3
# Provides:          hosting-queued
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
# Required-Start:    $network $local_fs
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Queue runner daemon for Aegir
# Description:       This module allows the Hosting tasks queue for the
#                    Aegir project to be 'daemonized' so that tasks
#                    are run as soon as possible instead of waiting
#                    for a cron run. This makes Aegir appear much more
#                    responsive.
### END INIT INFO

# Author: Antoine Beaupré <anarcat@koumbit.org>

# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
20 21
DESC="Aegir queue daemon"  # Introduce a short description here
NAME="hosting-queued" # Introduce the short server's name here
22
DAEMON=/usr/local/bin/drush      # Introduce the server's location here
23 24 25 26
DAEMON_ARGS="@hostmaster $NAME" # Arguments to run the daemon with
USER="aegir"
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
anarcat's avatar
anarcat committed
27
NICE=10
28 29 30 31 32 33 34

# Exit if the package is not installed
[ -x $DAEMON ] || exit 0

# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

35 36 37 38
# 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
39 40 41 42 43 44

#
# Function that starts the daemon/service
#
do_start()
{
anarcat's avatar
anarcat committed
45 46 47 48
    su - $USER $DAEMON $DAEMON_ARGS &
    ret=$?
    echo $! > $PIDFILE
    return $ret
49 50 51 52 53 54 55
}

#
# Function that stops the daemon/service
#
do_stop()
{
anarcat's avatar
anarcat committed
56 57 58 59 60 61 62 63
    if [ -e $PIDFILE ]; then
        kill `cat $PIDFILE`
        ret=$?
        rm -f $PIDFILE
    else
        ret=1
    fi
    return $ret
64 65 66 67 68 69
}

#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {
anarcat's avatar
anarcat committed
70
    kill -HUP `cat $PIDFILE`
71 72 73
}

case "$1" in
anarcat's avatar
anarcat committed
74
    start)
anarcat's avatar
anarcat committed
75
        [ "$VERBOSE" != no ] && printf "Starting $DESC... "
anarcat's avatar
anarcat committed
76 77
        do_start
        case "$?" in
anarcat's avatar
anarcat committed
78 79
            0|1) [ "$VERBOSE" != no ] && echo ok ;;
            2) [ "$VERBOSE" != no ] && echo FAIL ;;
80
        esac
anarcat's avatar
anarcat committed
81 82
        ;;
    stop)
anarcat's avatar
anarcat committed
83
        [ "$VERBOSE" != no ] && printf "Stopping $DESC... "
84 85
        do_stop
        case "$?" in
anarcat's avatar
anarcat committed
86 87
            0|1) [ "$VERBOSE" != no ] && echo ok ;;
            2) [ "$VERBOSE" != no ] && echo FAIL ;;
88 89
        esac
        ;;
anarcat's avatar
anarcat committed
90
    status)
91
        if [ -r $PIDFILE ] && ps `cat $PIDFILE` > /dev/null; then
anarcat's avatar
anarcat committed
92
            [ "$VERBOSE" != no ] && echo $DESC is running
93
            exit 0
anarcat's avatar
anarcat committed
94
        else
95
            ret=$?
anarcat's avatar
anarcat committed
96
            [ "$VERBOSE" != no ] && echo "$DESC is not running"
97
            exit $ret
98
        fi
anarcat's avatar
anarcat committed
99 100
        ;;
    reload|force-reload)
anarcat's avatar
anarcat committed
101 102
	[ "$VERBOSE" != no ] && printf "Reloading $DESC... "
	do_reload && echo ok || echo FAIL
103
	;;
anarcat's avatar
anarcat committed
104
    restart)
105 106 107 108
	#
	# If the "reload" option is implemented then remove the
	# 'force-reload' alias
	#
anarcat's avatar
anarcat committed
109
	[ "$VERBOSE" != no ] && printf "Restarting $DESC... "
110 111
	do_stop
	case "$?" in
anarcat's avatar
anarcat committed
112
	    0|1)
113 114
		do_start
		;;
anarcat's avatar
anarcat committed
115
	    *)
116
	  	# Failed to stop
anarcat's avatar
anarcat committed
117
                ret=$?
anarcat's avatar
anarcat committed
118
		[ "$VERBOSE" != no ] && echo FAIL
anarcat's avatar
anarcat committed
119
                return $ret
120 121 122
		;;
	esac
	;;
anarcat's avatar
anarcat committed
123
    *)
124
	echo "Usage: $SCRIPTNAME {start|stop|status|restart|reload|force-reload}" >&2
125 126 127 128 129
	exit 3
	;;
esac

: