From 7270023c92c025d9f3588e8c82b7c294c612690e Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Mon, 23 Nov 2020 00:45:50 +0900 Subject: [PATCH] Overwrite the `systemd` config to rotate the log files. --- .../files/etc/systemd/system/consul.service | 20 +++++++++++++++++++ cookbooks/consul/setup.rb | 14 +++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 cookbooks/consul/files/etc/systemd/system/consul.service 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