Class: Harbor::Script::Runner
- Inherits:
-
Object
- Object
- Harbor::Script::Runner
- Defined in:
- lib/harbor/script.rb
Constant Summary collapse
- COMMANDS =
%w(start stop restart)
Instance Method Summary collapse
-
#initialize(argv, services, script) ⇒ Runner
constructor
A new instance of Runner.
- #parse! ⇒ Object
- #restart ⇒ Object
- #run! ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(argv, services, script) ⇒ Runner
Returns a new instance of Runner.
102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/harbor/script.rb', line 102 def initialize(argv, services, script) raise ArgumentError.new("services must be a Harbor::Container but was #{services.inspect}") unless services.is_a?(Harbor::Container) @argv = argv @script = script @script_name = @script.to_s @services = services @services.register(@script_name, @script) unless services.registered?(@script_name) parse! end |
Instance Method Details
#parse! ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/harbor/script.rb', line 115 def parse! @options = { :daemonize => false } parser = OptionParser.new do |opts| opts.on("-d", "--daemonize", "Daemonize process") { @options[:daemonize] = true } end parser.parse!(@argv) @command = @argv.shift end |
#restart ⇒ Object
145 146 147 |
# File 'lib/harbor/script.rb', line 145 def restart Harbor::Script.restart(@script.pid_file) end |
#run! ⇒ Object
128 129 130 131 132 133 134 135 |
# File 'lib/harbor/script.rb', line 128 def run! unless COMMANDS.include?(@command) puts "#{@command.inspect} is not a valid command. Commands are: #{COMMANDS.join(", ")}" exit 1 end send(@command) end |
#start ⇒ Object
137 138 139 140 141 142 143 |
# File 'lib/harbor/script.rb', line 137 def start script = @services.get(@script_name, :options => @options, :services => @services) script.daemonize if @options[:daemonize] @argv.empty? ? script.run! : script.run!(*@argv) end |