Parent

BackgrounDRb::StartStop

Public Instance Methods

kill_process(arg_pid_file) click to toggle source

(Not documented)

    # File lib/backgroundrb/bdrb_start_stop.rb, line 3
 3:     def kill_process arg_pid_file
 4:       pid = nil
 5:       pid = File.open(arg_pid_file, "r") { |pid_handle| pid_handle.gets.strip.chomp.to_i }
 6:       pgid =  Process.getpgid(pid)
 7:       puts "Stopping BackgrounDRb with pid #{pid}...."
 8:       Process.kill('-TERM', pgid)
 9:       File.delete(arg_pid_file) if File.exists?(arg_pid_file)
10:       puts "Success!"
11:     end
really_running?(pid) click to toggle source

(Not documented)

    # File lib/backgroundrb/bdrb_start_stop.rb, line 16
16:     def really_running? pid
17:       begin
18:         Process.kill(0,pid)
19:         true
20:       rescue Errno::ESRCH
21:         puts "pid file exists but process doesn't seem to be running restarting now"
22:         false
23:       end
24:     end
running?() click to toggle source

(Not documented)

    # File lib/backgroundrb/bdrb_start_stop.rb, line 14
14:     def running?; File.exists?(PID_FILE); end
start() click to toggle source

(Not documented)

    # File lib/backgroundrb/bdrb_start_stop.rb, line 35
35:     def start
36:       if fork
37:         sleep(5)
38:         exit(0)
39:       else
40:         try_restart if running?
41:         puts "Starting BackgrounDRb .... "
42:         op = File.open(PID_FILE, "w")
43:         op.write(Process.pid().to_s)
44:         op.close
45:         if BDRB_CONFIG[:backgroundrb][:log].nil? or BDRB_CONFIG[:backgroundrb][:log] != 'foreground'
46:           log_file = File.open(SERVER_LOGGER,"w+")
47:           [STDIN, STDOUT, STDERR].each {|desc| desc.reopen(log_file)}
48:         end
49: 
50:         BackgrounDRb::MasterProxy.new()
51:       end
52:     end
stop() click to toggle source

(Not documented)

    # File lib/backgroundrb/bdrb_start_stop.rb, line 54
54:     def stop
55:       pid_files = Dir["#{RAILS_HOME}/tmp/pids/backgroundrb_*.pid"]
56:       pid_files.each { |x| kill_process(x) }
57:     end
try_restart() click to toggle source

(Not documented)

    # File lib/backgroundrb/bdrb_start_stop.rb, line 26
26:     def try_restart
27:       pid = nil
28:       pid = File.open(PID_FILE, "r") { |pid_handle| pid_handle.gets.strip.chomp.to_i }
29:       if really_running? pid
30:         puts "pid file already exists, exiting..."
31:         exit(-1)
32:       end
33:     end

secsequence

--- SEC00012

seccomment

--- ""

method_list

