Sha256: a38af2b11ea6a8fae7324591aa75a1eeafdb5ec4893836839d555ed483e4d64e
Contents?: true
Size: 1.21 KB
Versions: 3
Compression:
Stored size: 1.21 KB
Contents
#!/usr/bin/env ruby require 'fileutils' class Creeperctl attr_reader :stage, :pidfile, :timeout def initialize(stage, pidfile, timeout) @stage = stage @pidfile = pidfile @timeout = timeout done 'No pidfile given' if !pidfile done "Pidfile #{pidfile} does not exist" if !File.exist?(pidfile) done 'Invalid pidfile content' if pid == 0 fetch_process begin send(stage) rescue NoMethodError done 'Invalid control command' end end def fetch_process Process.getpgid(pid) rescue Errno::ESRCH done "Process doesn't exist" end def done(msg) puts msg exit(0) end def pid File.read(pidfile).to_i end def quiet `kill -USR1 #{pid}` end def stop `kill -TERM #{pid}` timeout.times do begin Process.getpgid(pid) rescue Errno::ESRCH FileUtils.rm_f pidfile done 'Creeper shut down gracefully.' end sleep 1 end `kill -9 #{pid}` FileUtils.rm_f pidfile done 'Creeper shut down forcefully.' end def shutdown quiet stop end end stage = ARGV[0] pidfile = ARGV[1] timeout = ARGV[2].to_i timeout = 10 if timeout == 0 Creeperctl.new(stage, pidfile, timeout)
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
creeper-2.0.2 | bin/creeperctl |
creeper-2.0.1 | bin/creeperctl |
creeper-2.0.0 | bin/creeperctl |