Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds systemd init style (support for arch platform) #145

Merged
merged 2 commits into from
Mar 14, 2015
Merged
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
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Installs and configures [Consul][1] client, server and UI.
- CentOS 5.10, 6.5, 7.0
- RHEL 5.10, 6.5, 7.0
- Ubuntu 10.04, 12.04, 14.04
- Arch Linux

## Attributes

Expand Down Expand Up @@ -135,19 +136,19 @@ Installs and configures [Consul][1] client, server and UI.
<tr>
<td><tt>['consul']['init_style']</tt></td>
<td>String</td>
<td>Service init mode for running consul as: init or runit</td>
<td>Service init mode for running consul as: init, runit or systemd</td>
<td><tt>init</tt></td>
</tr>
<tr>
<td><tt>['consul']['service_user']</tt></td>
<td>String</td>
<td>For runit service: run consul as this user (init uses 'root')</td>
<td>For runit/systemd service: run consul as this user (init uses 'root')</td>
<td><tt>consul</tt></td>
</tr>
<tr>
<td><tt>['consul']['service_group']</tt></td>
<td>String</td>
<td>For runit service: run consul as this group (init uses 'root')</td>
<td>For runit/systemd service: run consul as this group (init uses 'root')</td>
<td><tt>consul</tt></td>
</tr>
<tr>
Expand Down
4 changes: 2 additions & 2 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@
end

default['consul']['servers'] = []
default['consul']['init_style'] = 'init' # 'init', 'runit'
default['consul']['init_style'] = 'init' # 'init', 'runit', 'systemd'

case node['consul']['init_style']
when 'runit'
when 'runit' || 'systemd'
default['consul']['service_user'] = 'consul'
default['consul']['service_group'] = 'consul'
else
Expand Down
2 changes: 2 additions & 0 deletions metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
supports 'ubuntu', '= 12.04'
supports 'ubuntu', '= 14.04'

supports 'arch'

depends 'libarchive'
depends 'chef-provisioning'
depends 'golang', '~> 1.4'
Expand Down
13 changes: 13 additions & 0 deletions recipes/_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,17 @@
supports status: true, restart: true, reload: true
reload_command "'#{node['runit']['sv_bin']}' hup consul"
end
when 'systemd'
template '/etc/systemd/system/consul.service' do
source 'consul-systemd.erb'
mode 0755
notifies :restart, 'service[consul]', :immediately
end

service 'consul' do
supports status: true, restart: true, reload: true
action [:enable, :start]
subscribes :restart, "file[#{consul_config_filename}]"
subscribes :restart, "link[#{Chef::Consul.active_binary(node)}]"
end
end
17 changes: 17 additions & 0 deletions templates/default/consul-systemd.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[Unit]
Description=Consul Agent
Wants=basic.target
After=basic.target network.target

[Service]
User=<%= node['consul']['service_user'] %>
Group=<%= node['consul']['service_group'] %>
ExecStart=<%= Chef::Consul.active_binary(node) %> agent \
-config-dir <%= node['consul']['config_dir'] %>
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartSec=42s

[Install]
WantedBy=multi-user.target