1

I want to delay the start of a service if a exist (instead of fail the service if the file exist, as with ConditionPathExists=) but did not find anything in unit documentation

Is it technically possible with systemd ? How ?

3

using just one unit

Put TimeoutStartSec=infinity in the unit file and configure ExecStart= with a script like

#! /bin/bash

TIMEOUT=1000

test -f /path/to/testfile && sleep "$TIMEOUT"

exec /path/to/service/binary plus arguments

This cannot be done (in a useful way) with ExecStartPre=, see man systemd.service:

Note that ExecStartPre= may not be used to start long-running processes. All processes forked off by processes invoked via ExecStartPre= will be killed before the next service process is run.

using a helper unit

If you want to do this with systemd "alone" then you can create a helper unit check_and_wait. This one gets the entries

TimeoutStartSec=infinity
ConditionPathExists=/path/to/testfile
ExecStart=/usr/bin/sleep 1000
RemainAfterExit=yes

The main unit gets these entries:

Wants=check_and_wait
After=check_and_wait
  • 1
    Surely it can use ExecStartPre, just move binary into ExecStart. What goes wrong? – sourcejedi Aug 26 '17 at 13:47
  • Does this mean it is not possible with systemd and necessarily require a shell script (bash or other) ? – Zulgrib Aug 26 '17 at 14:45
  • @Zulgrib As usual there are several possibilities. I have added another to my answer. – Hauke Laging Aug 26 '17 at 15:22
  • You can use ExecStartPre (since it's not sleeping forever) ... methinks... – rogerdpack Jul 9 at 17:26

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.