Skip to content

Instantly share code, notes, and snippets.

@zloydadka
Created October 3, 2011 04:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zloydadka/1258463 to your computer and use it in GitHub Desktop.
Save zloydadka/1258463 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