summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2005-08-10 02:14:13 +0000
committerLuke Kanies <luke@madstop.com>2005-08-10 02:14:13 +0000
commitcb1956df8569b53a002d38c81e2dfe1010110cb7 (patch)
tree569764bcef44990ab158681d65c27cd31f8a87eb
parentbb4b5a544e85e5a56065ebb5dd175fbdea7280d2 (diff)
downloadpuppet-cb1956df8569b53a002d38c81e2dfe1010110cb7.tar.gz
puppet-cb1956df8569b53a002d38c81e2dfe1010110cb7.tar.xz
puppet-cb1956df8569b53a002d38c81e2dfe1010110cb7.zip
adding daemon helper module
git-svn-id: https://reductivelabs.com/svn/puppet/library/trunk@528 980ebf18-57e1-0310-9a29-db15c13687c0
-rwxr-xr-xlib/puppet/daemons.rb27
1 files changed, 27 insertions, 0 deletions
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$