Class: Daemon::MasterProcess
- Inherits:
-
Object
- Object
- Daemon::MasterProcess
- Includes:
- AASM
- Defined in:
- lib/onapp/engine/master_process.rb,
lib/onapp/engine/master_process/message.rb,
lib/onapp/engine/master_process/daemon_socket.rb,
lib/onapp/engine/master_process/middleware/fork.rb,
lib/onapp/engine/master_process/middleware/check.rb,
lib/onapp/engine/master_process/middleware/listen.rb,
lib/onapp/engine/master_process/middleware/prepare.rb,
lib/onapp/engine/master_process/middleware/pid_file.rb,
lib/onapp/engine/master_process/middleware/setup_tasks.rb,
lib/onapp/engine/master_process/middleware/environment.rb,
lib/onapp/engine/master_process/middleware/stop_service.rb
Defined Under Namespace
Modules: DaemonSocket Classes: Check, Environment, Fork, Listen, Message, PidFile, Prepare, SetupTasks, StopService
Constant Summary
- PROCESS_NAME =
'onapp_engine'- REFRESH_DELAY =
10- START_SIGNAL =
'USR1'- STOP_SIGNAL =
'USR2'- APP =
rack-like application constructed from middlewares
proc do |env, forked| builder = Middleware::Builder.new do use Daemon::MasterProcess::Environment use Daemon::MasterProcess::Prepare use Daemon::MasterProcess::SetupTasks use Daemon::MasterProcess::Listen end if forked builder.insert 0, Daemon::MasterProcess::PidFile builder.insert 0, Daemon::MasterProcess::Fork end builder.insert 0, Daemon::MasterProcess::Check builder.call(env) end
Instance Attribute Summary (collapse)
-
- (Object) forked
readonly
Sets if daemon should fork when running.
-
- (Object) log_file
readonly
Location of log_file.
-
- (Object) logger
Returns the value of attribute logger.
-
- (Object) pid_file
readonly
Location of pid_file.
-
- (Object) runners
readonly
Launched runners.
-
- (Object) stderr
readonly
Sets stdout and stderr streams when forking.
-
- (Object) stdout
readonly
Sets stdout and stderr streams when forking.
Class Method Summary (collapse)
-
+ (Fixnum) another_instance_pid
Finds onapp-engine process.
- + (Object) delete_pid
- + (Object) logger
- + (Pathname) pid_file
- + (Object) write_pid
Instance Method Summary (collapse)
- - (Object) another_instance_pid
-
- (MasterProcess) initialize(opts = {})
constructor
A new instance of MasterProcess.
- - (Object) run
- - (Object) stop_service
Constructor Details
- (MasterProcess) initialize(opts = {})
Returns a new instance of MasterProcess
104 105 106 107 108 109 110 111 |
# File 'lib/onapp/engine/master_process.rb', line 104 def initialize(opts = {}) @log_file = opts.fetch(:log_file, Daemon.log_dir.join("#{PROCESS_NAME}.log")).to_s @logger = Daemon::Logger.new(File.open(@log_file, 'a').tap { |f| f.sync = true}) @logger.level = ::Logger::DEBUG @forked = opts.fetch(:forked, false) @pid_file = opts.fetch(:pid_file, Daemon.pid_dir.join("#{PROCESS_NAME}.pid")).to_s @runners = [] end |
Instance Attribute Details
- (Object) forked (readonly)
Sets if daemon should fork when running
63 64 65 |
# File 'lib/onapp/engine/master_process.rb', line 63 def forked @forked end |
- (Object) log_file (readonly)
Location of log_file
73 74 75 |
# File 'lib/onapp/engine/master_process.rb', line 73 def log_file @log_file end |
- (Object) logger
Returns the value of attribute logger
60 61 62 |
# File 'lib/onapp/engine/master_process.rb', line 60 def logger @logger end |
- (Object) pid_file (readonly)
Location of pid_file
70 71 72 |
# File 'lib/onapp/engine/master_process.rb', line 70 def pid_file @pid_file end |
- (Object) runners (readonly)
Launched runners
76 77 78 |
# File 'lib/onapp/engine/master_process.rb', line 76 def runners @runners end |
- (Object) stderr (readonly)
Sets stdout and stderr streams when forking
66 67 68 |
# File 'lib/onapp/engine/master_process.rb', line 66 def stderr @stderr end |
- (Object) stdout (readonly)
Sets stdout and stderr streams when forking
66 67 68 |
# File 'lib/onapp/engine/master_process.rb', line 66 def stdout @stdout end |
Class Method Details
+ (Fixnum) another_instance_pid
Finds onapp-engine process
82 83 84 |
# File 'lib/onapp/engine/master_process.rb', line 82 def another_instance_pid Daemon::Utils::Process.find('ruby', PROCESS_NAME).first end |
+ (Object) delete_pid
95 96 97 |
# File 'lib/onapp/engine/master_process.rb', line 95 def delete_pid File.delete(pid_file) if File.file?(pid_file) end |
+ (Object) logger
99 100 101 |
# File 'lib/onapp/engine/master_process.rb', line 99 def logger @logger ||= ::Logger.new($stdout) end |
+ (Pathname) pid_file
87 88 89 |
# File 'lib/onapp/engine/master_process.rb', line 87 def pid_file Daemon.pid_dir.join("#{PROCESS_NAME}.pid") end |
+ (Object) write_pid
91 92 93 |
# File 'lib/onapp/engine/master_process.rb', line 91 def write_pid File.write(pid_file, Process.pid) end |
Instance Method Details
- (Object) another_instance_pid
117 118 119 |
# File 'lib/onapp/engine/master_process.rb', line 117 def another_instance_pid self.class.another_instance_pid end |
- (Object) run
113 114 115 |
# File 'lib/onapp/engine/master_process.rb', line 113 def run APP.call(self, @forked) end |
- (Object) stop_service
121 122 123 |
# File 'lib/onapp/engine/master_process.rb', line 121 def stop_service @stop_service ||= StopService.new(self, logger) end |