summaryrefslogtreecommitdiffstats
path: root/ext/bin/sleeper
diff options
context:
space:
mode:
authorJames Turnbull <james@lovedthanlost.net>2008-07-15 17:15:05 +1000
committerJames Turnbull <james@lovedthanlost.net>2008-07-15 17:15:05 +1000
commit65b9869362cd39f20609abb93729cb0c3977f0cf (patch)
tree2e13f202324da4be57d2a2a54191c42d2e53fb58 /ext/bin/sleeper
parent4ce7159baba4c637867c91519b5a3b16627dfca5 (diff)
downloadpuppet-65b9869362cd39f20609abb93729cb0c3977f0cf.tar.gz
puppet-65b9869362cd39f20609abb93729cb0c3977f0cf.tar.xz
puppet-65b9869362cd39f20609abb93729cb0c3977f0cf.zip
Further moves from the examples directory and ext directory
Diffstat (limited to 'ext/bin/sleeper')
-rwxr-xr-xext/bin/sleeper67
1 files changed, 67 insertions, 0 deletions
diff --git a/ext/bin/sleeper b/ext/bin/sleeper
new file mode 100755
index 000000000..980d66ac1
--- /dev/null
+++ b/ext/bin/sleeper
@@ -0,0 +1,67 @@
+#!/usr/bin/env ruby -w
+
+###
+# sleep indefinitely as a debug
+
+require 'getoptlong'
+
+#-----------------------------------------------------------------
+def daemonize
+ outfile = "/tmp/sleeperout"
+ if pid = fork()
+ Process.detach(pid)
+ sleep 1
+ # verify that we didn't have any problems starting the daemon
+ if FileTest.exists?(outfile)
+ $stderr.puts "Sleeper failed: %s" % File.read(outfile)
+ File.unlink(outfile)
+ exit(14)
+ else
+ exit(0)
+ end
+ end
+ Process.setsid
+ Dir.chdir("/")
+ begin
+ $stdin.reopen "/dev/null"
+ $stdout.reopen "/dev/null", "a"
+ $stderr.reopen $stdin
+ rescue => detail
+ File.open(outfile, "w") { |f|
+ f.puts detail
+ }
+ exit(12)
+ end
+end
+#-----------------------------------------------------------------
+
+debug = false
+
+result = GetoptLong.new(
+ [ "--debug", "-d", GetoptLong::NO_ARGUMENT ],
+ [ "--help", "-h", GetoptLong::NO_ARGUMENT ]
+)
+
+result.each { |opt,arg|
+ case opt
+ when "--help"
+ puts "There is no help yet"
+ exit
+ when "--debug"
+ debug = true
+ else
+ raise "Invalid option '#{opt}'"
+ end
+}
+
+trap(:INT) {
+ exit
+}
+
+unless debug
+ daemonize()
+end
+
+# Sleep for no more than two minutes
+sleep 120
+exit