Module: Luban::Deployment::Service::Controller::Base
- Defined in:
- lib/luban/deployment/cli/service/controller.rb
Instance Method Summary collapse
- #check_monitor_status(output: :info) ⇒ Object
- #check_process ⇒ Object
- #default_pending_interval ⇒ Object
- #default_pending_seconds ⇒ Object
- #kill_process ⇒ Object
- #monitor_check ⇒ Object
- #monitor_control_file_path ⇒ Object
- #monitor_executable ⇒ Object
- #monitor_off ⇒ Object
- #monitor_on ⇒ Object
- #monitor_process(output: :info) ⇒ Object
- #monitor_reload ⇒ Object
- #pid ⇒ Object
- #pid_file_exists? ⇒ Boolean
- #pid_file_missing? ⇒ Boolean
- #pid_file_orphaned? ⇒ Boolean
- #process_started? ⇒ Boolean
- #process_stopped? ⇒ Boolean
- #reload_monitor_process(output: :info) ⇒ Object
- #restart_process ⇒ Object
- #show_process ⇒ Object
- #start_process ⇒ Object
- #stop_process ⇒ Object
- #unmonitor_process(output: :info) ⇒ Object
Instance Method Details
#check_monitor_status(output: :info) ⇒ Object
170 171 172 |
# File 'lib/luban/deployment/cli/service/controller.rb', line 170 def check_monitor_status(output: :info) send(output, check_monitor_status!) end |
#check_process ⇒ Object
106 107 108 |
# File 'lib/luban/deployment/cli/service/controller.rb', line 106 def check_process update_result check_process! end |
#default_pending_interval ⇒ Object
175 |
# File 'lib/luban/deployment/cli/service/controller.rb', line 175 def default_pending_interval; 1; end |
#default_pending_seconds ⇒ Object
174 |
# File 'lib/luban/deployment/cli/service/controller.rb', line 174 def default_pending_seconds; 30; end |
#kill_process ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/luban/deployment/cli/service/controller.rb', line 114 def kill_process if process_stopped? update_result "Skipped! Already stopped #{service_full_name}", status: :skipped return end unmonitor_process if monitorable? 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_check ⇒ Object
142 143 144 |
# File 'lib/luban/deployment/cli/service/controller.rb', line 142 def monitor_check check_monitor_status(output: :update_result) end |
#monitor_control_file_path ⇒ Object
41 42 43 44 |
# File 'lib/luban/deployment/cli/service/controller.rb', line 41 def monitor_control_file_path @monitor_control_file_path ||= env_path.join(process_monitor[:env], 'shared', 'profile', process_monitor[:name], monitor_control_file_name) end |
#monitor_executable ⇒ Object
36 37 38 39 |
# File 'lib/luban/deployment/cli/service/controller.rb', line 36 def monitor_executable @monitor_executable ||= env_path.join(process_monitor[:env], 'bin', process_monitor[:name]) end |
#monitor_off ⇒ Object
134 135 136 |
# File 'lib/luban/deployment/cli/service/controller.rb', line 134 def monitor_off unmonitor_process(output: :update_result) end |
#monitor_on ⇒ Object
130 131 132 |
# File 'lib/luban/deployment/cli/service/controller.rb', line 130 def monitor_on monitor_process(output: :update_result) end |
#monitor_process(output: :info) ⇒ Object
146 147 148 149 150 151 152 |
# File 'lib/luban/deployment/cli/service/controller.rb', line 146 def monitor_process(output: :info) if monitor_process! send(output, "Turned on process monitor for #{service_entry}") else send(output, "Failed to turn on process monitor for #{service_entry}") end end |
#monitor_reload ⇒ Object
138 139 140 |
# File 'lib/luban/deployment/cli/service/controller.rb', line 138 def monitor_reload reload_monitor_process(output: :update_result) 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_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_process(output: :info) ⇒ Object
162 163 164 165 166 167 168 |
# File 'lib/luban/deployment/cli/service/controller.rb', line 162 def reload_monitor_process(output: :info) if reload_monitor_process! send(output, "Reloaded process monitor for #{service_entry}") else send(output, "Failed to reload process monitor for #{service_entry}") end end |
#restart_process ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/luban/deployment/cli/service/controller.rb', line 80 def restart_process if process_started? unmonitor_process if monitorable? 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 if monitorable? else remove_orphaned_pid_file update_result "Restart #{service_full_name}: [FAILED] #{output}", status: :failed, level: :error end end |
#show_process ⇒ Object
110 111 112 |
# File 'lib/luban/deployment/cli/service/controller.rb', line 110 def show_process update_result show_process! end |
#start_process ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/luban/deployment/cli/service/controller.rb', line 46 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 if monitorable? else remove_orphaned_pid_file update_result "Start #{service_full_name}: [FAILED] #{output}", status: :failed, level: :error end end |
#stop_process ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/luban/deployment/cli/service/controller.rb', line 63 def stop_process if process_stopped? update_result "Skipped! Already stopped #{service_full_name}", status: :skipped return end unmonitor_process if monitorable? 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_process(output: :info) ⇒ Object
154 155 156 157 158 159 160 |
# File 'lib/luban/deployment/cli/service/controller.rb', line 154 def unmonitor_process(output: :info) if unmonitor_process! send(output, "Turned off process monitor for #{service_entry}") else send(output, "Failed to turn off process monitor for #{service_entry}") end end |