Sha256: 5429f44235a1af00c8d63919654e121bbd6ed3bb25603a2f3c314a671e8a3295
Contents?: true
Size: 1.6 KB
Versions: 7
Compression:
Stored size: 1.6 KB
Contents
module Workhorse class Daemon::ShellHandler def self.run(**options, &block) unless ARGV.count == 1 usage exit 99 end lockfile_path = options.delete(:lockfile) || 'workhorse.lock' lockfile = File.open(lockfile_path, 'a') lockfile.flock(File::LOCK_EX || File::LOCK_NB) daemon = Workhorse::Daemon.new(**options, &block) begin case ARGV.first when 'start' exit daemon.start when 'stop' exit daemon.stop when 'kill' exit daemon.stop(true) when 'status' exit daemon.status when 'watch' exit daemon.watch when 'restart' exit daemon.restart when 'usage' usage exit 99 else usage end exit 0 rescue => e warn "#{e.message}\n#{e.backtrace.join("\n")}" exit 99 ensure lockfile.flock(File::LOCK_UN) end end def self.usage warn <<USAGE Usage: #{$PROGRAM_NAME} start|stop|status|watch|restart|usage Options: start Start the daemon stop Stop the daemon kill Kill the daemon status Query the status of the daemon. Exit with status 1 if any worker is not running. watch Checks the status (running or stopped) and whether it is as expected. Starts the daemon if it is expected to run but is not. restart Shortcut for consecutive 'stop' and 'start'. usage Show this message Exit status: 0 if OK, 1 if at least one worker has an unexpected status, 99 on all other errors. USAGE end end end
Version data entries
7 entries across 7 versions & 1 rubygems