class RubyYacht::Runner::Services
This class provides a command for starting, stopping, and restarting containers.
Attributes
command[RW]
The name of the docker command that we are running.
This can be ‘start`, `stop`, or `restart`.
Public Class Methods
command()
click to toggle source
The name of the command.
# File lib/ruby_yacht/runner/services.rb, line 6 def self.command; 'services'; end
description()
click to toggle source
The description for the command.
# File lib/ruby_yacht/runner/services.rb, line 9 def self.description; 'Start, stop, or restart containers'; end
Public Instance Methods
option_parser()
click to toggle source
This method gets the command-line flags for this command.
# File lib/ruby_yacht/runner/services.rb, line 12 def option_parser OptionParser.new do |options| 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" options.banner = usage end end
parse_positional_arguments(arguments)
click to toggle source
This method extracts the arguments from the command line.
### Parameters
-
**arguments: Array** The command-line arguments.
# File lib/ruby_yacht/runner/services.rb, line 31 def parse_positional_arguments(arguments) self.command = arguments.shift end
run()
click to toggle source
This method runs the logic for the command.
# 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()
click to toggle source
This method starts the default docker machine.
# 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