Module: Luban::Deployment::Service::Controller::Base
- Defined in:
- lib/luban/deployment/cli/service/controller.rb
Instance Method Summary collapse
- #check_process ⇒ Object
- #default_pending_interval ⇒ Object
- #default_pending_seconds ⇒ Object
- #kill_process ⇒ Object
- #monitor_command ⇒ Object
- #monitor_executable ⇒ Object
- #monitor_process ⇒ Object
- #pid ⇒ Object
- #pid_file_exists? ⇒ Boolean
- #pid_file_missing? ⇒ Boolean
- #pid_file_orphaned? ⇒ Boolean
- #process_monitor_defined? ⇒ Boolean
- #process_started? ⇒ Boolean
- #process_stopped? ⇒ Boolean
- #reload_monitor_command ⇒ Object
- #reload_monitor_process ⇒ Object
- #restart_process ⇒ Object
- #show_process ⇒ Object
- #start_process ⇒ Object
- #stop_process ⇒ Object
- #unmonitor_command ⇒ Object
- #unmonitor_process ⇒ Object
Instance Method Details
#check_process ⇒ Object
112 113 114 |
# File 'lib/luban/deployment/cli/service/controller.rb', line 112 def check_process update_result check_process! end |
#default_pending_interval ⇒ Object
171 |
# File 'lib/luban/deployment/cli/service/controller.rb', line 171 def default_pending_interval; 1; end |
#default_pending_seconds ⇒ Object
170 |
# File 'lib/luban/deployment/cli/service/controller.rb', line 170 def default_pending_seconds; 30; end |
#kill_process ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/luban/deployment/cli/service/controller.rb', line 120 def kill_process if process_stopped? update_result "Skipped! Already stopped #{service_full_name}", status: :skipped return end unmonitor_process output = kill_process! if check_until { process_stopped? } update_result "Kill #{service_full_name}: [OK] #{output}" else update_result "Kill #{service_full_name}: [FAILED] #{output}" end remove_orphaned_pid_file end |
#monitor_command ⇒ Object
40 41 42 |
# File 'lib/luban/deployment/cli/service/controller.rb', line 40 def monitor_command @monitor_command ||= "#{monitor_executable} monitor #{service_entry}" end |
#monitor_executable ⇒ Object
36 37 38 |
# File 'lib/luban/deployment/cli/service/controller.rb', line 36 def monitor_executable @monitor_executable ||= env_path.join("#{stage}.#{process_monitor[:env]}", 'bin', process_monitor[:name]) end |
#monitor_process ⇒ Object
140 141 142 143 144 145 146 147 148 |
# File 'lib/luban/deployment/cli/service/controller.rb', line 140 def monitor_process if process_monitor_defined? if monitor_process! info "Turned on process monitor for #{service_entry}" else info "Failed to turn on process monitor for #{service_entry}" end end end |
#pid ⇒ Object
6 7 8 |
# File 'lib/luban/deployment/cli/service/controller.rb', line 6 def pid capture(:cat, "#{pid_file_path} 2>/dev/null") end |
#pid_file_exists? ⇒ Boolean
26 27 28 |
# File 'lib/luban/deployment/cli/service/controller.rb', line 26 def pid_file_exists? file?(pid_file_path, "-s") # file is NOT zero size end |
#pid_file_missing? ⇒ Boolean
22 23 24 |
# File 'lib/luban/deployment/cli/service/controller.rb', line 22 def pid_file_missing? process_started? and !pid_file_exists? end |
#pid_file_orphaned? ⇒ Boolean
18 19 20 |
# File 'lib/luban/deployment/cli/service/controller.rb', line 18 def pid_file_orphaned? process_stopped? and pid_file_exists? end |
#process_monitor_defined? ⇒ Boolean
136 137 138 |
# File 'lib/luban/deployment/cli/service/controller.rb', line 136 def process_monitor_defined? !process_monitor[:name].nil? end |
#process_started? ⇒ Boolean
10 11 12 |
# File 'lib/luban/deployment/cli/service/controller.rb', line 10 def process_started? !!process_grep.keys.first end |
#process_stopped? ⇒ Boolean
14 15 16 |
# File 'lib/luban/deployment/cli/service/controller.rb', line 14 def process_stopped? !process_started? end |
#reload_monitor_command ⇒ Object
48 49 50 |
# File 'lib/luban/deployment/cli/service/controller.rb', line 48 def reload_monitor_command @reload_monitor_command ||= "#{monitor_executable} reload" end |
#reload_monitor_process ⇒ Object
160 161 162 163 164 165 166 167 168 |
# File 'lib/luban/deployment/cli/service/controller.rb', line 160 def reload_monitor_process if process_monitor_defined? if reload_monitor_process! info "Reloaded process monitor for #{service_entry}" else info "Failed to reload process monitor for #{service_entry}" end end end |
#restart_process ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/luban/deployment/cli/service/controller.rb', line 86 def restart_process if process_started? unmonitor_process output = stop_process! if check_until { process_stopped? } remove_orphaned_pid_file info "Stop #{service_full_name}: [OK] #{output}" else remove_orphaned_pid_file update_result "Stop #{service_full_name}: [FAILED] #{output}", status: :failed, level: :error return end end output = start_process! if check_until { process_started? } update_result "Restart #{service_full_name}: [OK] #{output}" monitor_process else remove_orphaned_pid_file update_result "Restart #{service_full_name}: [FAILED] #{output}", status: :failed, level: :error end end |
#show_process ⇒ Object
116 117 118 |
# File 'lib/luban/deployment/cli/service/controller.rb', line 116 def show_process update_result show_process! end |
#start_process ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/luban/deployment/cli/service/controller.rb', line 52 def start_process if process_started? update_result "Skipped! Already started #{service_full_name}", status: :skipped return end output = start_process! if check_until { process_started? } update_result "Start #{service_full_name}: [OK] #{output}" monitor_process else remove_orphaned_pid_file update_result "Start #{service_full_name}: [FAILED] #{output}", status: :failed, level: :error end end |
#stop_process ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/luban/deployment/cli/service/controller.rb', line 69 def stop_process if process_stopped? update_result "Skipped! Already stopped #{service_full_name}", status: :skipped return end unmonitor_process output = stop_process! || 'OK' if check_until { process_stopped? } update_result "Stop #{service_full_name}: [OK] #{output}" else update_result "Stop #{service_full_name}: [FAILED] #{output}", status: :failed, level: :error end remove_orphaned_pid_file end |
#unmonitor_command ⇒ Object
44 45 46 |
# File 'lib/luban/deployment/cli/service/controller.rb', line 44 def unmonitor_command @unmonitor_command ||= "#{monitor_executable} unmonitor #{service_entry}" end |
#unmonitor_process ⇒ Object
150 151 152 153 154 155 156 157 158 |
# File 'lib/luban/deployment/cli/service/controller.rb', line 150 def unmonitor_process if process_monitor_defined? if unmonitor_process! info "Turned off process monitor for #{service_entry}" else info "Failed to turn off process monitor for #{service_entry}" end end end |