Class: ParticlePi::Daemon
- Inherits:
-
Object
- Object
- ParticlePi::Daemon
- Defined in:
- lib/particlepi/daemon.rb
Instance Attribute Summary collapse
-
#exit_with_error ⇒ Object
Returns the value of attribute exit_with_error.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #daemonize? ⇒ Boolean
-
#initialize(options = {}) ⇒ Daemon
constructor
A new instance of Daemon.
- #logfile ⇒ Object
- #pidfile ⇒ Object
- #quit! ⇒ Object
- #quit? ⇒ Boolean
- #run! {|_self| ... } ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Daemon
Returns a new instance of Daemon.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/particlepi/daemon.rb', line 13 def initialize( = {}) = @quit = false # Allow swapping out the exit behavior for testing @exit_with_error = lambda do || $stderr.puts exit 1 end end |
Instance Attribute Details
#exit_with_error ⇒ Object
Returns the value of attribute exit_with_error.
11 12 13 |
# File 'lib/particlepi/daemon.rb', line 11 def exit_with_error @exit_with_error end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
10 11 12 |
# File 'lib/particlepi/daemon.rb', line 10 def end |
Instance Method Details
#daemonize? ⇒ Boolean
50 51 52 |
# File 'lib/particlepi/daemon.rb', line 50 def daemonize? [:daemonize] end |
#logfile ⇒ Object
54 55 56 |
# File 'lib/particlepi/daemon.rb', line 54 def logfile [:logfile] end |
#pidfile ⇒ Object
58 59 60 |
# File 'lib/particlepi/daemon.rb', line 58 def pidfile [:pidfile] end |
#quit! ⇒ Object
42 43 44 |
# File 'lib/particlepi/daemon.rb', line 42 def quit! @quit = true end |
#quit? ⇒ Boolean
46 47 48 |
# File 'lib/particlepi/daemon.rb', line 46 def quit? @quit end |
#run! {|_self| ... } ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/particlepi/daemon.rb', line 25 def run! check_pid daemonize if daemonize? write_pid trap_signals if logfile redirect_output elsif daemonize? suppress_output end # Start the worker, passing the daemon install to be able to exit # gracefully by checking daemon.quit? yield(self) if block_given? end |