Class: SVUtil::ProcessManager
- Inherits:
-
Object
- Object
- SVUtil::ProcessManager
- Defined in:
- lib/svutil/process_manager.rb
Instance Method Summary collapse
- #after_fork(&block) ⇒ Object
-
#initialize(klass_or_instance, config) ⇒ ProcessManager
constructor
A new instance of ProcessManager.
- #start ⇒ Object
Constructor Details
#initialize(klass_or_instance, config) ⇒ ProcessManager
Returns a new instance of ProcessManager.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/svutil/process_manager.rb', line 3 def initialize(klass_or_instance, config) @server_instance = if klass_or_instance.instance_of?(Class) klass_or_instance.new else klass_or_instance end @config = config # TODO: Add ability for users to specify these signals Signal.trap("INT") { shutdown('Interupted', 1) } Signal.trap("TERM") { shutdown('Terminated', 2) } unless RUBY_PLATFORM =~ /(win|w)32$/ Signal.trap("PIPE") { shutdown('Broken Pipe', 4) } end if running? STDERR.puts "There is already a '#{$0}' process running" exit 1 end end |
Instance Method Details
#after_fork(&block) ⇒ Object
36 37 38 |
# File 'lib/svutil/process_manager.rb', line 36 def after_fork(&block) @after_fork = block end |
#start ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/svutil/process_manager.rb', line 23 def start daemonize if @config.daemon write_pid_file begin @server_instance.run rescue StandardError => e Log.error(e.) Log.error(e.backtrace.join("\n")) if @config.trace shutdown("Process Completed with Error", 1) end shutdown("Process Completed") end |