corselia
11/28/2017 - 8:47 AM

easy watchdog by ruby

easy watchdog by ruby

command = %Q(pgrep -fl "manet")
processes = []
`#{command}`.each_line do |line|
  processes << line.chomp
end
processes = processes - processes.grep(/\A.*(sh|ruby)\z/)

if processes.empty?
  puts "NOT WORKING...SO REBOOT!"
  command = %Q(nohup manet &)
  `#{command}`
  puts "HAS REBOOTED!"
else
  puts "NOW WORKING!"
  # if kill, use xargs with pipe or pkill
end