Skip to content

Instantly share code, notes, and snippets.

@samullen
Created February 23, 2010 04:24
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 samullen/311852 to your computer and use it in GitHub Desktop.
Save samullen/311852 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems'
require 'basic_daemon'
basedir = "/tmp"
d = BasicDaemon.new
# for restarts to work properly, you can't use anonymous blocks. In other
# words, blocks have to be assigned to a variable
process = Proc.new do
i = 1
foo = open(basedir + "/out", "w")
while true do
foo.puts "loop: #{i}"
foo.flush
sleep 2
i += 1
end
end
if ARGV[0] == 'start'
d.start &process
elsif ARGV[0] == 'stop'
d.stop
exit!
elsif ARGV[0] == 'restart'
d.restart &process
else
STDERR.puts "wrong! Use start, stop, or restart."
exit!
end
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment