Class: Qs::Process
- Inherits:
-
Object
- Object
- Qs::Process
- Defined in:
- lib/qs/process.rb
Constant Summary collapse
- HALT =
'H'.freeze
- STOP =
'S'.freeze
- RESTART =
'R'.freeze
- WAIT_FOR_SIGNALS_TIMEOUT =
15
Instance Attribute Summary collapse
-
#daemon ⇒ Object
readonly
Returns the value of attribute daemon.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#pid_file ⇒ Object
readonly
Returns the value of attribute pid_file.
-
#restart_cmd ⇒ Object
readonly
Returns the value of attribute restart_cmd.
-
#signal_io ⇒ Object
readonly
Returns the value of attribute signal_io.
Instance Method Summary collapse
- #daemonize? ⇒ Boolean
-
#initialize(daemon, options = nil) ⇒ Process
constructor
A new instance of Process.
- #run ⇒ Object
Constructor Details
#initialize(daemon, options = nil) ⇒ Process
Returns a new instance of Process.
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/qs/process.rb', line 17 def initialize(daemon, = nil) ||= {} @daemon = daemon @name = "qs: #{@daemon.process_label}" @logger = @daemon.logger @pid_file = PIDFile.new(@daemon.pid_file) @signal_io = IOPipe.new @restart_cmd = RestartCmd.new skip_daemonize = ignore_if_blank(ENV['QS_SKIP_DAEMONIZE']) @daemonize = !![:daemonize] && !skip_daemonize end |
Instance Attribute Details
#daemon ⇒ Object (readonly)
Returns the value of attribute daemon.
14 15 16 |
# File 'lib/qs/process.rb', line 14 def daemon @daemon end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
14 15 16 |
# File 'lib/qs/process.rb', line 14 def name @name end |
#pid_file ⇒ Object (readonly)
Returns the value of attribute pid_file.
15 16 17 |
# File 'lib/qs/process.rb', line 15 def pid_file @pid_file end |
#restart_cmd ⇒ Object (readonly)
Returns the value of attribute restart_cmd.
15 16 17 |
# File 'lib/qs/process.rb', line 15 def restart_cmd @restart_cmd end |
#signal_io ⇒ Object (readonly)
Returns the value of attribute signal_io.
15 16 17 |
# File 'lib/qs/process.rb', line 15 def signal_io @signal_io end |
Instance Method Details
#daemonize? ⇒ Boolean
54 |
# File 'lib/qs/process.rb', line 54 def daemonize?; @daemonize; end |
#run ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/qs/process.rb', line 31 def run ::Process.daemon(true) if self.daemonize? log "Starting Qs daemon for #{@daemon.name}" $0 = @name @pid_file.write log "PID: #{@pid_file.pid}" @signal_io.setup trap_signals(@signal_io) start_daemon(@daemon) signal = catch(:signal) do wait_for_signals(@signal_io, @daemon) end @signal_io.teardown run_restart_cmd(@daemon, @restart_cmd) if signal == RESTART ensure @pid_file.remove end |