Sha256: 8b5e164e4b1f2a0ed701ee85c748ce8c4e024f6d15ab247e68dfa266041d98c2
Contents?: true
Size: 1.47 KB
Versions: 2
Compression:
Stored size: 1.47 KB
Contents
require 'daemons' require 'pathname' require 'optparse' module DispatchRider class Command def initialize(options = {}) @app_home = Pathname.new(Dir.getwd) @options = { :log_output => true, :dir_mode => :normal, :log_dir => (@app_home + "log").to_s, :dir => (@app_home + "log").to_s, :multiple => false, :monitor => false, :identifier => 0, }.merge(options) end def run(args, &block) process_args(args) process_name = "dispatch_rider.#{@options[:identifier]}" Daemons.run_proc(process_name, @options) do $0 = File.join(@options[:prefix], process_name) if @options[:prefix] Dir.chdir(@app_home.to_s) do block.call end end end private def process_args(args) opts = OptionParser.new do |opts| opts.banner = "Usage: #{File.basename($0)} [options] start|stop|restart|run" opts.on('-h', '--help', 'Show this message') do puts opts exit 1 end opts.on('-i', '--identifier=n', 'A numeric identifier for the worker.') do |n| @options[:identifier] = n end opts.on('-m', '--monitor', 'Start monitor process.') do @options[:monitor] = true end opts.on('-p', '--prefix NAME', "String to be prefixed to worker process names") do |prefix| @options[:prefix] = prefix end end @opts = opts.parse!(args) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
dispatch-rider-2.1.0 | lib/dispatch-rider/command.rb |
dispatch-rider-2.0.0 | lib/dispatch-rider/command.rb |