Created
August 23, 2012 07:17
-
-
Save watermint/3433770 to your computer and use it in GitHub Desktop.
Restart Node
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
pipe = '/somewhere/commands' | |
launch_cmd = 'cd /somewhere ; node' | |
process_name = 'node' | |
open(pipe, 'r') do |f| | |
begin | |
f.each_line do |line| | |
case line.strip | |
when 'restart' | |
pid = `pidof $process_name` | |
unless pid.empty? then | |
puts "Kill pid: #{pid}" | |
`kill #{pid}` | |
end | |
begin | |
pid = `pidof $process_name` | |
sleep 1 | |
puts "Waiting for shutdown" | |
`kill #{pid}` unless pid.empty? | |
end while !pid.empty? | |
puts "Start" | |
job = fork do | |
exec $launch_cmd | |
end | |
Process.detach(job) | |
end | |
end | |
sleep 5 | |
end while true | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment