#!/bin/sh [ -e /etc/rc.defaults ] && . /etc/rc.defaults [ -e /etc/rc.conf ] && . /etc/rc.conf DAEMON=inadyn DEFAULTOPTS="/etc/inadyn.conf" case "$1" in start) if [ ! -f "/var/run/$DAEMON.pid" ] then # Set default options if none set in rc.conf if [ $inadyn_config="" ] then echo "No options set in rc.conf for $DAEMON, using defaults" inadyn_config=$DEFAULTOPTS fi #Check for existence of config file if [ ! -f $inadyn_config ] echo "Error: Configuration file $inadyn_config not found!" echo "Please read /etc/inadyn.conf.example" exit 1 fi # Start Daemon echo "Starting $DAEMON" $DAEMON --input_file $inadyn_config >> /var/log/inadyn.log & # Get Daemon pid # Strip script PID from pidof output DAEMONPID=`pidof $DAEMON|sed s/$$//` # Write pid to file echo $DAEMONPID > /var/run/$DAEMON.pid # Check Daemon launched OK if ps -fp$! > /dev/null 2>&1 then echo " >> OK" else echo " ** FAILED" fi else # Daemon already running, show status echo "already running" $0 status exit 1 fi ;; stop) # Make sure we don't nuke this script # in the process of stopping daemon. # killall will kill this script as well # as it shares the same ps name if [ ! -f "/var/run/$DAEMON.pid" ] then # Daemon not running, show status $0 status exit 1 fi echo "Stopping $DAEMON" # kill daemon kill `cat /var/run/$DAEMON.pid` # Remove pid file rm /var/run/$DAEMON.pid echo " >> OK" ;; restart) # If daemon not running, start # Otherwise start and stop daemon # Ugly hack as ps id's change when using # $0 start and $0 stop if [ ! -f "/var/run/$DAEMON.pid" ] then echo "$DAEMON not running, starting" exec /etc/rc.d/$DAEMON start else echo "Stopping $DAEMON" kill `cat /var/run/$DAEMON.pid` rm /var/run/$DAEMON.pid echo " >> OK" exec /etc/rc.d/$DAEMON start fi ;; status) if [ ! -f "/var/run/$DAEMON.pid" ] then echo "$DAEMON is not running or pidfile does not exist" else DAEMONPID=`cat /var/run/$DAEMON.pid` echo "$DAEMON is running with pid $DAEMONPID" fi ;; *) echo "Usage: $0 " exit 1 ;; esac # vim:ts=4:sw=4:ic:ai:nows: