Module: Cognizant::Process::Actions::Stop
- Included in:
- Cognizant::Process::Actions
- Defined in:
- lib/cognizant/process/actions/stop.rb
Instance Attribute Summary collapse
-
#stop_after_command ⇒ String
The command to run after the process is stopped.
-
#stop_before_command ⇒ String
The command to run before the process is stopped.
-
#stop_command ⇒ String
The command to stop the process with.
-
#stop_env ⇒ Hash
Environment variables for process during stop.
-
#stop_signals ⇒ Array
The signals to pass to the process one by one attempting to stop it.
-
#stop_timeout ⇒ String
The grace time period in seconds for the process to stop within.
Instance Method Summary collapse
- #_stop_result_handler(result, time_left = 0) ⇒ Object
- #reset_attributes! ⇒ Object
- #stop_process ⇒ Object
Instance Attribute Details
#stop_after_command ⇒ String
The command to run after the process is stopped.
37 38 39 |
# File 'lib/cognizant/process/actions/stop.rb', line 37 def stop_after_command @stop_after_command end |
#stop_before_command ⇒ String
The command to run before the process is stopped. The exit status of this command determines whether or not to proceed.
12 13 14 |
# File 'lib/cognizant/process/actions/stop.rb', line 12 def stop_before_command @stop_before_command end |
#stop_command ⇒ String
The command to stop the process with. e.g. “/usr/bin/redis-server”
17 18 19 |
# File 'lib/cognizant/process/actions/stop.rb', line 17 def stop_command @stop_command end |
#stop_env ⇒ Hash
Environment variables for process during stop.
7 8 9 |
# File 'lib/cognizant/process/actions/stop.rb', line 7 def stop_env @stop_env end |
#stop_signals ⇒ Array
The signals to pass to the process one by one attempting to stop it. Each signal is passed within the timeout period over equally divided intervals (min. 2 seconds). Override with signals without “KILL” to never force kill the process. e.g. [“TERM”, “INT”]
25 26 27 |
# File 'lib/cognizant/process/actions/stop.rb', line 25 def stop_signals @stop_signals end |
#stop_timeout ⇒ String
The grace time period in seconds for the process to stop within. Covers the time period for the stop command or signals. After the timeout is over, the process is checked for running status and if not stopped, it re-enters the auto start lifecycle based on conditions.
33 34 35 |
# File 'lib/cognizant/process/actions/stop.rb', line 33 def stop_timeout @stop_timeout end |
Instance Method Details
#_stop_result_handler(result, time_left = 0) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/cognizant/process/actions/stop.rb', line 65 def _stop_result_handler(result, time_left = 0) # If it is a boolean and value is true OR if it's an execution result and it succeeded. if (!!result == result and result) or (result.respond_to?(:succeeded?) and result.succeeded?) unlink_pid if not pid_running? and self.daemonize end # Reset cached pid to read from file or command. @process_pid = nil # Rollback the pending skips. skip_ticks_for(-time_left) if time_left > 0 end |
#reset_attributes! ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/cognizant/process/actions/stop.rb', line 39 def reset_attributes! self.stop_env = {} self.stop_before_command = nil self.stop_command = nil self.stop_signals = ["QUIT", "TERM", "INT"] self.stop_timeout = 30 self.stop_after_command = nil super end |
#stop_process ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/cognizant/process/actions/stop.rb', line 49 def stop_process # We skip so that we're not reinformed about the required transition by the tick. skip_ticks_for(self.stop_timeout) = { env: self.env.merge(self.stop_env), before: self.stop_before_command, command: self.stop_command, signals: self.stop_signals, after: self.stop_after_command, timeout: self.stop_timeout } handle_action('_stop_result_handler', ) end |