--- 
- methods: 
  - visibility: public
    aref: M000042
    name: kill_process
    sourcecode: "    <span class=\"ruby-comment cmt\"># File lib/backgroundrb/bdrb_start_stop.rb, line 3</span>\n 3:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">kill_process</span> <span class=\"ruby-identifier\">arg_pid_file</span>\n 4:       <span class=\"ruby-identifier\">pid</span> = <span class=\"ruby-keyword kw\">nil</span>\n 5:       <span class=\"ruby-identifier\">pid</span> = <span class=\"ruby-constant\">File</span>.<span class=\"ruby-identifier\">open</span>(<span class=\"ruby-identifier\">arg_pid_file</span>, <span class=\"ruby-value str\">&quot;r&quot;</span>) { <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">pid_handle</span><span class=\"ruby-operator\">|</span> <span class=\"ruby-identifier\">pid_handle</span>.<span class=\"ruby-identifier\">gets</span>.<span class=\"ruby-identifier\">strip</span>.<span class=\"ruby-identifier\">chomp</span>.<span class=\"ruby-identifier\">to_i</span> }\n 6:       <span class=\"ruby-identifier\">pgid</span> =  <span class=\"ruby-constant\">Process</span>.<span class=\"ruby-identifier\">getpgid</span>(<span class=\"ruby-identifier\">pid</span>)\n 7:       <span class=\"ruby-identifier\">puts</span> <span class=\"ruby-node\">&quot;Stopping BackgrounDRb with pid #{pid}....&quot;</span>\n 8:       <span class=\"ruby-constant\">Process</span>.<span class=\"ruby-identifier\">kill</span>(<span class=\"ruby-value str\">'-TERM'</span>, <span class=\"ruby-identifier\">pgid</span>)\n 9:       <span class=\"ruby-constant\">File</span>.<span class=\"ruby-identifier\">delete</span>(<span class=\"ruby-identifier\">arg_pid_file</span>) <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-constant\">File</span>.<span class=\"ruby-identifier\">exists?</span>(<span class=\"ruby-identifier\">arg_pid_file</span>)\n\
      10:       <span class=\"ruby-identifier\">puts</span> <span class=\"ruby-value str\">&quot;Success!&quot;</span>\n\
      11:     <span class=\"ruby-keyword kw\">end</span>"
    params: (arg_pid_file)
  - visibility: public
    aref: M000044
    name: really_running?
    sourcecode: "    <span class=\"ruby-comment cmt\"># File lib/backgroundrb/bdrb_start_stop.rb, line 16</span>\n\
      16:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">really_running?</span> <span class=\"ruby-identifier\">pid</span>\n\
      17:       <span class=\"ruby-keyword kw\">begin</span>\n\
      18:         <span class=\"ruby-constant\">Process</span>.<span class=\"ruby-identifier\">kill</span>(<span class=\"ruby-value\">0</span>,<span class=\"ruby-identifier\">pid</span>)\n\
      19:         <span class=\"ruby-keyword kw\">true</span>\n\
      20:       <span class=\"ruby-keyword kw\">rescue</span> <span class=\"ruby-constant\">Errno</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">ESRCH</span>\n\
      21:         <span class=\"ruby-identifier\">puts</span> <span class=\"ruby-value str\">&quot;pid file exists but process doesn't seem to be running restarting now&quot;</span>\n\
      22:         <span class=\"ruby-keyword kw\">false</span>\n\
      23:       <span class=\"ruby-keyword kw\">end</span>\n\
      24:     <span class=\"ruby-keyword kw\">end</span>"
    params: (pid)
  - visibility: public
    aref: M000043
    name: running?
    sourcecode: "    <span class=\"ruby-comment cmt\"># File lib/backgroundrb/bdrb_start_stop.rb, line 14</span>\n\
      14:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">running?</span>; <span class=\"ruby-constant\">File</span>.<span class=\"ruby-identifier\">exists?</span>(<span class=\"ruby-constant\">PID_FILE</span>); <span class=\"ruby-keyword kw\">end</span>"
    params: ()
  - visibility: public
    aref: M000046
    name: start
    sourcecode: "    <span class=\"ruby-comment cmt\"># File lib/backgroundrb/bdrb_start_stop.rb, line 35</span>\n\
      35:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">start</span>\n\
      36:       <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">fork</span>\n\
      37:         <span class=\"ruby-identifier\">sleep</span>(<span class=\"ruby-value\">5</span>)\n\
      38:         <span class=\"ruby-identifier\">exit</span>(<span class=\"ruby-value\">0</span>)\n\
      39:       <span class=\"ruby-keyword kw\">else</span>\n\
      40:         <span class=\"ruby-identifier\">try_restart</span> <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">running?</span>\n\
      41:         <span class=\"ruby-identifier\">puts</span> <span class=\"ruby-value str\">&quot;Starting BackgrounDRb .... &quot;</span>\n\
      42:         <span class=\"ruby-identifier\">op</span> = <span class=\"ruby-constant\">File</span>.<span class=\"ruby-identifier\">open</span>(<span class=\"ruby-constant\">PID_FILE</span>, <span class=\"ruby-value str\">&quot;w&quot;</span>)\n\
      43:         <span class=\"ruby-identifier\">op</span>.<span class=\"ruby-identifier\">write</span>(<span class=\"ruby-constant\">Process</span>.<span class=\"ruby-identifier\">pid</span>().<span class=\"ruby-identifier\">to_s</span>)\n\
      44:         <span class=\"ruby-identifier\">op</span>.<span class=\"ruby-identifier\">close</span>\n\
      45:         <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-constant\">BDRB_CONFIG</span>[<span class=\"ruby-identifier\">:backgroundrb</span>][<span class=\"ruby-identifier\">:log</span>].<span class=\"ruby-identifier\">nil?</span> <span class=\"ruby-keyword kw\">or</span> <span class=\"ruby-constant\">BDRB_CONFIG</span>[<span class=\"ruby-identifier\">:backgroundrb</span>][<span class=\"ruby-identifier\">:log</span>] <span class=\"ruby-operator\">!=</span> <span class=\"ruby-value str\">'foreground'</span>\n\
      46:           <span class=\"ruby-identifier\">log_file</span> = <span class=\"ruby-constant\">File</span>.<span class=\"ruby-identifier\">open</span>(<span class=\"ruby-constant\">SERVER_LOGGER</span>,<span class=\"ruby-value str\">&quot;w+&quot;</span>)\n\
      47:           [<span class=\"ruby-constant\">STDIN</span>, <span class=\"ruby-constant\">STDOUT</span>, <span class=\"ruby-constant\">STDERR</span>].<span class=\"ruby-identifier\">each</span> {<span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">desc</span><span class=\"ruby-operator\">|</span> <span class=\"ruby-identifier\">desc</span>.<span class=\"ruby-identifier\">reopen</span>(<span class=\"ruby-identifier\">log_file</span>)}\n\
      48:         <span class=\"ruby-keyword kw\">end</span>\n\
      49: \n\
      50:         <span class=\"ruby-constant\">BackgrounDRb</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">MasterProxy</span>.<span class=\"ruby-identifier\">new</span>()\n\
      51:       <span class=\"ruby-keyword kw\">end</span>\n\
      52:     <span class=\"ruby-keyword kw\">end</span>"
    params: ()
  - visibility: public
    aref: M000047
    name: stop
    sourcecode: "    <span class=\"ruby-comment cmt\"># File lib/backgroundrb/bdrb_start_stop.rb, line 54</span>\n\
      54:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">stop</span>\n\
      55:       <span class=\"ruby-identifier\">pid_files</span> = <span class=\"ruby-constant\">Dir</span>[<span class=\"ruby-node\">&quot;#{RAILS_HOME}/tmp/pids/backgroundrb_*.pid&quot;</span>]\n\
      56:       <span class=\"ruby-identifier\">pid_files</span>.<span class=\"ruby-identifier\">each</span> { <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">x</span><span class=\"ruby-operator\">|</span> <span class=\"ruby-identifier\">kill_process</span>(<span class=\"ruby-identifier\">x</span>) }\n\
      57:     <span class=\"ruby-keyword kw\">end</span>"
    params: ()
  - visibility: public
    aref: M000045
    name: try_restart
    sourcecode: "    <span class=\"ruby-comment cmt\"># File lib/backgroundrb/bdrb_start_stop.rb, line 26</span>\n\
      26:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">try_restart</span>\n\
      27:       <span class=\"ruby-identifier\">pid</span> = <span class=\"ruby-keyword kw\">nil</span>\n\
      28:       <span class=\"ruby-identifier\">pid</span> = <span class=\"ruby-constant\">File</span>.<span class=\"ruby-identifier\">open</span>(<span class=\"ruby-constant\">PID_FILE</span>, <span class=\"ruby-value str\">&quot;r&quot;</span>) { <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">pid_handle</span><span class=\"ruby-operator\">|</span> <span class=\"ruby-identifier\">pid_handle</span>.<span class=\"ruby-identifier\">gets</span>.<span class=\"ruby-identifier\">strip</span>.<span class=\"ruby-identifier\">chomp</span>.<span class=\"ruby-identifier\">to_i</span> }\n\
      29:       <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">really_running?</span> <span class=\"ruby-identifier\">pid</span>\n\
      30:         <span class=\"ruby-identifier\">puts</span> <span class=\"ruby-value str\">&quot;pid file already exists, exiting...&quot;</span>\n\
      31:         <span class=\"ruby-identifier\">exit</span>(<span class=\"ruby-value\">-1</span>)\n\
      32:       <span class=\"ruby-keyword kw\">end</span>\n\
      33:     <span class=\"ruby-keyword kw\">end</span>"
    params: ()
  category: Instance
  type: Public

sectitle

--- 

[Validate]

Generated with the Darkfish Rdoc Generator.