-
-
Save yunano/c27eb679a29ab70178ca to your computer and use it in GitHub Desktop.
[Unit] | |
Description=consul agent | |
Requires=network-online.target | |
After=network-online.target | |
[Service] | |
EnvironmentFile=-/etc/sysconfig/consul | |
Environment=GOMAXPROCS=2 | |
Restart=on-failure | |
ExecStart=/usr/local/sbin/consul agent $OPTIONS -config-dir=/etc/consul.d | |
ExecReload=/bin/kill -HUP $MAINPID | |
KillSignal=SIGINT | |
[Install] | |
WantedBy=multi-user.target |
both SIGINT and SIGTERM result in an "ungraceful shutdown"
shouldn't it be ExecStop=/usr/local/sbin/consul leave ?
Per documentation here https://www.consul.io/docs/agent/basics.html#stopping-an-agent SIGINT
will gracefully shutdown consul.
Thanks for the script @yunano. ExecReload should be SIGHUP
as per https://www.consul.io/intro/getting-started/services.html#updating-services
Should add Documentation=https://consul.io/docs/
to [Unit]
session.
For running consul in SERVER mode as non root user , I use the below snippet and it seems to work for me.
[Unit]
Description=consul agent
Requires=network-online.target
After=network-online.target
[Service]
Type=simple
User=consul
Group=consul
LimitNOFILE=1024
PermissionsStartOnly=true
Environment="OPTIONS=-server -ui -advertise" # This can also set to agent mode and passed via EnvironmentFile as well.
ExecStartPre=/usr/bin/bash -c "/usr/bin/systemctl set-environment HOSTNAME_IP=$(hostname -i)"
ExecStart=/usr/local/bin/consul agent $OPTIONS $HOSTNAME_IP -config-dir /etc/consul.d
ExecReload=/bin/kill -HUP $MAINPID
KillSignal=SIGINT
[Install]
WantedBy=multi-user.target
Just as a reference, as I've also come across this topic, this comes from the official package installation (of course it needs to be adapted, according to the needs, but it should help anyway):
[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]
EnvironmentFile=/etc/consul.d/consul.env
User=consul
Group=consul
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
I see you configured $OPTIONS as a cli argument. How do you actually configure that in the environmental file? I see there's a json structure that consul might expect, but this has nothing to do with it, I gather?
should SIGTERM rather than SIGINT to prevent re-election issues.