Class: Kinetic::Master
- Inherits:
-
Object
- Object
- Kinetic::Master
- Defined in:
- lib/kinetic/master.rb
Constant Summary collapse
- SELF_PIPE =
[]
- QUEUE_SIGS =
[ :WINCH, :QUIT, :INT, :TERM, :USR1, :USR2, :HUP, :TTIN, :TTOU ]
- WORKERS =
{}
- SIG_QUEUE =
[]
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#reexecpid ⇒ Object
readonly
Returns the value of attribute reexecpid.
Instance Method Summary collapse
-
#initialize(app) ⇒ Master
constructor
A new instance of Master.
-
#run ⇒ Object
Starts and initializes the master process.
-
#start ⇒ Object
Starts and daemonizes the master process.
- #stop ⇒ Object
Constructor Details
#initialize(app) ⇒ Master
Returns a new instance of Master.
14 15 16 |
# File 'lib/kinetic/master.rb', line 14 def initialize(app) @app = app end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
12 13 14 |
# File 'lib/kinetic/master.rb', line 12 def app @app end |
#reexecpid ⇒ Object (readonly)
Returns the value of attribute reexecpid.
12 13 14 |
# File 'lib/kinetic/master.rb', line 12 def reexecpid @reexecpid end |
Instance Method Details
#run ⇒ Object
Starts and initializes the master process.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/kinetic/master.rb', line 30 def run begin daemonize if config[:daemonize] enable_logging! logger.debug 'Configuration:' logger.ap app.config.to_hash proc_name 'master' initialize_self_pipe! initialize_signal_traps! spawn_missing_workers join rescue => e logger.fatal e logger.fatal 'Unable to start worker!' ensure call_on_exit_callbacks exit! end end |
#start ⇒ Object
Starts and daemonizes the master process
19 20 21 22 23 24 25 26 27 |
# File 'lib/kinetic/master.rb', line 19 def start if File.exists?(config.pid) puts "Unable to start master process, a process with the pidfile #{config.pid} already exists." + 'If you wish to run another instance of this application please pass --pid to set a new pid file.' exit(1) end config.daemonize = true run end |
#stop ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/kinetic/master.rb', line 50 def stop unless File.exists?(File.join(config.root, config.pid)) puts "Unable to stop process, a process with the pidfile #{config.pid} could not be found" + 'If you have started this app with another pid file location pass --pid to set the pid file.' exit(1) end pid = File.open(File.join(config.root, config.pid), 'r') { |f| f.read }.to_i Process.kill(:QUIT, pid) end |