Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Guideline and note on crafting out a minimal long running process via systemd config file (sweat and tears in the process)
Description=My systemd service
# allow cap of 4 attempts to start the process
# within 1 second, if not success, then give up
ExecStart=/always/use/the/absolute/path/command --something --another-flag
# we won't be able to fail the systemd process with this line
# as it is executed inside `bash -c`. But this will allow us to
# pipe, otherwise output of command will be shown in `StandardOutput` e.g. journal.
ExecStartPost=bash -c 'curl -s "" > /dev/null'
# better use ExecStopPost in order to cover both normal restart of process, and
# unexpected restart (process crashes). ExecStop= only gets executed when
# ExecStart= successfully starts only, otherwise it won't get executed.
# recommended to use this instead of Environment= or various others
# due to security. This one strikes balance in ease of use, and maintain
# security. If you `systemctl show <service>`, it will output all environment
# variables as defined inside systemd config file, but not for EnvironmentFile=.
# As well, we can set permission accordingly for our envrionment variable file.
# So only us can read. Note, these variables will be passed before process runs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment