2

I would like to set a one-shot service to active even though systemd marks it as failed. How can I archive this?

Background:

Two node cluster with DRBD. Back in the days the state of the DRBD was managed by a simple script like:

# active.sh
drbdadm primary all
mount /dev/drbd0

# inactive:
umount /dev/drbd0
drbdadm secondary all

Now I have converted this logic to a one-shot systemd unit. The problem is, that on the current primary node the start of this service fails because drbdadm returns an error code for the device already in primary state.

This is desired in normal operation but not this very first time. I would like to set the service to active since effectively it is. Systemd just doesn't know it (which is perfectly OK, I just need a way to tell him that it's running).

2 Answers 2

1

There are a zillion systemd options, so you may be able to find an "ignore error" one.

Otherwise, a simple way is to create a custom launcher script, similar to what you used to have (active.sh). Then, point systemd to the launcher script.

The launcher can field any errors and decide which [if any] it should propagate up to systemd via an exit code (i.e. the last line of the script should be exit 0)

In other words, the script just ignores the drbdadm error and proceeds with the mount.

For tidiness, the last command in the script (e.g. mount) could be exec mount ...

-2

I believe the directive you're looking for here is SuccessExitStatus. You would only have to find out what exit code drbdadm returns for an already primary drive and add it to the list.

3
  • I do not want this in normal operation.
    – tim
    May 17, 2016 at 17:39
  • So you want to be able to get systemd to consider a service as launched under a certain condition even if it wasn't launched by systemd in the first place, is that it? And you want it to behave differently when not under "normal" operation, could you clarify on that? Do you mean at boot time? While configuring the cluster? I could see you have two conflicting units doing essentially the same thing, with one being used for normal operation and the other for maintenance or something, but unless you find a way to make sysd set the drives in primary state in the first place, that won't work. May 23, 2016 at 17:41
  • 1
    Exactly. A service is running but not started by systemd. Now I want to put it under systemd control without stopping it first. This happens exactly once. As far as my research went, this is not possible.
    – tim
    May 25, 2016 at 11:44

You must log in to answer this question.

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