-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcontainer.rb
More file actions
49 lines (43 loc) · 1.31 KB
/
container.rb
File metadata and controls
49 lines (43 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
define :container, :c_type => nil, :c_num => nil, :env => {}, :command => '', :port => nil, :image => nil, :slug_dir => nil, :enable => nil, :user => "root" do
# pull out local variables
c_type = params[:c_type]
c_num = params[:c_num]
env = params[:env]
command = params[:command]
port = params[:port]
image = params[:image]
slug_dir = params[:slug_dir]
user = params[:user]
# see if service should be enabled or disabled
if params[:enable] == true
actions = [:start, :enable]
on_change = :restart
else
actions = [:stop, :disable]
on_change = :nothing
end
# create upstart service definition
template "/etc/init/#{c_type}.#{c_num}.conf" do
source "container.conf.erb"
mode 0644
variables({
:log_dir => "/var/log",
:user => user,
:image => image,
:slug_dir => slug_dir,
:env => env,
:port => port,
:command => command,
:c_type => c_type,
:c_num => c_num
})
# stop the service to force job definition reload
notifies :stop, "service[#{c_type}.#{c_num}]", :immediately
notifies on_change, "service[#{c_type}.#{c_num}]", :delayed
end
# define an upstart daemon as enabled or disabled
service "#{c_type}.#{c_num}" do
provider Chef::Provider::Service::Upstart
action actions
end
end