Created
July 3, 2012 10:14
-
-
Save coop/3038892 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| 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