Skip to content

Instantly share code, notes, and snippets.

@syntaqx
Last active May 30, 2019 09:44
Show Gist options
  • Save syntaqx/0625ee4209319c383a5170565227936d to your computer and use it in GitHub Desktop.
Save syntaqx/0625ee4209319c383a5170565227936d to your computer and use it in GitHub Desktop.
Interfacing with systemd for a basic binary service.
[Unit]
Description=A dead simple REST API for Docker Swarm
Documentation=https://github.com/syntaqx/swarm-api
After=network.target
[Service]
Type=simple
Restart=always
RestartSec=5s
Environment=PORT=8080
ExecStartPre=/bin/bash -c "/bin/systemctl set-environment HOST=$(curl -sfL http://169.254.169.254/metadata/v1/interfaces/private/0/ipv4/address)"
ExecStart=/bin/swarm-api --host "$HOST"
[Install]
WantedBy=multi-user.target
curl -sfL https://install.goreleaser.com/github.com/syntaqx/swarm-api.sh | sh -s -- -b /bin
systemctl enable swarm-api.service
systemctl start swarm-api.service
# log messages
journalctl -u swarm-api.service
# status listing
systemctl -l status swarm-api
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment