Skip to content

Instantly share code, notes, and snippets.

@r7vme
Last active June 16, 2017 07:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save r7vme/ee0ca68023e912aba3f8502efd5a14d3 to your computer and use it in GitHub Desktop.
Save r7vme/ee0ca68023e912aba3f8502efd5a14d3 to your computer and use it in GitHub Desktop.
systemd unit for haproxy running in docker container
[Unit]
Description=Haproxy container
After=docker.service
Requires=docker.service
ConditionFileNotEmpty=/etc/haproxy/haproxy.cfg
[Service]
TimeoutStartSec=0
Restart=always
Environment=CONFIG_DIR=/etc/haproxy
ExecStartPre=-/usr/bin/docker stop %n
ExecStartPre=-/usr/bin/docker rm %n
ExecStartPre=/usr/bin/docker pull haproxy
ExecStart=/usr/bin/docker run \
--rm \
--name %n \
--net=host \
-v ${CONFIG_DIR}:${CONFIG_DIR} \
haproxy \
haproxy -f ${CONFIG_DIR}/haproxy.cfg
[Install]
WantedBy=multi-user.target
# To reload config use "docker kill -s HUP haproxy.service"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment