Class: ProcessWanker::PIDService
- Inherits:
-
ProcessService
- Object
- Service
- ProcessService
- ProcessWanker::PIDService
- Defined in:
- lib/service_classes/pid_service.rb
Constant Summary
Constants included from Log
Log::DEBUG, Log::ERROR, Log::INFO, Log::WARN
Instance Attribute Summary
Attributes inherited from Service
#attempt_count, #config_node, #current_state, #dependencies, #ignore, #last_action_time, #last_fail_time, #last_transition_time, #params, #prev_state, #show_state, #stable, #suppress, #want_state, #want_state_mode
Class Method Summary collapse
Instance Method Summary collapse
-
#do_ping ⇒ Object
ping.
-
#do_stop(attempt_count) ⇒ Object
stop.
- #env_hash ⇒ Object
-
#initialize(iparams) ⇒ PIDService
constructor
:start_dir (optional) :run_user (optional) :soft_kill_limit (optional).
Methods inherited from ProcessService
Methods included from Log
debug, error, info, log, set_level, warn
Methods inherited from Service
#check_action_delay, #do_start, #extract_params, #group_name, #matches_single, #matches_spec, #name, #resolve_dependencies, #safe_do, #safe_do_ping, #safe_do_start, #safe_do_stop, #set_want_state, #tick, #validate_params
Constructor Details
#initialize(iparams) ⇒ PIDService
:start_dir (optional)
:run_user (optional)
:soft_kill_limit (optional)
plus anything to be passed to Service
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/service_classes/pid_service.rb', line 43 def initialize(iparams) # extract parameters extract_params( iparams, [ :pid_file, ]) raise "service has no pid_file" if(!@params[:pid_file]) super(iparams) end |
Class Method Details
.nice_name ⇒ Object
25 26 27 |
# File 'lib/service_classes/pid_service.rb', line 25 def self.nice_name "pid_service" end |
Instance Method Details
#do_ping ⇒ Object
ping
return run state of process
93 94 95 96 97 98 99 100 |
# File 'lib/service_classes/pid_service.rb', line 93 def do_ping begin pid = File.read(@params[:pid_file]).strip.to_i return(:up) if(ProcessUtil::all_processes[pid]) rescue Exception => e end :down end |
#do_stop(attempt_count) ⇒ Object
stop
stop the process (either with -TERM or -KILL)
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/service_classes/pid_service.rb', line 65 def do_stop(attempt_count) info("do_stop[#{attempt_count}] for #{self.name}") kl=@params[:soft_kill_limit] mode = (kl && attempt_count >= kl) ? :hard : :soft if(mode == :soft) if(params[:stop_cmd]) system(params[:stop_cmd]) return end end ProcessWanker::with_logged_rescue("PidServer::do_stop - reading pid file") do pid = File.read(@params[:pid_file]).strip.to_i Process.kill({ :hard => "KILL", :soft => "TERM" }[mode],pid) end end |
#env_hash ⇒ Object
109 110 111 |
# File 'lib/service_classes/pid_service.rb', line 109 def env_hash() nil end |