Sha256: b7460ff1a0fc1201263711fcab96281d8c59dd8fdc4105c50ab97611f46b8206

Contents?: true

Size: 1.99 KB

Versions: 1

Compression:

Stored size: 1.99 KB

Contents

#!/usr/bin/env ruby
# frozen_string_literal: true
# rubocop:disable all
require 'optparse'

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) {
    |value| $LOAD_PATH.unshift(*value.split(':').map {
      |v| File.expand_path(v)
    })
}
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)

#==============================================================================
# EXECUTE script
#==============================================================================

require File.expand_path('lib/legion.rb') unless options[:action] == :help
Legion.start
require File.expand_path('lib/legion/process.rb') unless options[:action] == :help
# case options[:action]
# when :help    then puts op.to_s
# when :version then puts Legion::VERSION
# else
#   Legion::Process.run!(options)
# end

Legion::Process.new(options).run!

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
legionio-0.2.0 bin/legion