bin/legion in legionio-0.3.1 vs bin/legion in legionio-0.3.2

- old
+ new

@@ -2,64 +2,23 @@ # frozen_string_literal: true require 'optparse' require 'etc' -options = { action: :run } - -daemonize_help = 'run daemonized in the background (default: false)' -pidfile_help = 'the pid filename' -logfile_help = 'the log filename' -include_help = 'an additional $LOAD_PATH (may be used more than once)' -debug_help = 'set $DEBUG to true' -warn_help = 'enable warnings' -time_help = 'only run legion for X seconds' - -op = OptionParser.new -op.banner = 'An example of how to daemonize a long running Ruby process.' -op.separator '' -op.separator 'Usage: server [options]' -op.separator '' - -op.separator '' -op.separator 'Process options:' -op.on('-d', '--daemonize', daemonize_help) { options[:daemonize] = true } -op.on('-p', '--pid PIDFILE', pidfile_help) { |value| options[:pidfile] = value } -op.on('-l', '--log LOGFILE', logfile_help) { |value| options[:logfile] = value } -op.on('-t', '--time 10', time_help) { |value| options[:time_limit] = value } - -op.separator '' -op.separator 'Ruby options:' -op.on('-I', '--include PATH', include_help) do |value| - $LOAD_PATH.unshift(*value.split(':').map do |v| - File.expand_path(v) - end) -end -op.on('--debug', debug_help) { $DEBUG = true } -op.on('--warn', warn_help) { $-w = true } - -op.separator '' -op.separator 'Common options:' -op.on('-h', '--help') { options[:action] = :help } -op.on('-v', '--version') { options[:action] = :version } - -op.separator '' -op.parse!(ARGV) - @children = [] children = 5 if children == 1 - require File.expand_path('lib/legion.rb') unless options[:action] == :help - require File.expand_path('lib/legion/process.rb') unless options[:action] == :help + require 'legion' + require 'legion/process' Legion.start Legion::Process.new(options).run! else children.times do @children.push( Process.fork do - require File.expand_path('lib/legion.rb') unless options[:action] == :help - require File.expand_path('lib/legion/process.rb') unless options[:action] == :help + require 'legion' + require 'legion/process' Legion.start sleep(1) Legion::Process.new(options).run! end @@ -71,18 +30,18 @@ trap('SIGINT') do @quit = true @children.each do |child| Process.kill('SIGINT', child) end - sleep(5) + sleep(0.5) end trap('SIGTERM') do @children.each do |child| Process.kill('SIGTERM', child) end - sleep(5) + sleep(1) end sleep(1) until @quit end