Created
February 23, 2010 04:24
-
-
Save samullen/311852 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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