2009-04-03

Initd Script für cruisecontrolrb

Based on the $CCRB_HOME/daemon/cruise.sample version.


#!/usr/bin/ruby
# chkconfig: 235 99 10
# description: Start or stop the SnipSnap server
#
### BEGIN INIT INFO
# Provides: cruisecontrolrb
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: Start or stop the cruisecontrolrb daemon
### END INIT INFO

ENV['PATH']="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11"

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/cruise/cruisecontrolrb"
end

def cruise_user
"cruise"
end

def cruise_log
"/var/log/cruisecontrolrb.log"
end

def start
system "su - #{cruise_user} -c 'cd #{cruise_path} && ./cruise start -d >> #{cruise_log}'"
end

def stop
system "mongrel_rails stop -P #{cruise_path}/tmp/pids/mongrel.pid >> #{cruise_log}" if File.exists?("#{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
end

command = ARGV.shift

system "touch #{cruise_log}"
system "chown #{cruise_user} #{cruise_log}"


case command
when 'start'
start
exit 0
when 'stop'
stop
exit 0
when 'restart'
stop
start
exit 0
else
puts "Usage: /etc/init.d/cruise start|stop|restart"
exit 1
end

Keine Kommentare

Kommentar veröffentlichen