Class: RubyYacht::Runner::Services
- Defined in:
- lib/ruby_yacht/runner/services.rb
Overview
This class provides a command for starting, stopping, and restarting containers.
Instance Attribute Summary collapse
-
#command ⇒ Object
The name of the docker command that we are running.
Class Method Summary collapse
-
.command ⇒ Object
The name of the command.
-
.description ⇒ Object
The description for the command.
Instance Method Summary collapse
-
#option_parser ⇒ Object
This method gets the command-line flags for this command.
-
#parse_positional_arguments(arguments) ⇒ Object
This method extracts the arguments from the command line.
-
#run ⇒ Object
This method runs the logic for the command.
-
#start_docker_machine ⇒ Object
This method starts the default docker machine.
Methods inherited from Command
#backtick, #default_project, #docker, #docker_machine, #get_machine_info, #log, #project_named, #projects, short_script_name, #system
Instance Attribute Details
#command ⇒ Object
The name of the docker command that we are running.
This can be start
, stop
, or restart
.
24 25 26 |
# File 'lib/ruby_yacht/runner/services.rb', line 24 def command @command end |
Class Method Details
.command ⇒ Object
The name of the command.
6 |
# File 'lib/ruby_yacht/runner/services.rb', line 6 def self.command; 'services'; end |
.description ⇒ Object
The description for the command.
9 |
# File 'lib/ruby_yacht/runner/services.rb', line 9 def self.description; 'Start, stop, or restart containers'; end |
Instance Method Details
#option_parser ⇒ Object
This method gets the command-line flags for this command.
12 13 14 15 16 17 18 19 |
# File 'lib/ruby_yacht/runner/services.rb', line 12 def option_parser OptionParser.new do || usage = "Usage: #{Command.short_script_name} #{self.class.command} [COMMAND]" usage += "\n\n#{self.class.description}" usage += "\n\n[COMMAND] is required, and can be start, stop, or restart" . = usage end end |
#parse_positional_arguments(arguments) ⇒ Object
This method extracts the arguments from the command line.
Parameters
- arguments: Array The command-line arguments.
31 32 33 |
# File 'lib/ruby_yacht/runner/services.rb', line 31 def parse_positional_arguments(arguments) self.command = arguments.shift end |
#run ⇒ Object
This method runs the logic for the command.
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 |
# File 'lib/ruby_yacht/runner/services.rb', line 36 def run if self.command == nil log "You must provide a command" log "Run #{Command.short_script_name} help services for more information" return false end unless %w(start stop restart).include?(command) log "#{command} is not a valid docker command" log "Run #{Command.short_script_name} help services for more information" return false end if command == 'start' start_docker_machine end projects.each do |project| project.databases.select(&:local?).each do |database| docker "#{command} #{database.container_name}" end project.apps.each do |app| docker "#{command} #{app.container_name}" end project.web_servers.each do |server| docker "#{command} #{server.container_name}" end end true end |
#start_docker_machine ⇒ Object
This method starts the default docker machine.
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/ruby_yacht/runner/services.rb', line 71 def start_docker_machine if docker_machine != '' system "#{docker_machine} start default" environment_args = backtick("#{docker_machine} env default").split("\n") environment_args.each do |arg| if arg =~ /export (\w*)=\"(.*)\"/ ENV[$1] = $2 end end end end |