#200 open
Chad Woolley

Better daemon init script

Reported by Chad Woolley | July 17th, 2008 @ 02:09 PM | in 1.4

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

    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"

    1. in order to make cruise run as daemon, you need:
    2. 1. cp $CCRB_HOME/daemon/cruise.sample $CCRB_HOME/daemon/cruise
    3. 2. specify your cruise_path to $CCRB_HOME in $CCRB_HOME/daemon/cruise file
    4. 3. ln -s $CCRB_HOME/daemon/cruise /etc/init.d/cruise (you may need to 'sudo' this)
    5. 4. update-rc.d cruise (you may want to choose options by yourself, and you may need to 'sudo' this)
    6. 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

    Chad Woolley July 17th, 2008 @ 02:15 PM

    Ugh, probably better to do these as attachments, huh...

  • Chad Woolley
  • Chad Woolley

    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

    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:

    http://github.com/thewoolleyman/...

  • Jeremy Lightsmith

    Jeremy Lightsmith July 29th, 2008 @ 07:20 PM

      • → Assigned user changed from “” to “Jeremy Lightsmith”
      • → State changed from “new” to “open”
      • → Milestone changed from “” to “1.4”

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket