Consul server stop - the best way?

Hi There,

I have managed to get a bit confused as to the best thing to do within a service file as ExecStop= for a consul server service…

I have read the documents though it feels like they conflict somewhat due to my limited understanding…


When a Server is gracefully exited, the server will not be marked as left. This is to minimally impact the consensus quorum. Instead, the Server will be marked as failed.
For nodes in server mode, the node is removed from the Raft peer set in a graceful manner. This is critical, as in certain situations a non-graceful leave can affect cluster availability.

from the above the first document makes me think that the server should fail to keep the cluster size… But then the second document makes me think that the ‘leave’ command should be used for a graceful leave??

Can someone please let me know the best practice… .currently I have;

[Unit]
Description=Consul Agent
After=syslog.target network.target

[Service]
Type=simple
User=consul
Group=consul
PermissionsStartOnly=true
ExecStartPre=/bin/sleep 2
ExecStartPre=/bin/chown -R consul:consul /opt/consul
ExecStart=/usr/bin/consul agent -config-file=/etc/consul.d/consul.json -config-dir=/home/consul/
ExecStop=/usr/bin/consul leave

TimeoutStopSec=30
Restart=always

[Install]
WantedBy=multi-user.target