3

I have successfully created and configured a systemd template for easily spawning instances of similar services.

the template looks like this:

[Unit]
Description=my awesome service %I
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/binary -c /path/to/config/%i.conf
ExecStop=/usr/bin/pkill --full %i
Restart=on-failure
User=root
Group=root
TimeoutSec=30

[Install]
WantedBy=multi-user.target

I enabled and started the instance with systemcl enable name@kkk, systemctl start name@kkk and did not create a /path/to/config/kkk.conf file, so the service fails:

~# systemctl status [email protected][email protected] - my awesome service  kkk
   Loaded: loaded (/etc/systemd/system/[email protected]; enabled; vendor preset: enabled)
   Active: inactive (dead) (Result: exit-code) since Wed 2017-10-04 15:20:09 CEST; 3min 27s ago
  Process: 30116 ExecStop=/usr/bin/pkill --full %i (code=exited, status=1/FAILURE)
  Process: 30113 ExecStart=/usr/local/bin/binary -c /path/to/config/kkk.conf (code=exited, status=1/FA
 Main PID: 30113 (code=exited, status=1/FAILURE)

Oct 04 15:20:08 host systemd[1]: [email protected]: Unit entered failed state.
Oct 04 15:20:08 host systemd[1]: [email protected]: Failed with result 'exit-code'.
Oct 04 15:20:09 host systemd[1]: [email protected]: Service hold-off time over, scheduling restart.
Oct 04 15:20:09 host systemd[1]: Stopped my awesome service for kkk.

If I run systemctl --failed, I get

0 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.

which is obviously not correct, because the service is failed. Am I doing something wrong or missing something here? TIA.

3
  • 1
    The service isn't actually in an inactive state. If you run, "systemctl --failed --all" as suggested, you should see it. Oct 4, 2017 at 13:53
  • you are right, of course. It's just confusing that in the output of the status command it says right there 'unit entered failed state' Oct 4, 2017 at 14:55
  • for what it's worth, I have fixed it by remove the Type=simple (which is the default anyway) and adding a RestartPreventExitStatus=1 directive. Now it fails Oct 4, 2017 at 14:57

2 Answers 2

2

This is a bug in systemd, where a service which fails all of its restarts gets listed as "inactive" rather than "failed". In my testing it occurs in 229 (default with Ubuntu Xenial), and is fixed in 238; maybe some changelog snooping will reveal which version fixed it.

The best workaround seems to be to remove Restart from your service file and manually handle restarting yourself.

0

The service is not in a failed state. As you can see here :

Active: inactive (dead) (Result: exit-code) since Wed 2017-10-04 15:20:09 CEST; 3min 27s ago

It is inactive (dead). If it was failed you would get something like this :

Active: failed (Result: exit-code)

To see both failed and inactive services you should use the command :

systemctl --failed --all

You must log in to answer this question.

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