Module: Asmodai::Daemon::ProcessManagement
- Included in:
- Asmodai::Daemon
- Defined in:
- lib/asmodai/daemon/process_management.rb
Instance Method Summary collapse
Instance Method Details
#is_running? ⇒ Boolean
10 11 12 |
# File 'lib/asmodai/daemon/process_management.rb', line 10 def is_running? pid_file_path.exist? and ( Process.kill(0,pid); true ) rescue false end |
#pid ⇒ Object
6 7 8 |
# File 'lib/asmodai/daemon/process_management.rb', line 6 def pid pid_file_path.read.strip.to_i rescue 0 end |
#pid_file_path ⇒ Object
2 3 4 |
# File 'lib/asmodai/daemon/process_management.rb', line 2 def pid_file_path Asmodai.root.join("log/#{daemon_name}.pid") end |
#start ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/asmodai/daemon/process_management.rb', line 14 def start if is_running? false else self.new.start true end end |
#terminate ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/asmodai/daemon/process_management.rb', line 23 def terminate if is_running? Process.kill('TERM', pid) while is_running? sleep 0.1 end FileUtils.rm pid_file_path.to_s true else false end end |