From cb1956df8569b53a002d38c81e2dfe1010110cb7 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Wed, 10 Aug 2005 02:14:13 +0000 Subject: adding daemon helper module git-svn-id: https://reductivelabs.com/svn/puppet/library/trunk@528 980ebf18-57e1-0310-9a29-db15c13687c0 --- lib/puppet/daemons.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 lib/puppet/daemons.rb (limited to 'lib/puppet') diff --git a/lib/puppet/daemons.rb b/lib/puppet/daemons.rb new file mode 100755 index 000000000..b160d3eed --- /dev/null +++ b/lib/puppet/daemons.rb @@ -0,0 +1,27 @@ +# helper functions for daemons + +require 'puppet' + +module Puppet + module Daemon + def daemonize + if pid = fork() + Process.detach(pid) + exit(0) + end + + Process.setsid + Dir.chdir("/") + begin + $stdin.reopen "/dev/null" + $stdout.reopen "/dev/null", "a" + $stderr.reopen $stdin + rescue => detail + Puppet.err "Could not start %s: %s" % [$0, detail] + exit(12) + end + end + end +end + +# $Id$ -- cgit