I needed an init script for God, so that it could be managed via the
service command.

This is undoubtedly wrong in some way, but it seems to be working for
me nicely, now that I hacked one I found at  thewebfellas.com to give
something nicer for  the "service god status" command, and to remove
the pid on stop. I'm not sure why god seems to abandon it, but I
hacked it here until I get time to dig into god and fix it.

Anyway, here's my take on it in case someone else needs it...

# ===============================
#!/bin/bash

### BEGIN INIT INFO
# Provides: god
# Default-Start:  2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop god
# Description: monitoring by god.
### END INIT INFO

# fedora10: phi
# original: chris anderton, thewebfellas.com

# source function library
. /etc/rc.d/init.d/functions

RETVAL=0
prog="god"

set -e

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="god daemon"
NAME=god
DAEMON=/usr/bin/$NAME
CONFIGFILEDIR=/etc/$NAME
PIDFILE=/var/run/$NAME/$NAME.pid
LOGFILE=/var/log/$NAME.log
SCRIPTNAME=/etc/init.d/$NAME

# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0

d_start() {
  $DAEMON -l $LOGFILE -P $PIDFILE || echo -en "\n already running"
  for file in `ls -1 $CONFIGFILEDIR/*.god`; do $DAEMON load $file;
done
}

d_stop() {
  kill -QUIT `cat $PIDFILE` || echo -en "\n not running"
  if [ -f $PIDFILE ] ; then
    rm $PIDFILE
  fi
}

d_reload() {
  kill -HUP `cat $PIDFILE` || echo -en "\n can't reload"
}

d_status() {
  if [ -f $PIDFILE ] ; then
     echo `cat $PIDFILE`
  else
     echo " not running"
  fi
}

case "$1" in
  start)
    echo -n "Starting $DESC: $NAME"
    d_start
        echo "."
  ;;
  stop)
    echo -n "Stopping $DESC: $NAME"
    d_stop
        echo "."
  ;;
  reload)
    echo -n "Reloading $DESC configuration..."
    d_reload
        echo "."
  ;;
  restart)
    echo -n "Restarting $DESC: $NAME"
    d_stop
    sleep 5
    d_start
    echo "."
  ;;
  status)
    echo -n "$NAME : "
    d_status
  ;;
  *)
    echo "Usage: $SCRIPTNAME {start|stop|status|restart|reload}" >&2
    exit 3
  ;;
esac

exit 0

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"god.rb" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/god-rb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to