Class: Kogno::WebhookCtl
- Inherits:
-
Object
- Object
- Kogno::WebhookCtl
- Defined in:
- lib/core/bin_helpers/webhook_ctl.rb
Class Method Summary collapse
- .alive? ⇒ Boolean
- .delete_pid ⇒ Object
- .fg ⇒ Object
- .get_pid ⇒ Object
- .kill_process(pid) ⇒ Object
- .log_environment_info ⇒ Object
- .options(option) ⇒ Object
- .pid_file ⇒ Object
- .save_pid(pid) ⇒ Object
- .server_file ⇒ Object
- .start ⇒ Object
- .status ⇒ Object
- .stop ⇒ Object
Class Method Details
.alive? ⇒ Boolean
34 35 36 37 38 |
# File 'lib/core/bin_helpers/webhook_ctl.rb', line 34 def alive? pid = get_pid return false if pid == 0 Process.getpgid(pid) rescue false end |
.delete_pid ⇒ Object
21 22 23 |
# File 'lib/core/bin_helpers/webhook_ctl.rb', line 21 def delete_pid save_pid("") end |
.fg ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/core/bin_helpers/webhook_ctl.rb', line 53 def fg log_environment_info() if get_pid > 0 && alive? logger.write "Error: It has already started..", :red else system("RACK_ENV=#{Kogno::Application.config.environment} ruby #{self.server_file}") end end |
.get_pid ⇒ Object
25 26 27 |
# File 'lib/core/bin_helpers/webhook_ctl.rb', line 25 def get_pid File.read(File.join(self.pid_file)).to_i end |
.kill_process(pid) ⇒ Object
29 30 31 32 |
# File 'lib/core/bin_helpers/webhook_ctl.rb', line 29 def kill_process(pid) return false if pid.to_i == 0 Process.kill("KILL",pid) rescue nil end |
.log_environment_info ⇒ Object
9 10 11 |
# File 'lib/core/bin_helpers/webhook_ctl.rb', line 9 def log_environment_info logger.write "Kogno #{Gem.loaded_specs["kogno"].version.version} http server starting in #{Kogno::Application.config.environment}", :bright end |
.options(option) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/core/bin_helpers/webhook_ctl.rb', line 77 def (option) case option.to_s.to_sym when :start self.start when :stop self.stop when :restart self.stop self.start when :status self.status when :fg self.fg else puts "usage: http stop|start|restart|status|fg" end end |
.pid_file ⇒ Object
5 6 7 |
# File 'lib/core/bin_helpers/webhook_ctl.rb', line 5 def pid_file Application.file_path(File.join(Application.project_path,"tmp","webhook.pid")) end |
.save_pid(pid) ⇒ Object
17 18 19 |
# File 'lib/core/bin_helpers/webhook_ctl.rb', line 17 def save_pid(pid) File.write(self.pid_file, pid) end |
.server_file ⇒ Object
13 14 15 |
# File 'lib/core/bin_helpers/webhook_ctl.rb', line 13 def server_file File.join(Application.core_path,"lib/core/web/webhook.rb") end |
.start ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/core/bin_helpers/webhook_ctl.rb', line 40 def start log_environment_info() if get_pid > 0 && alive? logger.write "Error: It has already started..", :red else system(%{ RACK_ENV=#{Kogno::Application.config.environment} ruby #{self.server_file} daemon > /dev/null& echo $! > "#{self.pid_file}" }) logger.write "START", :green end end |
.status ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/core/bin_helpers/webhook_ctl.rb', line 69 def status if alive? logger.write "Running | Pid: #{self.get_pid}..", :green else logger.write "Stopped", :red end end |
.stop ⇒ Object
62 63 64 65 66 67 |
# File 'lib/core/bin_helpers/webhook_ctl.rb', line 62 def stop pid = self.get_pid self.kill_process(pid) self.delete_pid logger.write "STOP", :red end |