Skip to content

Commit

Permalink
multi service support for docker_service_manager_upstart
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean OMeara committed Dec 4, 2015
1 parent 7042fec commit 0909ad3
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 7 deletions.
7 changes: 7 additions & 0 deletions .kitchen.cloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,13 @@ suites:
run_list:
- recipe[docker_test::service_upstart]

- name: service-upstart-multi
includes: [
'ubuntu-14.04'
]
run_list:
- recipe[docker_test::service_upstart_multi]

#################################
# docker_service_systemd resource
#################################
Expand Down
12 changes: 6 additions & 6 deletions libraries/docker_service_manager_upstart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,36 @@ class DockerServiceManagerUpstart < DockerServiceBase
provides :docker_service_manager, platform: 'ubuntu'

action :start do
template '/etc/init/docker.conf' do
path '/etc/init/docker.conf'
template "/etc/init/#{docker_name}.conf" do
source 'upstart/docker.conf.erb'
owner 'root'
group 'root'
mode '0644'
variables(
config: new_resource,
docker_name: docker_name,
docker_cmd: docker_cmd,
docker_daemon_cmd: docker_daemon_cmd
)
cookbook 'docker'
notifies :restart, new_resource unless ::File.exist? '/etc/docker-firstconverge'
notifies :restart, new_resource unless ::File.exist? "/etc/#{docker_name}-firstconverge"
notifies :restart, new_resource if auto_restart
action :create
end

file '/etc/docker-firstconverge' do
file "/etc/#{docker_name}-firstconverge" do
action :create
end

service 'docker' do
service docker_name do
provider Chef::Provider::Service::Upstart
supports status: true
action :start
end
end

action :stop do
service 'docker' do
service docker_name do
provider Chef::Provider::Service::Upstart
supports status: true
action :stop
Expand Down
2 changes: 1 addition & 1 deletion templates/default/upstart/docker.conf.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
description "Docker daemon"
description "<%= @docker_name %> daemon"

start on (filesystem and net-device-up IFACE!=lo)
stop on runlevel [!2345]
Expand Down
63 changes: 63 additions & 0 deletions test/cookbooks/docker_test/recipes/service_upstart_multi.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# installation
docker_installation_binary 'default' do
action :create
end

# service named 'default'
docker_service_manager_upstart 'default' do
graph '/var/lib/docker'
host 'unix:///var/run/docker.sock'
action :start
end

docker_image 'busybox' do
host 'unix:///var/run/docker.sock'
end

docker_container 'service default echo server' do
container_name 'an_echo_server'
repo 'busybox'
command 'nc -ll -p 7 -e /bin/cat'
port '7:7'
action :run
end

# service A
docker_service_manager_upstart 'one' do
graph '/var/lib/docker-one'
host 'unix:///var/run/docker-one.sock'
action :start
end

docker_image 'hello-world' do
host 'unix:///var/run/docker-one.sock'
tag 'latest'
end

docker_container 'hello-world' do
host 'unix:///var/run/docker-one.sock'
command '/hello'
action :create
end

# service B
docker_service_manager_upstart 'two' do
graph '/var/lib/docker-two'
host 'unix:///var/run/docker-two.sock'
action :start
end

docker_image 'alpine' do
host 'unix:///var/run/docker-two.sock'
tag '3.1'
end

docker_container 'service two echo_server' do
container_name 'an_echo_server'
repo 'alpine'
tag '3.1'
command 'nc -ll -p 7 -e /bin/cat'
port '7:7'
host 'unix:///var/run/docker-two.sock'
action :run
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# # a service named default
describe command('docker images') do
its(:exit_status) { should eq 0 }
its(:stdout) { should match(/busybox/) }
end

describe command('docker ps -a') do
its(:exit_status) { should eq 0 }
its(:stdout) { should match(/an_echo_server/) }
end

# service A
describe command('docker --host=unix:///var/run/docker-one.sock images') do
its(:exit_status) { should eq 0 }
its(:stdout) { should match(/^hello-world/) }
its(:stdout) { should_not match(/^alpine/) }
end

describe command('docker --host=unix:///var/run/docker-one.sock ps -a') do
its(:exit_status) { should eq 0 }
its(:stdout) { should match(/hello-world/) }
its(:stdout) { should_not match(/an_echo_server/) }
end

# service B
describe command('docker --host=unix:///var/run/docker-two.sock images') do
its(:exit_status) { should eq 0 }
its(:stdout) { should_not match(/^hello-world/) }
its(:stdout) { should match(/^alpine/) }
end

describe command('docker --host=unix:///var/run/docker-two.sock ps -a') do
its(:exit_status) { should eq 0 }
its(:stdout) { should_not match(/hello-world/) }
its(:stdout) { should match(/an_echo_server/) }
end

0 comments on commit 0909ad3

Please sign in to comment.