Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 62 lines (56 sloc) 1.666 kB
5849e93 Commit backgroundrb to git
gnufied authored
1 #!/usr/bin/env ruby
2
3 rails_root = File.expand_path(File.join(File.dirname(__FILE__)+"/.."))
4 RAILS_HOME = rails_root
5 PACKET_APP = rails_root + "/vendor/plugins/backgroundrb"
6 WORKER_ROOT = rails_root + "/lib/workers"
7 SERVER_LOGGER = rails_root + "/log/backgroundrb_server.log"
8
9 ["server","framework","lib"].each { |x| $LOAD_PATH.unshift(PACKET_APP + "/#{x}")}
10 $LOAD_PATH.unshift(WORKER_ROOT)
11
12 require RAILS_HOME + '/config/boot.rb'
13 require "active_record"
14 require "active_support"
15 require "rubygems"
16 require "packet"
17 require "meta_worker"
18 require "cron_trigger"
19 require "trigger"
20 require "log_worker"
21 require "yaml"
22 require "erb"
23 require "logger"
24 require "master_worker"
25
26 case ARGV[0]
27 when 'start'
28 if fork
29 exit
30 else
31 path = "#{RAILS_HOME}/log/backgroundrb.pid"
32 config_file = YAML.load(ERB.new(IO.read("#{RAILS_HOME}/config/backgroundrb.yml")).result)
33 op = File.open(path, "w")
34 op.write(Process.pid().to_s)
35 op.close
36 if config_file[:backgroundrb][:log].nil? or config_file[:backgroundrb][:log] != 'foreground'
37 log_file = File.open(SERVER_LOGGER,"w+")
38 [STDIN, STDOUT, STDERR].each {|desc| desc.reopen(log_file)}
39 end
40
41 BackgrounDRb::MasterProxy.new()
42 end
43 when 'stop'
44 path = "#{RAILS_HOME}/log/backgroundrb.pid"
45 pid = nil
46 File.open(path, "r") { |pid_handle| pid = pid_handle.gets.strip.chomp.to_i }
47 begin
48 pgid = Process.getpgid(pid)
49 Process.kill('TERM', pid)
50 Process.kill('-TERM', pgid)
51 Process.kill('KILL', pid)
52 rescue Errno::ESRCH => e
53 puts "Deleting pid file"
54 rescue
55 puts $!
56 ensure
57 File.delete(path) if File.exists?(path)
58 end
59 else
60 BackgrounDRb::MasterProxy.new()
61 end
Something went wrong with that request. Please try again.