Class: Sidejobs::Daemon
- Inherits:
-
Object
- Object
- Sidejobs::Daemon
- Defined in:
- lib/sidejobs/daemon.rb
Instance Method Summary collapse
-
#initialize ⇒ Daemon
constructor
A new instance of Daemon.
- #pid ⇒ Object
- #restart ⇒ Object
- #running? ⇒ Boolean
- #start ⇒ Object
- #stop ⇒ Object
- #stopping? ⇒ Boolean
Constructor Details
#initialize ⇒ Daemon
Returns a new instance of Daemon.
4 5 6 |
# File 'lib/sidejobs/daemon.rb', line 4 def initialize @stopping = false end |
Instance Method Details
#pid ⇒ Object
46 47 48 |
# File 'lib/sidejobs/daemon.rb', line 46 def pid File.read(pid_path).to_i rescue nil end |
#restart ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/sidejobs/daemon.rb', line 37 def restart if running? stop start else start end end |
#running? ⇒ Boolean
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/sidejobs/daemon.rb', line 8 def running? if pid begin Process.kill 0, pid true rescue Errno::ESRCH false end else false end end |
#start ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/sidejobs/daemon.rb', line 21 def start unless running? daemonize write_pid trap_signals process end end |
#stop ⇒ Object
30 31 32 33 34 35 |
# File 'lib/sidejobs/daemon.rb', line 30 def stop if running? Process.kill :TERM, pid delete_pid end end |
#stopping? ⇒ Boolean
50 51 52 |
# File 'lib/sidejobs/daemon.rb', line 50 def stopping? @stopping == true end |