4

I created a test service under /etc/systemd/system which is the correct path to create custom unit files.

[root@apollo system]# cat sample.service
[Unit]
Description=This is my test service
Wants=chronyd.service
After=chronyd.service

[Service]
Type=forking
ExecStart=/root/sample.sh

[Install]
WantedBy=multiuser.target chronyd.service
#RequiredBy=multiuser.target chronyd.service
#Alias=xyz
[root@apollo system]# pwd
/etc/systemd/system
[root@apollo system]#

I made sure systemd is aware by running "systemctl daemon-reload". I was also able to stop/start the service.

When I tried to mask it, it shows me this error:

[root@apollo system]# systemctl mask sample.service
Failed to execute operation: File exists
[root@apollo system]#

That is because systemd is trying to create a symlink using this command:

ln -s /dev/null /etc/systemd/system/sample.service

Since sample.service already exists inside /etc/systemd/system, the command will fail unless systemd will use "ln -fs".

So meaning we cannot mask any unit files we create under /etc/systemd/system?

I tried to move sample.service to /usr/lib/systemd/system and I was able to mask it because it was able to create a symlink under /etc/systemd/system without any hindrance.

Has anybody experience this? Do you think this is a bug?

  • BTW, I am using RHEL 7.2 – mit13 Mar 15 '17 at 18:29
3

There is not a way to mask services which have service files in /etc/systemd/system without first removing the file from there. This is intentional design.

You can disable the service by using systemctl disable servicename.service which will have the same effect as masking it in many cases.

The post by the author of systemd Three Levels of Off has more detail on the differences between stop, disable and mask in systemd.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.