Skip to content

Instantly share code, notes, and snippets.

@coop
Created July 3, 2012 10:14
Show Gist options
  • Select an option

  • Save coop/3038892 to your computer and use it in GitHub Desktop.

Select an option

Save coop/3038892 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
fork do
Process.setsid
exit if fork
if File.exists?('/path/to/pid.pid')
puts 'Pidfile already exists, not starting.'
exit 1
end
Dir.chdir '/'
File.open('/path/to/pid.pid', 'w') { |file| file << Process.pid }
File.umask 0000
$stdin.reopen '/dev/null'
$stdout.reopen File.new('/path/to/logfile', 'a')
$stdout.sync = true
$stderr.sync = true
$stderr.reopen $stdout
Signal.trap('TERM') { exit }
while true do
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment