Class: ChainReactor::Controller
- Inherits:
-
Object
- Object
- ChainReactor::Controller
- Defined in:
- lib/chain-reactor/controller.rb
Overview
The Controller manages starting and stopping of the server, and daemonizing.
Instance Method Summary collapse
-
#initialize(config, log) ⇒ Controller
constructor
Parse the chain file with a ChainfileParser object.
-
#start ⇒ Object
Start the server, as a daemon or on top if –ontop is supplied as a CLI arg.
-
#stop ⇒ Object
Stop a daemonized process via the PID file specified in the options.
Constructor Details
#initialize(config, log) ⇒ Controller
Parse the chain file with a ChainfileParser object.
11 12 13 14 15 16 17 |
# File 'lib/chain-reactor/controller.rb', line 11 def initialize(config,log) @config = config @log = log # log to STDOUT/ERR while parsing the chain file, only daemonize when complete. @reactor = ChainfileParser.new(@config.chainfile,@config,@log).parse end |
Instance Method Details
#start ⇒ Object
Start the server, as a daemon or on top if –ontop is supplied as a CLI arg.
Uses dante as the daemonizer.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/chain-reactor/controller.rb', line 22 def start if not @config.on_top? and RUBY_PLATFORM == 'java' @log.warn { "fork() is not implemented in JRuby, chain-reactor will run on top instead of daemonizing" } @config.on_top = true end # Change output format for logging to file if daemonizing unless @config.on_top? @log.outputters.first.formatter = ChainReactor::PatternFormatter.new(:pattern => "[%l] %d :: %m") @log.info { "Starting daemon, PID file => #{@config.pid_file}" } end # Dante picks up ARGV, so remove it ARGV.replace [] server = Server.new(@config.address,@config.port,@reactor,@log) Dante::Runner.new('chain-reactor').execute(daemon_opts) do server.start(@config.multithreaded?) end end |
#stop ⇒ Object
Stop a daemonized process via the PID file specified in the options.
44 45 46 47 48 |
# File 'lib/chain-reactor/controller.rb', line 44 def stop ARGV.replace [] Dante::Runner.new('chain-reactor').execute(:kill => true, :pid_path => @config.pid_file) end |