diff --git a/cookbooks/consul/files/etc/systemd/system/consul.service b/cookbooks/consul/files/etc/systemd/system/consul.service new file mode 100644 index 0000000..ae0cb84 --- /dev/null +++ b/cookbooks/consul/files/etc/systemd/system/consul.service @@ -0,0 +1,20 @@ +[Unit] +Description="HashiCorp Consul - A service mesh solution" +Documentation=https://www.consul.io/ +Requires=network-online.target +After=network-online.target +ConditionFileNotEmpty=/etc/consul.d/consul.hcl + +[Service] +User=consul +Group=consul +ExecStartPre=/usr/bin/find /var/log/consul/ -type f -delete +ExecStart=/usr/bin/consul agent -config-dir=/etc/consul.d/ +ExecReload=/bin/kill --signal HUP $MAINPID +KillMode=process +KillSignal=SIGTERM +Restart=on-failure +LimitNOFILE=65536 + +[Install] +WantedBy=multi-user.target diff --git a/cookbooks/consul/setup.rb b/cookbooks/consul/setup.rb index 6749ba3..2edc097 100644 --- a/cookbooks/consul/setup.rb +++ b/cookbooks/consul/setup.rb @@ -15,6 +15,8 @@ template '/etc/consul.d/consul.hcl' do ) source "templates/etc/consul.d/#{SRC}" + + notifies :restart, 'service[consul]' end directory '/var/log/consul/' do @@ -23,12 +25,24 @@ directory '/var/log/consul/' do mode '0755' end +remote_file '/etc/systemd/system/consul.service' do + owner 'root' + group 'root' + mode '0644' + + notifies :restart, 'service[consul]' +end + remote_file '/etc/consul.d/service-consul.json' do owner 'consul' group 'consul' mode '644' end +service 'consul' do + action [:enable, :start] +end + # iptables settings here: %w( 8300/tcp 8301/tcp 8301/udp 8500/tcp ).each do |port| execute "ufw allow #{port}" do