Adam Thorsen
2007-Mar-05 16:25 UTC
[Ferret-talk] programatically stopping acts_as_ferret drb server
I need a way to kill the ferret_server drb process programatically, so I can start/stop it as part of the capistrano deployment process. This should be as simple as adding some sort of stop method to ActsAsFerret::Remote::Server. I was just messing around and was able to do it by modifying method_missing to look for the :stop method and then calling DRb.thread.exit -- this is not good enough for a general solution however. If anyone has an idea of how it should be done, I can do it and submit a patch. Thanks, -Adam -- Posted via http://www.ruby-forum.com/.
Jens Kraemer
2007-Mar-05 16:53 UTC
[Ferret-talk] programatically stopping acts_as_ferret drb server
Hi! On Mon, Mar 05, 2007 at 05:25:50PM +0100, Adam Thorsen wrote:> I need a way to kill the ferret_server drb process programatically, so I > can start/stop it as part of the capistrano deployment process. > > This should be as simple as adding some sort of stop method to > ActsAsFerret::Remote::Server. I was just messing around and was able to > do it by modifying method_missing to look for the :stop method and then > calling DRb.thread.exit -- this is not good enough for a general > solution however. > > If anyone has an idea of how it should be done, I can do it and submit a > patch.I could imagine a set of start/stop scripts where the start script launched the server as a daemon and recorded it''s pid somewhere. stop the only had to read that pid and kill the process. Those scripts could then be easily be called from cap recipes. Something like Daemonize (http://grub.ath.cx/daemonize/) might come in handy. I''d really appreciate if you could tackle that subject :-) cheers, Jens -- Jens Kr?mer webit! Gesellschaft f?r neue Medien mbH Schnorrstra?e 76 | 01069 Dresden Telefon +49 351 46766-0 | Telefax +49 351 46766-66 kraemer at webit.de | www.webit.de Amtsgericht Dresden | HRB 15422 GF Sven Haubold, Hagen Malessa
Adam Thorsen
2007-Mar-06 01:05 UTC
[Ferret-talk] programatically stopping acts_as_ferret drb server
Ok I''ve put together a couple of scripts that are basically a
hodgepodge
of daemonize, mongrel, and aaf code that start and stop ferret_server.
The start script looks for the pid_file value in ferret_server.yml, then
creates a pid file in config based on that value, forks, end exits.
The stop script looks for the pid_file in the same place and sends the
TERM signal. Upon receiving the TERM signal, script that launched
ferret_server removes the pid file and exits.
Here is the start script:
#!/usr/bin/env script/runner
config =
YAML.load(ERB.new(IO.read("#{RAILS_ROOT}/config/ferret_server.yml")).result)[RAILS_ENV]
@pid_file = "#{RAILS_ROOT}/#{config[''pid_file'']}"
def write_pid_file
open(@pid_file,"w") {|f| f.write(Process.pid) }
end
def safefork
tryagain = true
while tryagain
tryagain = false
begin
if pid = fork
return pid
end
rescue Errno::EWOULDBLOCK
sleep 5
tryagain = true
end
end
end
safefork and exit
write_pid_file
at_exit do
File.unlink(@pid_file) if @pid_file and File.exists?(@pid_file)
end
puts "Starting ferret_server..."
trap("TERM") { exit(0) }
sess_id = Process.setsid
STDIN.reopen "/dev/null" # Free file descriptors and
STDOUT.reopen "/dev/null", "a" # point them somewhere
sensible
STDERR.reopen STDOUT # STDOUT/STDERR should go to a logfile
ActsAsFerret::Remote::Server.start
DRb.thread.join
Here is the Stop Script:
#!/usr/bin/env script/runner
config =
YAML.load(ERB.new(IO.read("#{RAILS_ROOT}/config/ferret_server.yml")).result)[RAILS_ENV]
def send_signal(signal, pid_file)
pid = open(pid_file).read.to_i
print "Sending #{signal} to ferret_server at PID #{pid}..."
begin
Process.kill(signal, pid)
rescue Errno::ESRCH
puts "Process does not exist. Not running."
end
puts "Done."
end
pid_file = config[''pid_file'']
puts "Stopping ferret_server..."
send_signal("TERM", pid_file)
Haven''t really tested them very much but they seem to be working.
Jens Kraemer wrote:> Hi!
>
> On Mon, Mar 05, 2007 at 05:25:50PM +0100, Adam Thorsen wrote:
>> patch.
> I could imagine a set of start/stop scripts where the start script
> launched the server as a daemon and recorded it''s pid somewhere.
stop
> the only had to read that pid and kill the process. Those scripts could
> then be easily be called from cap recipes.
>
> Something like Daemonize (http://grub.ath.cx/daemonize/) might come in
> handy.
>
> I''d really appreciate if you could tackle that subject :-)
>
> cheers,
> Jens
>
>
> --
> Jens Kr?mer
> webit! Gesellschaft f?r neue Medien mbH
> Schnorrstra?e 76 | 01069 Dresden
> Telefon +49 351 46766-0 | Telefax +49 351 46766-66
> kraemer at webit.de | www.webit.de
>
> Amtsgericht Dresden | HRB 15422
> GF Sven Haubold, Hagen Malessa
--
Posted via http://www.ruby-forum.com/.
Jens Kraemer
2007-Mar-06 09:53 UTC
[Ferret-talk] programatically stopping acts_as_ferret drb server
On Tue, Mar 06, 2007 at 02:05:20AM +0100, Adam Thorsen wrote:> Ok I''ve put together a couple of scripts that are basically a hodgepodge > of daemonize, mongrel, and aaf code that start and stop ferret_server. > > The start script looks for the pid_file value in ferret_server.yml, then > creates a pid file in config based on that value, forks, end exits. > > The stop script looks for the pid_file in the same place and sends the > TERM signal. Upon receiving the TERM signal, script that launched > ferret_server removes the pid file and exits.cool, I''ll add this to trunk asap! cheers, Jens -- Jens Kr?mer webit! Gesellschaft f?r neue Medien mbH Schnorrstra?e 76 | 01069 Dresden Telefon +49 351 46766-0 | Telefax +49 351 46766-66 kraemer at webit.de | www.webit.de Amtsgericht Dresden | HRB 15422 GF Sven Haubold, Hagen Malessa