Skip to content

Instantly share code, notes, and snippets.

@watermint
Created August 23, 2012 07:17
Show Gist options
  • Save watermint/3433770 to your computer and use it in GitHub Desktop.
Save watermint/3433770 to your computer and use it in GitHub Desktop.
Restart Node
#!/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