Sha256: e5715120c7f8c3135e4ac539a5c49515cd8905e8e7407811456fe074ab57cbde

Contents?: true

Size: 1.29 KB

Versions: 5

Compression:

Stored size: 1.29 KB

Contents

#!/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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
puppet-0.24.9 ext/bin/sleeper
puppet-0.24.6 ext/bin/sleeper
puppet-0.24.5 ext/bin/sleeper
puppet-0.24.7 ext/bin/sleeper
puppet-0.24.8 ext/bin/sleeper