Zed A. Shaw dijo [Fri, Jun 06, 2008 at 01:01:32AM -0400]:
> That would be the ideal situation, but Ruby doesn't have good enough
> process management APIs to do this portably. To make it work you'd
> have to portably be able to take a PID and see if there's a mongrel
> running with that PID.
>
> You can't use /proc or /sys because that's linux only. You can't use
> `ps` because the OSX morons changed everything, Solaris has different
> format, etc.
>
> If you were to do this, you'd have to dip into C code to pull it off.
>
> Now, if you're only on linux then you could write yourself a small
> little hack to the mongrel_rails script that did this with info out
> of /proc.
Oh, silly me... I thought Ruby's Process class did with the
architectural incompatibilities... What I wrote to check for the
status is quite straightforward:
------------------------------------------------------------
#!/usr/bin/ruby
require 'yaml'
confdir = '/etc/mongrel-cluster/sites-enabled'
restart_cmd = '/etc/init.d/mongrel-cluster restart'
needs_restart = false
(Dir.open(confdir).entries - ['.', '..']).each do |site|
conf = YAML.load_file "#{confdir}/#{site}"
pid_location = [conf['cwd'],
conf['pid_file']].join('/').gsub(/\.pid$/, '*.pid')
pid_files = Dir.glob(pid_location)
pid_files.each do |pidf|
pid = File.read(pidf)
begin
Process.getpgid(pid.to_i)
rescue Errno::ESRCH
warn "Process #{pid} (cluster #{site}) is dead!"
File.unlink pidf
needs_restart = true
end
end
end
system(restart_cmd) if needs_restart
------------------------------------------------------------
(periodically run via cron)
I guess this works in any Unixy environment... I have no idea on
whether Windows implements something similar to Process.getpgid, or
for that matter, anything on Windows' process management.
Greetings,
--
Gunnar Wolf - [EMAIL PROTECTED] - (+52-55)5623-0154 / 1451-2244
PGP key 1024D/8BB527AF 2001-10-23
Fingerprint: 0C79 D2D1 2C4E 9CE4 5973 F800 D80E F35A 8BB5 27AF
_______________________________________________
Mongrel-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/mongrel-users