TimeServer Daemonize

This silly little script will daemonize the TimeServer script and provide start|stop|status control with help.

I can't use this directly as a Linux RC script, as the status option must return NONZERO if the process was not found.

We can easily wrap this script to generate the correct exit status, (using yet another custom RC script), but it

would be nice if the Daemons library would return the correct exit code (as per LSB) when status is queried and the process is not found to be running.

I like the option of being able to store the pid in /var/run (via :dir_mode => :system), and as a extra bennie,

he put the log & output files into /var/log. Didn't see the part about /var/log in the documentation.

I like the option of monitor (via :monitor => true). This will create a process, named as "TimeServer_monitor", that will monitor the process and

restart it if it dies. Be aware however, if you're using something like Heartbeat to control this service, and you wish to use Heartbeat monitoring, you should disable monitor (:monitor => false). We don't want 2 processes fisting it out over who starts & monitors the thing.

Here's the code:

#! /usr/bin/env ruby

# vi:set nu ai ap aw smd showmatch tabstop=4 shiftwidth=4:

# ts-ctl.rb

require 'rubygems'

require 'daemons'

Daemons.run_proc(

'TimeServer', # name of daemon

:dir_mode => :system,

# :dir => /var/run/TimeServer,

:backtrace => true,

:monitor => true,

:log_output => true

) do

exec "ruby /usr/global/prog/ts.rb"

end