From 8fce2447a4ad689835fc34b693bc80a059bac40b Mon Sep 17 00:00:00 2001 From: Logan Koester Date: Sat, 14 Mar 2015 07:38:59 -0400 Subject: [PATCH 1/2] Adds systemd init style --- README.md | 6 +++--- attributes/default.rb | 4 ++-- recipes/_service.rb | 13 +++++++++++++ templates/default/consul-systemd.erb | 17 +++++++++++++++++ 4 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 templates/default/consul-systemd.erb diff --git a/README.md b/README.md index a88822ff..3e5328a7 100644 --- a/README.md +++ b/README.md @@ -135,19 +135,19 @@ Installs and configures [Consul][1] client, server and UI. ['consul']['init_style'] String - Service init mode for running consul as: init or runit + Service init mode for running consul as: init, runit or systemd init ['consul']['service_user'] String - For runit service: run consul as this user (init uses 'root') + For runit/systemd service: run consul as this user (init uses 'root') consul ['consul']['service_group'] String - For runit service: run consul as this group (init uses 'root') + For runit/systemd service: run consul as this group (init uses 'root') consul diff --git a/attributes/default.rb b/attributes/default.rb index ab0e116a..89bedd57 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -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 diff --git a/recipes/_service.rb b/recipes/_service.rb index ce27353e..19969f05 100644 --- a/recipes/_service.rb +++ b/recipes/_service.rb @@ -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 diff --git a/templates/default/consul-systemd.erb b/templates/default/consul-systemd.erb new file mode 100644 index 00000000..a591784a --- /dev/null +++ b/templates/default/consul-systemd.erb @@ -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 From 081ce39fde8937fd3b34ba938c6c16588b898c75 Mon Sep 17 00:00:00 2001 From: Logan Koester Date: Sat, 14 Mar 2015 07:40:32 -0400 Subject: [PATCH 2/2] Note that this cookbook now works on Arch Linux --- README.md | 1 + metadata.rb | 2 ++ 2 files changed, 3 insertions(+) diff --git a/README.md b/README.md index 3e5328a7..dc3029db 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/metadata.rb b/metadata.rb index bb22475f..fdcd4a7a 100644 --- a/metadata.rb +++ b/metadata.rb @@ -21,6 +21,8 @@ supports 'ubuntu', '= 12.04' supports 'ubuntu', '= 14.04' +supports 'arch' + depends 'libarchive' depends 'chef-provisioning' depends 'golang', '~> 1.4'