Chad Woolley
2007-Dec-30 22:10 UTC
[Cruisecontrolrb-users] cruise init script that works on server reboot
I just hacked the daemon cruise init script to work properly on reboot
on my debian (ubuntu) server. On debian bootup, there is a very
minimal root-user environment, so you have to do some extra steps to
make it run at all, and run as a non-root user.
The important changes are:
* shebang fully qualified to point to ruby exec
* manually populate PATH env to contain ruby (/usr/local/...)
* add cruise_user method to define local user used to run cruise
* invoke ''start'' command as specified cruise_user
Here''s what I currently have, hopefully it will help someone. If you
want this committed, it could use a little cleanup, and might not be
as portable as the old version - let me know if you are interested and
I can try to make a ticket/patch:
-----------------
#!/usr/local/bin/ruby
ENV[''PATH'']="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11"
# in order to make cruise run as daemon, you need:
# 1. cp $CCRB_HOME/daemon/cruise.sample $CCRB_HOME/daemon/cruise
# 2. specify your cruise_path to $CCRB_HOME in $CCRB_HOME/daemon/cruise file
# 3. ln -s $CCRB_HOME/daemon/cruise /etc/init.d/cruise (you may need
to ''sudo'' this)
# 4. update-rc.d cruise (you may want to choose options by yourself,
and you may need to ''sudo'' this)
# 5. it''s done :>
require "fileutils"
include FileUtils
require "rubygems"
begin
gem ''mongrel''
rescue => e
puts "Error: daemon mode of CC.rb requires mongrel installed"
exit 1
end
def cruise_path
"/home/woolley/workspace/cruisecontrolrb"
end
def cruise_user
"woolley"
end
command = ARGV.shift
case command
when ''start''
#cd cruise_path
system "su - woolley -c ''cd #{cruise_path} && ./cruise
start -d''"
exit 0
when ''stop''
system "mongrel_rails stop -P #{cruise_path}/tmp/pids/mongrel.pid"
Dir["#{cruise_path}/tmp/pids/builders/*.pid"].each do |pid_file|
pid = File.open(pid_file){|f| f.read }
system "kill -9 #{pid}"
rm pid_file
end
exit 0
else
p "Usage: /etc/init.d/cruise start|stop"
exit 1
end