Better daemon init script
Reported by Chad Woolley | July 17th, 2008 @ 02:15 PM | in next
I'd like to improve the current daemon init script. It doesn't work well when invoked as an init script (on debian at least). A couple I've found is running it as a different user, and the shbang for env ruby not working (the shbang thing just wasted about 4 hours for me, didn't work on a new Ubuntu 8.04 slicehost instance for some reason)
I've seen a different init script for almost every ccrb install I work with. It would be great to work toward something that "just works" for most cases.
This ticket is requesting people to attach their init script examples, so we can at least start to identify ideas and best practices, and at least include some gotchas in the sample daemon comments, even if we don't handle all edge cases.
Thanks,
-- Chad
Comments and changes to this ticket
-
Chad Woolley July 17th, 2008 @ 02:12 PM
Here is the one from my personal server, running on Ubuntu 6.10:
#!/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 }
puts "Killing builder at file #{pid_file}, pid=#{pid}"
system "kill -9 #{pid}"
rm pid_file
end
exit 0
else
p "Usage: /etc/init.d/cruise start|stop"
exit 1
end
-
Chad Woolley July 18th, 2008 @ 07:33 PM
Here is my improved version, which is working for me:
http://github.com/thewoolleyman/...
Note, I named it ccrb_daemon to avoid conflicts, but it can replace the old one if we keep it.
This has several advantages over the old one:
- Most importantly, works correctly on system reboot (when run in startup mode as root)
- Doesn't need to be edited, can optionally use /etc/ccrb/ccrb_daemon_config (sample provided)
- Can use env vars instead of config file
- can run as root or as non-root user
- gives correct non-zero return codes on any failure.
-
Chad Woolley July 26th, 2008 @ 05:20 AM
I further updated and tested this init script. It is working well for me. It consists of just two new files to replace the old sample file. They can be copied directly:
-
Jeremy Lightsmith July 29th, 2008 @ 07:20 PM
- Assigned user set to Jeremy Lightsmith
- State changed from new to open
- Milestone set to current
-
Jeremy Lightsmith October 30th, 2008 @ 10:35 AM
- Milestone changed from current to next
-
Chad Woolley March 28th, 2009 @ 12:10 PM
Attaching another patch:
Improve daemon_helper to kill all child processes (don't leave any orphans)
-
Chad Woolley March 28th, 2009 @ 12:11 PM
- no changes were found...
-
Chad Woolley March 28th, 2009 @ 01:05 PM
- State changed from open to resolved
- Assigned user changed from Jeremy Lightsmith to Chad Woolley
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป