Skip to content
This repository has been archived by the owner on Jul 29, 2018. It is now read-only.

Config + hook to restart docker on 'vagrant up' #51

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
# vi: set ft=ruby :

Vagrant.configure(2) do |config|

config.vm.box = "projectatomic/adb"

config.vm.network "private_network", type: "dhcp"

config.servicemanager.providers = 'docker'

end
34 changes: 34 additions & 0 deletions lib/vagrant-service-manager/action/restart_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module Vagrant
module ServiceManager
module Action
class RestartService
def initialize(app, env)
@app = app
@machine = env[:machine]
@ui = env[:ui]
@providers = @machine.config.servicemanager.providers.split(',').map(&:chomp)
end

def execute_command(command, provider)
@machine.communicate.execute(command) do |type, data|
if type == :stderr
@ui.error(data)
else
@ui.info("# Restarted #{provider} service.")
end
end
end

def call(env)
@providers.each do |provider|
command = "sudo systemctl restart #{provider}"
command = "sudo rm /etc/docker/ca.pem && " + command if provider == 'docker'
execute_command(command, provider)
end

@app.call(env)
end
end
end
end
end
7 changes: 0 additions & 7 deletions lib/vagrant-service-manager/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,6 @@ def execute_docker_info
# First, get the TLS Certificates, if needed
if !File.directory?(secrets_path) then

# Regenerate the certs and restart docker daemon in case of the new ADB box and for VirtualBox provider
if machine.provider_name == :virtualbox then
# `test` checks if the file exists, and then regenerates the certs and restart the docker daemon, else do nothing.
command2 = "test ! -f /opt/adb/cert-gen.sh || (sudo rm /etc/docker/ca.pem && sudo systemctl restart docker)"
machine.communicate.execute(command2)
end

# Get the private key
hprivate_key_path = machine.ssh_info[:private_key_path][0]

Expand Down
22 changes: 22 additions & 0 deletions lib/vagrant-service-manager/config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module Vagrant
module ServiceManager
class Config < Vagrant.plugin('2', :config)
attr_accessor :providers

def initialize
super
@providers = UNSET_VALUE
end

def finalize!
# enable docker as provider by default
@providers = 'docker' if @providers == UNSET_VALUE
end

def validate(machine)
errors = _detected_errors
{ "servicemanager" => errors }
end
end
end
end
11 changes: 11 additions & 0 deletions lib/vagrant-service-manager/plugin.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require_relative "action/restart_service"

module Vagrant
module ServiceManager
class Plugin < Vagrant.plugin('2')
Expand All @@ -8,6 +10,15 @@ class Plugin < Vagrant.plugin('2')
require_relative 'command'
Command
end

config 'servicemanager' do
require_relative 'config'
Config
end

action_hook(:servicemanager, :machine_action_up) do |hook|
hook.append(Action::RestartService)
end
end
end
end