Skip to content

Commit

Permalink
Merge pull request #145 from logankoester/systemd
Browse files Browse the repository at this point in the history
Adds systemd init style (support for arch platform)
  • Loading branch information
johnbellone committed Mar 14, 2015
2 parents 60e3072 + 081ce39 commit ffda5c3
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 5 deletions.
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

0 comments on commit ffda5c3

Please sign in to comment.