#!/bin/sh . /etc/init.d/functions PATH=/sbin:/usr/sbin:/bin:/usr/bin DAEMON=/usr/bin/Starter NAME=tango-starter DESC="Tango Control System Starter" PIDFILE=/var/run/$NAME.pid USER=tango GROUP=tango INSTANCE=`hostname` [ -x "$DAEMON" ] || { failure; echo " $DAEMON executable not found."; exit 1; } [ -r /etc/default/$NAME ] && . /etc/default/$NAME check_database() { # Ping network seems to be broken (hangs forever) #tango_admin --ping-network 40 || return 1 tango_admin --ping-database 6 || return 1 } check_and_register_instance() { tango_admin --check-device tango/admin/$INSTANCE || \ tango_admin --add-server Starter/$INSTANCE Starter tango/admin/$INSTANCE || return 1 } do_start() { echo "Starting $DESC..." check_database [ "$?" -eq "1" ] && { failure; echo " Database ping failed."; exit 1; } passed; echo " Database ping OK." check_and_register_instance [ "$?" -eq "1" ] && { failure; echo " Could not register Starter instance $INSTANCE."; exit 1; } passed; echo " Starter instance OK."; start-stop-daemon -S -x $DAEMON -c $USER:$GROUP -p $PIDFILE -m -b -- $INSTANCE success; echo " $DESC started." } do_stop() { echo "Stopping $DESC..." start-stop-daemon -K -x $DAEMON -p $PIDFILE success; echo " $DESC stopped." } case "$1" in start) do_start ;; stop) do_stop ;; status) status $DAEMON ;; reload) echo "Reloading $DESC..." start-stop-daemon -K -s 1 -x $DAEMON -p $PIDFILE success; echo " $DESC reloaded." ;; restart|force-reload) echo "Restarting $DESC..." do_stop sleep 5 do_start success; echo " $DESC restarted." ;; *) N=/etc/init.d/$NAME echo "Usage: $N {start|stop|status|reload|restart|force-reload}" >&2 exit 1 ;; esac exit 0