Sample Header Ad - 728x90

How to prevent SElinux from blocking custom systemd service at boot?

2 votes
2 answers
4058 views
SElinux is preventing a custom service of mine from getting picked up by systemd at boot. > MESSAGE=SELinux is preventing systemd from read access on the file custom.service #### before rebooting
[root@box opt]# systemctl daemon-reload
[root@box opt]# systemctl enable --now custom
[root@box opt]# systemctl status custom.service
● custom.service - foo
   Loaded: loaded (/opt/foo/bar/systemd/custom.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2022-10-07 12:18:27 EDT; 1min 28s ago
...
...
#### after reboot
[root@box opt]# systemctl status custom.service
Unit custom.service could not be found.
So I disabled selinux and rebooted but it didn’t seem to help anything. I then changed the selinux user, role, and type of the service file and tried a reboot again.
[root@box opt]# chcon -R -u unconfined_u -r object_r -t systemd_unit_file_t foo/bar/systemd/
Still nothing... Then I noticed that the symlink I placed in /etc/systemd/system was showing a ? for the secontext. The same thing happens if I cp the service file into the /etc/systemd/system directory too.
[root@box opt]# ls -Z /etc/systemd/system/custom.service
? /etc/systemd/system/custom.service
Anyone know what needs to be done here to fix this? **TLDR** - SElinux is preventing systemd from reading an enabled custom systemd unit even though selinux is disabled.
Asked by Cory W. (21 rep)
Oct 7, 2022, 05:27 PM
Last activity: Jul 28, 2025, 01:20 PM