I'm having trouble using ExecStartPost in a systemd service. Even with the following simple command:

ExecStartPost=/bin/sh -c "exit 0"

... when I start the service, I get a "time out" error:

start-post operation timed out. Stopping.

Here is my full service definition. mbtileserver is a blocking program, not a daemon.

Description=mbtileserver daemon

ExecStart=/home/crp/go/bin/mbtileserver -d /home/crp/tiles/ -p 8080 -s "eGJ0NwI9_OyxHEFvBcU-9zR6O89z_S0RNfIOSP3utSU"
ExecStartPost=/bin/sh -c "exit 0"
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID


How do I create an ExecStartPost that doesn't time out?


I eventually discovered that the problem was that PIDFile didn't exist. This doesn't appear to be documented, but you need a valid PIDFile in order to use ExecStartPost (possibly no PIDFile would work, but an missing file definitely doesn't work).

Ironically, I was going to use ExecStartPost to create the pid file, but wanted to try it with something simple (originally had an echo) first.

Changing ExecStartPost to the following made the service work:

ExecStartPost=/bin/sh -c "pgrep -o mbtileserver > /home/crp/var/run/mbtileserver.pid"
  • 2
    Your program is supposed to create the PID file, not systemd. If your program doesn't create a PID file, then do not use the directive at all in your systemd unit. – Michael Hampton Jun 20 at 18:22
  • I had known that, but it hadn't caused a problem until I added ExecStartPost, which is what tripped me up. – Nikolas Stevenson-Molnar Jun 20 at 18:23
  • 2
    Well, congrats, you found some undocumented behavior in systemd. It's probably worth a bug report, if only so the documentation can be fixed. – Michael Hampton Jun 20 at 18:26
  • Good idea! I'll file a bug report. – Nikolas Stevenson-Molnar Jun 20 at 18:31
  • 1
    Here's a bit more background on PIDFile= that you might find useful. – Michael Hampton Jun 20 at 18:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.