0

I have two services for an application:

  1. healthcheck- which check the health of a system and attempts restart when the validation fails.
  2. rollback- when multiple restart attempts fails to pass the healthcheck, it does the rollback to the previous version.

the unit file looks like this for health check:

[Unit]
Description=greenboot Health Checks Runner
Before=boot-complete.target
OnFailureJobMode=fail

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/libexec/greenboot/greenboot health-check
Restart=no

[Install]
RequiredBy=boot-complete.target
WantedBy=multi-user.target

and rollback

[Unit]
Description=Greenboot rollback
DefaultDependencies=no
Before=multi-user.target ostree-finalize-staged.service greenboot.service
Wants=local-fs.target
After=local-fs.target
ConditionNeedsUpdate=|/etc
ConditionNeedsUpdate=|/var

[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/usr/libexec/greenboot/greenboot rollback
Restart=no

[Install]
WantedBy=multi-user.target

rollback has other set of trigger conditions including a grub variable, How can I ensure the the health-check service does not run when rollback run with exit code 0.

1 Answer 1

0

Try to make use of the OnFailure= in health check to activate rollback when it fails, and SuccessAction=reboot in rollback to automatically reboot the system after your "rollback" operation finishes successfully.

In both units, IMHO, RemainAfterExit=true is unwanted. (Well at least in rollback)

Only health check should contain an [Install] section because the other should only be activated on failures...


To properly answer the topic title, without regarding the use-case of the poster:

  1. You should make use of ConditionPathExists=!/some/path/filename, in service "A" to prevent it being run when that file exists.
  2. And create that file in the other service "B" in an ExecStartPost= directive, to prevent the first service "A" to start, when this service "B" exits successfully.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.