Skip to content

Commit

Permalink
fix for double fork
Browse files Browse the repository at this point in the history
  • Loading branch information
gnufied committed May 20, 2009
1 parent c291046 commit 2fce0af
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions lib/backgroundrb/bdrb_start_stop.rb
Expand Up @@ -36,14 +36,14 @@ def stop
# 3 program is not running # 3 program is not running
def status def status
@status ||= begin @status ||= begin
if pidfile_exists? and process_running? if pidfile_exists? and process_running?
0 0
elsif pidfile_exists? # but not process_running elsif pidfile_exists? # but not process_running
1 1
else else
3 3
end end
end end


return @status return @status
end end
Expand Down Expand Up @@ -91,15 +91,25 @@ def start_bdrb
require "bdrb_job_queue" require "bdrb_job_queue"
require "backgroundrb_server" require "backgroundrb_server"


main_pid = fork do #proper way to daemonize - double fork to ensure parent can have no interest in the grandchild
if fork # Parent exits, child continues.
sleep(5)
exit(0)
else
Process.setsid # Become session leader.

op = File.open(PID_FILE, "w")
op.write(Process.pid().to_s)
op.close

if BDRB_CONFIG[:backgroundrb][:log].nil? or BDRB_CONFIG[:backgroundrb][:log] != 'foreground' if BDRB_CONFIG[:backgroundrb][:log].nil? or BDRB_CONFIG[:backgroundrb][:log] != 'foreground'
redirect_io(SERVER_LOGGER) redirect_io(SERVER_LOGGER)
end end
$0 = "backgroundrb master" $0 = "backgroundrb master"
BackgrounDRb::MasterProxy.new() BackgrounDRb::MasterProxy.new()
end end


File.open(PID_FILE, "w") {|pidfile| pidfile.write(main_pid)} #File.open(PID_FILE, "w") {|pidfile| pidfile.write(main_pid)}
end end


def kill_process(pid_file) def kill_process(pid_file)
Expand Down

0 comments on commit 2fce0af

Please sign in to comment.