Skip to content

Instantly share code, notes, and snippets.

@ainoya
Created July 28, 2016 06:49
Show Gist options
  • Save ainoya/ea1f4079ab0b7b0011747324a8729fde to your computer and use it in GitHub Desktop.
Save ainoya/ea1f4079ab0b7b0011747324a8729fde to your computer and use it in GitHub Desktop.
damonize process and restart regularly
#!/usr/bin/env ruby
require 'rufus-scheduler'
$stdout.sync = true
scheduler = Rufus::Scheduler.new
def exec_command(cmd)
IO.popen(cmd) do |io|
while (line = io.gets) do
puts line
end
end
end
def deploy_process
puts `git pull`
puts `pip2 install -r requirements.txt`
puts `pkill -f hogescript.py`
exec_command "python2 hogescript.py"
end
scheduler.in '1s' do
deploy_process
end
scheduler.every '30m' do
deploy_process
end
scheduler.join
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment