Tue, 31 Mar 09

CruiseControlrb With Passenger and Launchd on a Mac

This has taken me ages, is quite fiddly and I’m still not 100% happy with it but it seems to work well enough to document here.

Configuring the server to run under Passenger

   config.after_initialize do
     require CRUISE_DATA_ROOT + '/site_config' if File.exists?(CRUISE_DATA_ROOT + "/site_config.rb")
     require RAILS_ROOT + '/config/dashboard_initialize' 
  -  BuilderStarter.start_builders 
  +  BuilderStarter.start_builders unless ENV['CCRB_WITHOUT_BUILDERS']
   end
  $ cat > ~/ruby_for_passenger
  #!/bin/sh

  export CCRB_WITHOUT_BUILDERS=true

  exec "/usr/bin/ruby" "$@"

  $ sudo mv ~/ruby_for_passenger /usr/local/bin/
  $ sudo chmod +x /usr/local/bin/ruby_for_passenger
  $ sudo vi /etc/apache2/httpd.conf
  #PassengerRuby /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
  PassengerRuby /usr/local/bin/ruby_for_passenger

Configuring the builders to start under launchd

  -  CRUISE_OPTIONS[:log_file_name] = "log/#{CRUISE_OPTIONS[:project_name]}_builder.log"
  +  CRUISE_OPTIONS[:log_file_name] = File.join(RAILS_ROOT, 'log', "#{CRUISE_OPTIONS[:project_name]}_builder.log")
  <?xml version="1.0" encoding="UTF-8"?>
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  <plist version="1.0">
    <dict>
      <key>EnvironmentVariables</key>
      <dict>
        <key>PATH</key>
        <string>/usr/bin:/opt/local/bin</string>
      </dict>
      <key>Label</key>
      <string>label-describing-your-builder</string>
      <key>ProgramArguments</key>
      <array>
        <string>/Users/chrisroos/cruisecontrol.rb/cruise</string>
        <string>build</string>
        <string>name-of-project-to-build</string>
      </array>
      <key>RunAtLoad</key>
      <true/>
    </dict>
  </plist>
  
  # Notes:
  # We set the PATH environment variable so that both git and ruby can be found.
  # We set RunAtLoad so that as soon as the plist is loaded by launchctl it will start to run.
  $ launchctl load ~/Library/LaunchAgents/label-from-plist

And that should be about it. I’d appreciate any feedback anyone has about this approach and to hear about alternative approaches of getting cruise running automatically on system boot.