Created
October 20, 2009 15:55
-
-
Save bmarini/214368 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
# This is a skeleton for a daemon process that behaves well in | |
# a unix environment. | |
# Fork a child process and exit the parent | |
exit(0) if Process.fork | |
# Trap the signal sent by the kill command | |
trap("SIGTERM") { Syslog.warning("I died"); exit(0) } | |
# Establish this process as a new session and process group leader, | |
# with no controlling tty | |
Process.setsid | |
# Ensure we are not on a mounted filesystem, as this process would | |
# allow it to be unmounted | |
Dir.chdir("/") | |
# Clear the file mode creation mask for our process, in case a | |
# mask was inherited from the parent process. | |
File.umask(0000) | |
# Use syslog for logging | |
require 'syslog' | |
Syslog.open | |
loop do | |
Syslog.warning "Looping and logging for no reason!" | |
sleep(2) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment