Olly Lylo
2008-Jan-03 15:03 UTC
[Backgroundrb-devel] Start script not working when run via Rake
Hi there I''m using the latest release (r300) and ''script/backgroundrb start'' works perfectly when executed on the server, but when put inside a Rake task, it doesn''t launch the worker processes. The Rake task is as follows: task :start_backgroundrb do run "cd #{current_path} && ./script/backgroundrb start" end When I run this task, the following files are created in the log directory: backgroundrb.pid backgroundrb_debug.log backgroundrb_server.log Observations: The process ID found in backgroundrb.pid doesn''t exist, backgroundrb_server.log is zero bytes long and backgroundrb_debug.log contains the following: # Logfile created on Thu Jan 03 14:43:24 +0000 2008 by / It looks like the process is being started by Rake, but terminates before the worker processes are started. Could anyone shed any light on why this might be happening and how I can resolve the issue? I have also noticed that calling ''./script/backgroundrb stop'' when BackgroundRB isn''t running throws an exception, which causes problems when executing ''backgroundrb stop'' in a rake task. As a workaround I have modified by ''backgroundrb'' script as follows: when ''stop'' path = "#{RAILS_HOME}/log/backgroundrb.pid" pid = nil begin File.open(path, "r") { |pid_handle| pid pid_handle.gets.strip.chomp.to_i } pgid = Process.getpgid(pid) Process.kill(''TERM'', pid) Process.kill(''-TERM'', pgid) Process.kill(''KILL'', pid) rescue puts $! ensure puts "Deleting pid file" File.delete(path) if File.exists?(path) end Cheers, Olly --- FreeAgent: Streamlined Money Management for UK Freelancers, Contractors and Consultants www.freeagentcentral.co.uk -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/backgroundrb-devel/attachments/20080103/5492d04a/attachment.html
Jason LaPier
2008-Jan-03 16:29 UTC
[Backgroundrb-devel] Start script not working when run via Rake
On Jan 3, 2008 7:03 AM, Olly Lylo <list at lylo.co.uk> wrote:> Hi there > > I''m using the latest release (r300) and ''script/backgroundrb start'' works > perfectly when executed on the server, but when put inside a Rake task, it > doesn''t launch the worker processes. > > The Rake task is as follows: > > task :start_backgroundrb do > run "cd #{current_path} && ./script/backgroundrb start" > end >I don''t know much about rake, but I think you want to use ''sh'' instead of ''run''. http://rake.rubyforge.org/classes/FileUtils.html#M000018 - Jason L. -- My Rails and Linux Blog: http://offtheline.net
Olly Lylo
2008-Jan-03 17:23 UTC
[Backgroundrb-devel] Start script not working when run via Rake
Sorry, I''m saying Rake when actually I mean Capistrano (1.4.1). The tasks I mention are Capistrano tasks and run is a Cap method: http://manuals.rubyonrails.com/read/chapter/104#page290 On 1/3/08, Jason LaPier <jason.lapier at gmail.com> wrote:> > I don''t know much about rake, but I think you want to use ''sh'' instead of > ''run''. > http://rake.rubyforge.org/classes/FileUtils.html#M000018 >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/backgroundrb-devel/attachments/20080103/b1890413/attachment.html
hemant
2008-Jan-03 21:55 UTC
[Backgroundrb-devel] Start script not working when run via Rake
On Jan 3, 2008 8:33 PM, Olly Lylo <list at lylo.co.uk> wrote:> Hi there > > I''m using the latest release (r300) and ''script/backgroundrb start'' works > perfectly when executed on the server, but when put inside a Rake task, it > doesn''t launch the worker processes. > > The Rake task is as follows: > > task :start_backgroundrb do > run "cd #{current_path} && ./script/backgroundrb start" > end > > When I run this task, the following files are created in the log directory: > > backgroundrb.pid > backgroundrb_debug.log > backgroundrb_server.log > > > Observations: The process ID found in backgroundrb.pid doesn''t exist, > backgroundrb_server.log is zero bytes long and backgroundrb_debug.log > contains the following: > > # Logfile created on Thu Jan 03 14:43:24 +0000 2008 by / > > > It looks like the process is being started by Rake, but terminates before > the worker processes are started. Could anyone shed any light on why this > might be happening and how I can resolve the issue? > > I have also noticed that calling ''./script/backgroundrb stop'' when > BackgroundRB isn''t running throws an exception, which causes problems when > executing ''backgroundrb stop'' in a rake task. As a workaround I have > modified by ''backgroundrb'' script as follows: > > when ''stop'' > path = "#{RAILS_HOME}/log/backgroundrb.pid" > pid = nil > begin > File.open(path, "r") { |pid_handle| pid > pid_handle.gets.strip.chomp.to_i } > pgid = Process.getpgid(pid) > Process.kill(''TERM'', pid) > Process.kill(''-TERM'', pgid) > Process.kill(''KILL'', pid) > rescue > puts $! > ensure > puts "Deleting pid file" > File.delete(path) if File.exists?(path) > end >Okay, I have imported changes in stop part of script. Again, are you able to start backgroundrb from command prompt? Is it that, just cap tasks fails? Try printing value of RAILS_HOME and see if its correct. -- Let them talk of their oriental summer climes of everlasting conservatories; give me the privilege of making my own summer with my own coals. http://gnufied.org
Olly Lylo
2008-Jan-04 10:07 UTC
[Backgroundrb-devel] Start script not working when run via Rake
> > Okay, I have imported changes in stop part of script. Again, are you > able to start backgroundrb from command prompt? Is it that, just cap > tasks fails?Works fine from the command prompt -- it just doesn''t start when run from the Cap task. Try printing value of RAILS_HOME and see if its correct.>RAILS_HOME is correct. I''ve added '':log: foreground'' to my YML file and put some logging into the backgroundrb script as detailed below, to try and figure this out: when ''start'' if fork puts ''Exiting'' exit else path = "#{RAILS_HOME}/log/backgroundrb.pid" puts "Path = #{path}" config_file = YAML.load(ERB.new(IO.read ("#{RAILS_HOME}/config/backgroundrb.yml")).result) op = File.open(path, "w") op.write(Process.pid().to_s) op.close if config_file[:backgroundrb][:log].nil? or config_file[:backgroundrb][:log] != ''foreground'' log_file = File.open(SERVER_LOGGER,"w+") [STDIN, STDOUT, STDERR].each {|desc| desc.reopen(log_file)} end puts "Creating proxing" BackgrounDRb::MasterProxy.new() end puts "Done" The output is: Path = /var/www/apps/my_app/releases/20080103141158/log/backgroundrb.pid Creating proxy Exiting This seems fine except the ''puts "Done"'' statement at the end of the block isn''t being callled. Does this give you any idea about what might be happening? Cheers, Olly -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/backgroundrb-devel/attachments/20080104/59bf28b2/attachment.html
Jonathan Wallace
2008-Jan-04 13:15 UTC
[Backgroundrb-devel] Start script not working when run via Rake
I''d like to second this issue as well. I haven''t had time to investigate (maybe an upgrade to the latest capistrano would fix it?) but I have to manually stop and restart bdrb on my production server after a deploy when we''ve updated the worker code. Jonathan On Jan 4, 2008 5:07 AM, Olly Lylo <list at lylo.co.uk> wrote:> > > Okay, I have imported changes in stop part of script. Again, are you > > able to start backgroundrb from command prompt? Is it that, just cap > > tasks fails? > > > Works fine from the command prompt -- it just doesn''t start when run from > the Cap task. > > > Try printing value of RAILS_HOME and see if its correct. > > > > RAILS_HOME is correct. I''ve added '':log: foreground'' to my YML file and put > some logging into the backgroundrb script as detailed below, to try and > figure this out: > > when ''start'' > if fork > puts ''Exiting'' > exit > else > path = "#{RAILS_HOME}/log/backgroundrb.pid" > puts "Path = #{path}" > config_file > YAML.load(ERB.new(IO.read("#{RAILS_HOME}/config/backgroundrb.yml")).result) > op = File.open(path, "w") > op.write(Process.pid().to_s) > op.close > if config_file[:backgroundrb][:log].nil? or > config_file[:backgroundrb][:log] != ''foreground'' > log_file = File.open(SERVER_LOGGER,"w+") > [STDIN, STDOUT, STDERR].each {|desc| desc.reopen(log_file)} > end > > puts "Creating proxing" > BackgrounDRb::MasterProxy.new () > end > puts "Done" > > > The output is: > > Path = /var/www/apps/my_app/releases/20080103141158/log/backgroundrb.pid > Creating proxy > Exiting > > This seems fine except the ''puts "Done"'' statement at the end of the block > isn''t being callled. Does this give you any idea about what might be > happening? > > > Cheers, Olly > _______________________________________________ > Backgroundrb-devel mailing list > Backgroundrb-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/backgroundrb-devel >-- Jonathan Wallace