Skip to content

Instantly share code, notes, and snippets.

@deepthawtz
Created February 28, 2009 00:28
Show Gist options
  • Save deepthawtz/71797 to your computer and use it in GitHub Desktop.
Save deepthawtz/71797 to your computer and use it in GitHub Desktop.
Merb::Server.daemonize
def daemonize(port)
Merb.logger.warn! "About to fork..." if Merb::Config[:verbose]
fork do
Process.setsid
exit if fork
Merb.logger.warn! "In #{Process.pid}" if Merb.logger
File.umask 0000
STDIN.reopen "/dev/null"
STDOUT.reopen "/dev/null", "a"
STDERR.reopen STDOUT
begin
Dir.chdir Merb::Config[:merb_root]
rescue Errno::EACCES => e
Merb.fatal! "You specified Merb root as #{Merb::Config[:merb_root]}, " \
"yet the current user does not have access to it. ", e
end
at_exit { remove_pid_file(port) }
Merb::Config[:port] = port
bootup
end
rescue NotImplementedError => e
Merb.fatal! "Daemonized mode is not supported on your platform. ", e
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment