I have a systemd service (for heka) which causes me some headaches.

The problem is that "start" returns successfully even if the heka daemon dies shortly after starting. This is happening if the configuration files are wrong, for example: the process will start, it will verify the configuration and die if it's not happy about what it finds. Systemd returns successfully in this case.

Is there any way to force systemd to check the program status after it is initializing? Maybe to sleep n seconds after the process has started?

This is the script:

    Description=Heka event/metric/log collection and routing daemon
    After=network.target auditd.service

    ExecStart=/usr/bin/hekad -config=/etc/heka
    ExecReload=/bin/kill -HUP $MAINPID


3 Answers 3


You can chain multiple ExecPostStart commands together. And you can run them even if the main ExecStart failed by adding a -/ (systemd.service: Type=). Something like this:

ExecStart=-/usr/bin/hekad -config=/etc/heka
ExecStartPost=/bin/sleep 3
ExecStartPost=/bin/kill -0 $MAINPID &>/dev/null

This ensures that you still have the MAINPID to use when stopping or restarting the service for instance.

  • Instead of "kill -0" I used /bin/bash -c "[ ! -z $MAINPID ]"
    – cristi
    Feb 23, 2016 at 10:38

If there is an easy way to check whether hekad is still alive then I would start the daemon using ExecStartPre=/usr/bin/hekad -config=/etc/heka and with ExecStart run a small script that has a loop that first sleeps X seconds, then checks if the hekad daemon is still running. Breaking the loop only if the hekad seems to have stopped.

  • I want to control start status even when the daemon is stopped.
    – cristi
    Feb 15, 2016 at 12:42
  • Sorry,I didn't read your answer correctly the first time. But what happens when you want to stop with your script? Systemd will send the kill signals to the process from ExecStart.
    – cristi
    Feb 15, 2016 at 12:50
  • @Cristi the script would have to trap the SIGTERM and kill the real process in function that handles the trap.
    – Anthon
    Feb 15, 2016 at 15:49

You should use ExecStartPost to launch a command or script that sleeps and then runs a check. If this exits non-zero, the unit is considered a failure.

See: https://www.freedesktop.org/software/systemd/man/systemd.service.html

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .