summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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$