Skip to content

Instantly share code, notes, and snippets.

@bmarini
Created October 20, 2009 15:55
Show Gist options
  • Save bmarini/214368 to your computer and use it in GitHub Desktop.
Save bmarini/214368 to your computer and use it in GitHub Desktop.
# 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