Back

保证某个进程不断运行的脚本

发布时间: 2020-09-20 12:05:00

新版本的 openethereum 经常莫名其妙的挂掉 。

非常奇怪。 没办法。所以需要使用crontab 来进行管理。

1. 写一个脚本

vim /home/ubuntu/keep_eth_running.rb , 内容如下:

grep_command = "ps -ef | grep openethereum | grep -v grep"
start_command = "cd ~ && nohup ./openethereum &"

puts "command: |#{grep_command}"
result = `#{grep_command}`

puts "== |" + result + "|" 

is_process_down = false

if result == '' || result == nil
  is_process_down = true
end

if is_process_down
  puts "== restarting command..."
  result = `#{start_command}`
  puts result
else
  puts "== running, nothing to do"
end

2. 在crontab中持续运行

* * * * * ruby /home/ubuntu/keep_eth_running.rb >> /var/log/cron.log 2>&1

Back