Skip to content
Evan Carmi edited this page Dec 3, 2010 · 4 revisions

#God God is an easy to configure, easy to extend monitoring framework written in Ruby. We use it to start, monitor, and keep running the following processes:

  • iguanaIR (igdaemon)
  • lirc
  • roomtrol-daemon

Install god using gems

First, we install god using gems and create a wrapper script so that you can start god without using rvm.

sudo su
source /usr/local/lib/rvm
rvm 1.9.2
gem install god
rvm wrapper 1.9.2 bootup god
exit

Symlink god on to bin path

We now put a link to this script on the bin path so a shell can find it. sudo ln -s /usr/local/rvm/bin/bootup_god /usr/local/bin/god

Setup god configuration file

We now need to setup the god configuration file. Save the following in /home/roomtrol/roomtrol.god:

# run with: god -c /path/to/roomtrol.god
# use the -D flag for --no-daemonize if you want to see output
# god -c /home/roomtrol/roomtrol.god -l /var/log/god.log

# Place all pid files in /var/run/ and all log files /var/log/
PID_ROOT = "/var/run"
LOG_ROOT = "/var/log"

# Create a watch for iguanaIR
God.watch do |w|
	w.name = "iguanaIR"
	w.interval = 30.seconds
	w.start_grace = 10.seconds
	w.restart_grace = 10.seconds
	w.pid_file = File.join(PID_ROOT, "#{w.name}.pid")
	w.log = File.join(LOG_ROOT, "#{w.name}.log")
	w.start = "igdaemon -p #{w.pid_file} -l #{w.log}"
	w.stop = "kill `cat #{w.pid_file}`"
	w.behavior(:clean_pid_file)
	
	# Start if not running
	w.start_if do |start|
		start.condition(:process_running) do |c|
			c.interval = 5.seconds
			c.running = false
		end
	end
end

# Create a watch for bootup_roomtrol
God.watch do |w|
	w.name = "roomtrol-daemon"
	w.interval = 30.seconds
	w.start_grace = 10.seconds
	w.restart_grace = 10.seconds
	w.pid_file = File.join(PID_ROOT, "#{w.name}.pid")
	w.log = File.join(LOG_ROOT, "#{w.name}.log")
	w.start = "bootup_roomtrol -pidfile #{w.pid_file} -l #{w.log}"
	w.stop = "bootup_roomtrol stop"
	w.behavior(:clean_pid_file)
	
	# Start if not running
	w.start_if do |start|
		start.condition(:process_running) do |c|
			c.interval = 5.seconds
			c.running = false
		end
	end
end

# Create a watch for lirc
God.watch do |w|
	w.name = "lirc"
	w.interval = 30.seconds
	w.start_grace = 10.seconds
	w.restart_grace = 10.seconds
	w.pid_file = File.join(PID_ROOT, "#{w.name}.pid")
	w.log = File.join(LOG_ROOT, "#{w.name}.log")
	w.start = "mkdir -p /var/run/lirc && lircd -P #{w.pid_file} -H iguanaIR -d /dev/iguanaIR/0"
	w.stop = "kill `cat #{w.pid_file}`"
	w.behavior(:clean_pid_file)
	
	# Start if not running
	w.start_if do |start|
		start.condition(:process_running) do |c|
			c.interval = 5.seconds
			c.running = false
		end
	end
end

Create god upstart configuration file

However, we also need something to start god. For that we use upstart. So create a upstart script to start god at /etc/init/god.conf with the following:

description "god"

respawn

start on (started rc-sysinit)
stop on runlevel [06]

exec /usr/local/rvm/bin/bootup_god -D -c /home/roomtrol/roomtrol.god -l /var/log/god.log

Notice that we use the -D (no-daemonize) flag to start god in non-daemon mode. This allows upstart to watch it more accurately.

Use god

You can know use god and upstart to manage processes: roomtrol@roomtrol-dev3:~$ god --help Usage: Commands: start start task or group restart restart task or group stop stop task or group monitor monitor task or group unmonitor unmonitor task or group remove remove task or group from god load load a config into a running god log show realtime log for given task status [task or group name] show status signal signal all matching tasks quit stop god terminate stop god and all tasks check

Checking everything started properly

If you want to quickly (perhaps after a reboot) make sure that all the processes have started you can use the following command and should see the example output: roomtrol@roomtrol-dev3:~$ ps -e | egrep "god|lircd|igdaemon|roomtrol" 586 ? 00:00:02 god 1117 ? 00:00:04 roomtrol 1124 ? 00:00:05 igdaemon 1126 ? 00:00:00 lircd