'systemd apparently not finding .service file
I've put together a foo.service file for our foo service that runs as a daemon. The service runs fine when I run systemctl start foo
(and stop
) but
systemtcl enable foo
results in Failed to issue method call: Invalid argument
. The unit file is placed in /etc/systemd/system/foo.service
, and has permissions 0755. Setting systemd to debug and running enable gives
Looking for unit files in (highest priority first):`
/etc/systemd/system
/run/systemd/system
/usr/local/lib/systemd/system
/usr/lib/systemd/system
Looking for SysV init scripts in:
/etc/rc.d/init.d
Looking for SysV rcN.d links in:
/etc/rd.c
Failed to issue method call: Invalid argument
Googling around, it seems like systemctl isn't finding the .service file. Is there any way to verify that? If so, how can I fix that? Any other ideas about what might be wrong? Is there more debugging I can enable? The debug info given doesn't really help me narrow down the problem.
foo.service looks like:
[Unit]
Description=Blah Blah Blah
[Service]
ExecStart=/usr/bar/doof/foo
Type=simple
PIDFile=/var/run/foo.pid
[Install]
WantedBy=multi-user.target,graphical.target
EDIT: Yes, I did run systemctl daemon-reload
.
Solution 1:[1]
For people from Google:
- Validate with
sudo systemd-analyze verify NAME.service
- When using a symlink, make sure it uses absolute path
- Make sure the name is like
/etc/systemd/system/*.service
- Do
sudo systemctl daemon-reload
after changes
Solution 2:[2]
The issue in my case was the file was symlinked from another partition and systemd do not support that.
Unit files have to reside on a partition that is mounted at the moment the host PID 1 is invoked. i.e. either on the root partition or some other partition that the initrd premounts.
I'm answering to an old question because this is a top result while googling on the issue and might help someone
Solution 3:[3]
Error is because of two target are specified to WantedBy
. Just mention in this way:
[Install]
WantedBy=multi-user.target
I really don't know how we can specify two targets to it.
Solution 4:[4]
I found this question over google, searching for "systemctl unit not found"
In my case I generated a *.service file via podman and no matter what I did, systemctl wouldn't find the service file.
Solution was to check selinux and set the correct labels. Example:
/sbin/restorecon -v /etc/systemd/system/container_httpd.service
Solution 5:[5]
I ran into this error when using Podman to generate systemd unit files.
The error occurred because selinux was blocking the file from being properly read. I found there were two solutions.
Set your directory to the systemd service location for unit files with
cd /etc/systemd/system
. Then usepodman generate
to create the file directly here. This seems to be accepted by selinux without issue.Generate the systemd unit file with
podman generate
and copy the file to/etc/systemd/system
. You then need to run/sbin/restorecon -v /etc/systemd/system/container-<your container name>.service
to have selinux reset its security context for that file.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Mark |
Solution 2 | vinzee |
Solution 3 | slm |
Solution 4 | N02291 |
Solution 5 |