terom@27: #! /bin/sh terom@27: ### BEGIN INIT INFO terom@27: # Provides: fixbot-nexus terom@27: # Required-Start: $remote_fs terom@27: # Required-Stop: $remote_fs terom@27: # Default-Start: 2 3 4 5 terom@27: # Default-Stop: 0 1 6 terom@27: # Short-Description: FixBot Nexus component terom@27: # Description: Acts as the IRC bot, and provides an API server that other components may connect to terom@27: ### END INIT INFO terom@27: terom@27: # Author: Tero Marttila terom@27: terom@27: # Do NOT "set -e" terom@27: terom@27: # PATH should only include /usr/* if it runs after the mountnfs.sh script terom@27: PATH=/sbin:/usr/sbin:/bin:/usr/bin terom@27: terom@27: # fixbot stuff terom@27: FIXBOT_NAME=fixbot-nexus terom@27: # what plugin to run terom@27: TWISTD_PLUGIN=fixbot_nexus terom@27: DESC="FixBot Nexus component" terom@27: PIDFILE=/var/run/$FIXBOT_NAME.pid terom@27: SCRIPTNAME=/etc/init.d/$FIXBOT_NAME terom@27: # custom arguments to twistd(1) terom@27: TWISTD_ARGS= terom@27: # custom arguments to fixbot, see `twistd fixbot_nexus --help` terom@27: FIXBOT_ARGS= terom@27: terom@27: terom@27: # twistd stuff terom@27: DAEMON_NAME=twistd terom@27: DAEMON=/usr/bin/$DAEMON_NAME terom@27: terom@27: # Exit if the package is not installed terom@27: [ -x "$DAEMON" ] || exit 0 terom@27: terom@27: # Read configuration variable file if it is present terom@27: [ -r /etc/default/$FIXBOT_NAME ] && . /etc/default/$FIXBOT_NAME terom@27: terom@27: # what arguments we run with terom@27: DAEMON_ARGS="--pidfile=$PIDFILE $TWISTD_ARGS $TWISTD_PLUGIN $FIXBOT_ARGS" terom@27: terom@27: # Load the VERBOSE setting and other rcS variables terom@27: . /lib/init/vars.sh terom@27: terom@27: # Define LSB log_* functions. terom@27: # Depend on lsb-base (>= 3.0-6) to ensure that this file is present. terom@27: . /lib/lsb/init-functions terom@27: terom@27: # terom@27: # Function that starts the daemon/service terom@27: # terom@27: do_start() terom@27: { terom@27: # Return terom@27: # 0 if daemon has been started terom@27: # 1 if daemon was already running terom@27: # 2 if daemon could not be started terom@27: start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \ terom@27: || return 1 terom@27: start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \ terom@27: $DAEMON_ARGS \ terom@27: || return 2 terom@27: # Add code here, if necessary, that waits for the process to be ready terom@27: # to handle requests from services started subsequently which depend terom@27: # on this one. As a last resort, sleep for some time. terom@27: } terom@27: terom@27: # terom@27: # Function that stops the daemon/service terom@27: # terom@27: do_stop() terom@27: { terom@27: # Return terom@27: # 0 if daemon has been stopped terom@27: # 1 if daemon was already stopped terom@27: # 2 if daemon could not be stopped terom@27: # other if a failure occurred terom@27: start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $DAEMON_NAME terom@27: RETVAL="$?" terom@27: [ "$RETVAL" = 2 ] && return 2 terom@27: # Wait for children to finish too if this is a daemon that forks terom@27: # and if the daemon is only ever run from this initscript. terom@27: # If the above conditions are not satisfied then add some other code terom@27: # that waits for the process to drop all resources that could be terom@27: # needed by services started subsequently. A last resort is to terom@27: # sleep for some time. terom@27: start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON terom@27: [ "$?" = 2 ] && return 2 terom@27: # Many daemons don't delete their pidfiles when they exit. terom@27: rm -f $PIDFILE terom@27: return "$RETVAL" terom@27: } terom@27: terom@27: # terom@27: # Function that sends a SIGHUP to the daemon/service terom@27: # terom@27: do_reload() { terom@27: # terom@27: # If the daemon can reload its configuration without terom@27: # restarting (for example, when it is sent a SIGHUP), terom@27: # then implement that here. terom@27: # terom@27: start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME_DAEMON terom@27: return 0 terom@27: } terom@27: terom@27: case "$1" in terom@27: start) terom@27: [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$FIXBOT_NAME" terom@27: do_start terom@27: case "$?" in terom@27: 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; terom@27: 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; terom@27: esac terom@27: ;; terom@27: stop) terom@27: [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$FIXBOT_NAME" terom@27: do_stop terom@27: case "$?" in terom@27: 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; terom@27: 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; terom@27: esac terom@27: ;; terom@27: #reload|force-reload) terom@27: # terom@27: # If do_reload() is not implemented then leave this commented out terom@27: # and leave 'force-reload' as an alias for 'restart'. terom@27: # terom@27: #log_daemon_msg "Reloading $DESC" "$NAME" terom@27: #do_reload terom@27: #log_end_msg $? terom@27: #;; terom@27: restart|force-reload) terom@27: # terom@27: # If the "reload" option is implemented then remove the terom@27: # 'force-reload' alias terom@27: # terom@27: log_daemon_msg "Restarting $DESC" "$FIXBOT_NAME" terom@27: do_stop terom@27: case "$?" in terom@27: 0|1) terom@27: do_start terom@27: case "$?" in terom@27: 0) log_end_msg 0 ;; terom@27: 1) log_end_msg 1 ;; # Old process is still running terom@27: *) log_end_msg 1 ;; # Failed to start terom@27: esac terom@27: ;; terom@27: *) terom@27: # Failed to stop terom@27: log_end_msg 1 terom@27: ;; terom@27: esac terom@27: ;; terom@27: *) terom@27: #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2 terom@27: echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2 terom@27: exit 3 terom@27: ;; terom@27: esac terom@27: terom@27: :