Skip to content

Instantly share code, notes, and snippets.

@jacek213
Forked from zloydadka/file.rb
Created February 16, 2016 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacek213/d8a45495007595d3e1bf to your computer and use it in GitHub Desktop.
Save jacek213/d8a45495007595d3e1bf to your computer and use it in GitHub Desktop.
Write a simple init.d ruby startup script
#!/usr/local/bin/bootup_ruby
# this is /my/daemon/file
require 'rubygems'
require 'daemons'
Daemons.run('main.rb')
#main.rb is the real script
#!/usr/local/bin/bootup_ruby
# This is the /etc/init.d/mydaemon file
APP_NAME = 'MyScript'
APP_PATH = '/my/daemon/file'
case ARGV.first
when 'start'
puts "Starting #{APP_NAME}..."
system(APP_PATH, 'start')
when 'stop'
system(APP_PATH, 'stop')
when 'restart'
system(APP_PATH, 'restart')
end
unless %w{start stop restart}.include? ARGV.first
puts "Usage: #{APP_NAME} {start|stop|restart}"
exit
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment