2

I have a service file with an ExecCondition that, when exits with status=1/FAILURE, doesn't prevent the start of the daemon.

Which I believe, based on the documentation, should prevent the daemon from starting as well as prevent all other ExecStartPre commands from running.

when an ExecCondition= command exits with exit code 1 through 254 (inclusive), the remaining commands are skipped and the unit is not marked as failed.

systemd.service documentation

I put in a condition that should fail every time in an obvious way. ExecCondition=-sh -c 'exit(1)'

Here's the service file (with names changed to protect the innocent).

[Unit]
Description=Application
Wants=x-ray.service yankee.service zulu.service
Requires=alpha.service bravo.service
After=x-ray.service charlie.service bravo.service

[Service]
ExecCondition=-sh -c 'exit(1)'
ExecStartPre=-sh -c 'prestartShellScript.sh'
ExecStart=/opt/app/app argument1 argument2
WatchdogSec=10
Restart=always
RestartSec=10
WorkingDirectory=/opt/app
TimeoutSec=10

[Install]
WantedBy=multi-user.target

But when I start the service, using systemctl status app I see this showing the app is running and the other processes also ran:

     Active: active (running) since Fri 2020-02-07 18:06:57 UTC; 6s ago
    Process: 33783 ExecCondition=/bin/sh -c exit(1) (code=exited, status=1/FAILURE)
    Process: 33796 ExecStartPre=/bin/sh -c prestartShellScript.sh (code=exited, status=0/SUCCESS)
   Main PID: 33827 (app)
      Tasks: 19 (limit: 4177)
     Memory: 101.5M
     CGroup: /system.slice/app.service
             └─33827 /opt/app/app argument1 argument2

I've also changed my ExecCondition to ExecStartPre but I see the same behavior.

1
  • It looks like you have an answer already, but just for future questions, one thing that might help people be more inclined to answer is to add the exact version and type of OS. This looks like it might be Centos or Red Hat versions 7 or 8 .. ? Jul 24, 2021 at 22:18

1 Answer 1

5

Your command is prefixed with -, which is a general flag accepted in all Exec*= parameters and specifically means "ignore exit code and treat the command as always successful". Don't use the - if you actually want systemd to fail the unit when the command reports failure.

0

You must log in to answer this question.

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