Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 74 lines (62 sloc) 2.096 kb
5849e93 Commit backgroundrb to git
gnufied authored
1 #!/usr/bin/env ruby
2
17a68dc Implement changes that enables loading of workers by fork and exec
gnufied authored
3 RAILS_HOME = File.expand_path(File.join(File.dirname(__FILE__),".."))
4 BDRB_HOME = File.join(RAILS_HOME,"vendor","plugins","backgroundrb")
5 WORKER_ROOT = File.join(RAILS_HOME,"lib","workers")
6 WORKER_LOAD_ENV = File.join(RAILS_HOME,"script","load_worker_env")
5849e93 Commit backgroundrb to git
gnufied authored
7
17a68dc Implement changes that enables loading of workers by fork and exec
gnufied authored
8 ["server","server/lib","lib","lib/backgroundrb"].each { |x| $LOAD_PATH.unshift(BDRB_HOME + "/#{x}")}
5849e93 Commit backgroundrb to git
gnufied authored
9 $LOAD_PATH.unshift(WORKER_ROOT)
10
4d2270b fix bugs with some reconnection and environment loading
gnufied authored
11 require "rubygems"
12 require "yaml"
13 require "erb"
17a68dc Implement changes that enables loading of workers by fork and exec
gnufied authored
14 require "logger"
15 require "packet"
16 require "optparse"
17
18 require "bdrb_config"
e7f8659 @gnufied fix problem with environment loading and activesupport
authored
19 require RAILS_HOME + "/config/boot"
20 require "active_support"
ef202d0 @benwyrosdick load rails environment before reading backgroundrb.yml since it may incl...
benwyrosdick authored
21
c48505d @gnufied fix issue with unix scheduler working
authored
22 require RAILS_HOME + "/config/boot"
23 require "active_support"
24
a2f38c9 [BUG] ARGV was not passed into config.rb
Alex P authored
25 BackgrounDRb::Config.parse_cmd_options ARGV
25f0426 @gnufied check in test cases
authored
26 BDRB_CONFIG = BackgrounDRb::Config.read_config("#{RAILS_HOME}/config/backgroundrb.yml")
78b956b 1) CLI options are parsed now before loading of RoR environment
Alex P authored
27
12d8846 revert changes for loading env files
Hemant Kumar authored
28 require RAILS_HOME + "/config/environment"
7c53f8d @gnufied finish job queue functionality
authored
29 require "bdrb_job_queue"
14b5c53 fix errors related to load path and stuff
Hemant Kumar authored
30 require "backgroundrb_server"
27b3c2e Commit patch by Alex to implement conditional loading of rails environme...
gnufied authored
31
25f0426 @gnufied check in test cases
authored
32 pid_file = "#{RAILS_HOME}/tmp/pids/backgroundrb_#{BDRB_CONFIG[:backgroundrb][:port]}.pid"
33 SERVER_LOGGER = "#{RAILS_HOME}/log/backgroundrb_debug_#{BDRB_CONFIG[:backgroundrb][:port]}.log"
5849e93 Commit backgroundrb to git
gnufied authored
34
35 case ARGV[0]
36 when 'start'
37 if fork
aa1882b @gnufied fix problem with postgres and forking parent process
authored
38 sleep(5)
5849e93 Commit backgroundrb to git
gnufied authored
39 exit
40 else
27b3c2e Commit patch by Alex to implement conditional loading of rails environme...
gnufied authored
41 op = File.open(pid_file, "w")
5849e93 Commit backgroundrb to git
gnufied authored
42 op.write(Process.pid().to_s)
43 op.close
25f0426 @gnufied check in test cases
authored
44 if BDRB_CONFIG[:backgroundrb][:log].nil? or BDRB_CONFIG[:backgroundrb][:log] != 'foreground'
5849e93 Commit backgroundrb to git
gnufied authored
45 log_file = File.open(SERVER_LOGGER,"w+")
46 [STDIN, STDOUT, STDERR].each {|desc| desc.reopen(log_file)}
47 end
48
49 BackgrounDRb::MasterProxy.new()
50 end
51 when 'stop'
0e8c810 @gnufied make process stopping generic
authored
52 def kill_process arg_pid_file
53 pid = nil
54 File.open(arg_pid_file, "r") { |pid_handle| pid = pid_handle.gets.strip.chomp.to_i }
55 begin
56 pgid = Process.getpgid(pid)
57 Process.kill('TERM', pid)
58 Process.kill('-TERM', pgid)
59 Process.kill('KILL', pid)
60 rescue Errno::ESRCH => e
61 puts "Deleting pid file"
62 rescue
63 puts $!
64 ensure
65 File.delete(arg_pid_file) if File.exists?(arg_pid_file)
66 end
5849e93 Commit backgroundrb to git
gnufied authored
67 end
0e8c810 @gnufied make process stopping generic
authored
68 pid_files = Dir["#{RAILS_HOME}/tmp/pids/backgroundrb_*.pid"]
69 pid_files.each { |x| kill_process(x) }
5849e93 Commit backgroundrb to git
gnufied authored
70 else
71 BackgrounDRb::MasterProxy.new()
72 end
0d74b45 @gnufied make taks runnable on specific hosts
authored
73
Something went wrong with that request. Please try again.