Class: Raad::Runner
Constant Summary collapse
- SECOND =
1
- STOP_TIMEOUT =
60 * SECOND
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#pid_file ⇒ Object
Returns the value of attribute pid_file.
-
#service ⇒ Object
Returns the value of attribute service.
Instance Method Summary collapse
-
#initialize(argv, service) ⇒ Runner
constructor
Create a new Runner.
- #run ⇒ Object
Methods included from Daemonizable
#daemonize, #force_kill_and_remove_pid_file, #pid, #post_fork_setup, #read_pid_file, #remove_pid_file, #remove_stale_pid_file, #send_signal, #write_pid_file
Constructor Details
#initialize(argv, service) ⇒ Runner
Create a new Runner
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/raad/runner.rb', line 16 def initialize(argv, service) @argv = argv.dup # lets keep a copy for jruby double-launch (service).parse!(argv) # start/stop @options[:command] = argv[0].to_s.downcase unless ['start', 'stop', 'post_fork'].include?([:command]) puts(">> start|stop command is required") exit!(false) end @service = service @service_name = nil @logger_options = nil @pid_file = nil @stop_signaled = false end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
10 11 12 |
# File 'lib/raad/runner.rb', line 10 def @options end |
#pid_file ⇒ Object
Returns the value of attribute pid_file.
10 11 12 |
# File 'lib/raad/runner.rb', line 10 def pid_file @pid_file end |
#service ⇒ Object
Returns the value of attribute service.
10 11 12 |
# File 'lib/raad/runner.rb', line 10 def service @service end |
Instance Method Details
#run ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/raad/runner.rb', line 35 def run # first load config if present Configuration.load([:config] || File.("./config/#{default_service_name}.rb")) # settings which depends on configuration @service_name = [:name] || Configuration.daemon_name || default_service_name unless [:log_file] [:log_file] = ([:daemonize] ? File.("#{@service_name}.log") : nil) end unless [:log_stdout] [:log_stdout] = ![:daemonize] end @logger_options = { :file => .delete(:log_file) || Configuration.log_file, :stdout => .delete(:log_stdout) || Configuration.log_stdout, :verbose => .delete(:verbose) || Configuration.verbose, :pattern => .delete(:log_pattern) || Configuration.log_pattern, } @pid_file = .delete(:pid_file) || "./#{@service_name}.pid" @stop_timeout = (.delete(:stop_timeout) || Configuration.stop_timeout || STOP_TIMEOUT).to_i # check for stop command, @pid_file must be set if [:command] == 'stop' puts(">> Raad service wrapper v#{VERSION} stopping") # first send the TERM signal which will invoke the daemon wait_or_will method which will timeout after @stop_timeout # if still not stopped afer @stop_timeout + 2, KILL -9 will be sent. success = send_signal('TERM', @stop_timeout + 2) exit(success) end # setup logging Logger.setup(@logger_options) Logger.level = Configuration.log_level if Configuration.log_level Dir.chdir(File.(File.dirname("./"))) unless Raad.test? if [:command] == 'post_fork' # we've been spawned and re executed, finish setup post_fork_setup(@service_name, [:redirect]) run_service else puts(">> Raad service wrapper v#{VERSION} starting") [:daemonize] ? daemonize(@argv, @service_name, [:redirect]) {run_service} : run_service end end |