Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/etc/systemd/system/consul.service
[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
@adambonny

This comment has been minimized.

Copy link

commented Apr 23, 2016

should SIGTERM rather than SIGINT to prevent re-election issues.

@espencerz

This comment has been minimized.

Copy link

commented Jul 25, 2017

both SIGINT and SIGTERM result in an "ungraceful shutdown"
shouldn't it be ExecStop=/usr/local/sbin/consul leave ?

@manavid

This comment has been minimized.

Copy link

commented Dec 15, 2017

Per documentation here https://www.consul.io/docs/agent/basics.html#stopping-an-agent SIGINT will gracefully shutdown consul.

@alejojo

This comment has been minimized.

Copy link

commented May 31, 2018

Thanks for the script @yunano. ExecReload should be SIGHUP as per https://www.consul.io/intro/getting-started/services.html#updating-services

@dungdm93

This comment has been minimized.

Copy link

commented Jun 17, 2018

Should add Documentation=https://consul.io/docs/ to [Unit] session.

@smitjainsj

This comment has been minimized.

Copy link

commented Sep 10, 2018

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.