Why does systemd reject my unit name as 'neither a valid invocation ID nor unit name'?

Solution 1:

This is caused by a systemd bug introduced in v233 and fixed in v240. It is not necessary to upgrade systemd, in most cases systemctl edit is little more than a shortcut for the following anyway:

sudo mkdir -p /etc/systemd/system/[email protected]/
sudo vim /etc/systemd/system/[email protected]/override.conf

The override files will work, even in systemd versions where the systemctl edit command does not. Do not forget to apply new configuration using:

sudo systemctl daemon-reload

Solution 2:

I received the same error message about 'neither a valid invocation ID nor unit name' when starting a service failed, but the fix was different than the accepted answer and unrelated to the bug. The error message was a total red-herring and a time waster as I explain below.

My issue was with systemd netfilter-persistent service. The error message lead me to believe there was a problem with the systemd-gears starting the service. Then I had an epiphany: What if there was a duff iptables rule in "rules.v4" the service called?

Yup: the service wasn't starting because of a dependent file required to raise it, in this case "rules.v4" had an error. This didn't appear in the systemctl status or journalctl -xe. A sed expression failed to match and replace a placeholder with a subnet. Once I the rules file built correctly, the service rose-up correctly.

When investigating this error message, don't get so blinkered looking at the systemd service definition itself that you don't review any dependent files being called that might be in error error.

Anyhoo, hope this saves others from chasing their tail with this error message.