Install God background process monitoring on Ubuntu 12.04

God, a monitoring framework written in Ruby is easy to configure, easy to extend and easy to use. God allows you to monitor the state of a process (whether it is running or not) and perform specific tasks dependent upon the state. These tasks can be as simple as restarting the process or go as far as alerting you via email, text, a phone call – basically, anything you can programmatically do in Ruby.

This tutorial shows you how to setup God on Ubuntu 12.04 (and I’m pretty sure it would work for earlier versions of Ubuntu too). I will cover the installation and layout of configuration files, as well as setting up an init service script allowing for God to be started|stopped|restarted easily, and automatically started at boot.

Installation

On Ubuntu 12.04 you install God through Ruby gems, as so:

sudo gem install god

Configuration files

Once installed, God can be run from the command line. But to start we need to setup configuration files. Create a directory in /etc to store the God configuration files:

sudo mkdir /etc/god.d

Then create the master God configuration file. This will include configuration files inside of /etc/god.d – which is just a pleasant way of having multiple process monitoring configurations.

sudo vi /etc/god.conf

Add the following line

1
God.load '/etc/god.d/*.god'

Now, when God starts it will utilize all the process monitoring configuration files located in /etc/god.d/.

Init script

To make God an init based service you can create an init.d script. I did not write this script, Benjamin Larralde did.

sudo vi /etc/init.d/god
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash
#
# god       Startup script for god (<a href="http://god.rubyforge.org">http://god.rubyforge.org</a>)
#
# chkconfig: - 99 1
# description: God is an easy to configure, easy to extend monitoring \
#              framework written in Ruby.
#
 
CONF_FILE=/opt/god/master.conf
DAEMON=/home/ben/.rvm/bin/boot_god
PIDFILE=/var/run/god.pid
LOGFILE=/var/log/god.log
SCRIPTNAME=/etc/init.d/god
 
#DEBUG_OPTIONS="--log-level debug"
DEBUG_OPTIONS=""
 
# Gracefully exit if 'god' gem is not available.
test -x $DAEMON || exit 0
 
RETVAL=0
 
god_start() {
      start_cmd="$DAEMON -l $LOGFILE -P $PIDFILE $DEBUG_OPTIONS -c $CONF_FILE"
      echo $start_cmd
      $start_cmd || echo -en "god already running"
      RETVAL=$?
      return $RETVAL
}
 
god_stop() {
      stop_cmd="$DAEMON terminate"
      #stop_cmd="kill -QUIT `cat $PIDFILE`"
      echo $stop_cmd
      $stop_cmd || echo -en "god not running"
}
 
case "$1" in
    start)
      god_start
      RETVAL=$?
  ;;
    stop)
      god_stop
      RETVAL=$?
  ;;
    restart)
      god_stop
      god_start
      RETVAL=$?
  ;;
    status)
      $DAEMON status
      RETVAL=$?
  ;;
    *)
      echo "Usage: god {start|stop|restart|status}"
      exit 1
  ;;
esac
 
exit $RETVAL

Save the file and ensure it is execuatble.

sudo chmod +x /etc/init.d/god

Then register the startup/shutdown processes (to automatically start on boot).

sudo update-rc.d -f god defaults

You can now start, stop and restart God as a service:

sudo /etc/init.d/god start
sudo /etc/init.d/god stop
sudo /etc/init.d/god restart

God will also start when your server starts.

You can now start adding process monitoring configurations. Enjoy!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>