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
> [EMAIL PROTECTED] | www.webit.de
> 
> Amtsgericht Dresden | HRB 15422
> GF Sven Haubold, Hagen Malessa


-- 
Posted via http://www.ruby-forum.com/.
_______________________________________________
Ferret-talk mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ferret-talk

Reply via email to