Skip to content

Commit

Permalink
Create private inner class for starting and stopping the docker daemon
Browse files Browse the repository at this point in the history
This allows us to not polute the interface of EmbeddedAnsible classes
or objects with docker specific methods and also to share the methods
between the DockerEmbeddedAnsible class and instance methods
  • Loading branch information
carbonin committed Dec 4, 2017
1 parent 0e3e2e0 commit 74396f2
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions lib/embedded_ansible/docker_embedded_ansible.rb
@@ -1,12 +1,29 @@
class DockerEmbeddedAnsible < EmbeddedAnsible
AWX_WEB_PORT = "54321".freeze

class DockerDaemon
def initialize
require 'linux_admin'
end

def start
return unless Rails.env.production?
LinuxAdmin::Service.new("docker").start.enable
end

def stop
return unless Rails.env.production?
LinuxAdmin::Service.new("docker").stop.disable
end
end

private_constant :DockerDaemon

def self.available?
require 'docker'
start_docker_daemon
status = Docker.validate_version!
stop_docker_daemon
status

DockerDaemon.new.start
Docker.validate_version!
rescue
false
end
Expand All @@ -21,7 +38,7 @@ def initialize
end

def start
self.class.start_docker_daemon
DockerDaemon.new.start
run_rabbitmq_container
run_memcached_container
sleep(15)
Expand All @@ -40,7 +57,7 @@ def start

def stop
container_names.each { |c| stop_container(c) }
self.class.stop_docker_daemon
DockerDaemon.new.stop
end

alias disable stop
Expand All @@ -63,18 +80,6 @@ def alive?
false
end

private_class_method def self.start_docker_daemon
return unless Rails.env.production?
require 'linux_admin'
LinuxAdmin::Service.new("docker").start.enable
end

private_class_method def self.stop_docker_daemon
return unless Rails.env.production?
require 'linux_admin'
LinuxAdmin::Service.new("docker").stop.disable
end

private

def run_rabbitmq_container
Expand Down

0 comments on commit 74396f2

Please sign in to comment.