Systemd unit script that should print a message to the terminal is not working

William Seligman asked:

I have a CentOS7 server running named-chroot. The problem is named and named-chroot are separate systemd services in CentOS7, and I have both a stable system and a short memory. Months go by between any need for BIND maintenance. When I have BIND work to do, I always forget to type

systemctl restart named-chroot

and instead type

systemctl restart named

If I get it wrong, there’s no warning that I’m starting the incorrect service.

I’d like to use systemd configurations to edit the named service to remind me that I’ve made a mistake. This is as far I’ve gotten to overriding the standard named service: I use

systemctl edit named

and put in the following:

Description=You want named-chroot

ExecStart=/bin/bash -c "/usr/bin/echo 'No, you want named-chroot'"
ExecReload=/bin/bash -c "/usr/bin/echo 'No, you want named-chroot'"
ExecStop=/bin/bash -c "/usr/bin/echo 'No, you want named-chroot'"

This is as far as I got. The results of the echo commands will be visible in journalctl and systemctl status. Of course, the ideal would be to have them print on the terminal, but I haven’t figured that out. This does not work:


nor variants thereof; I get error messages that tell me that /dev/tty is not available in bash!

Another problem: even with the above file, commands like these one can cause named-chroot to halt with no visible indicator or warning:

systemctl restart named
systemctl start named

I can’t figure out why the named daemon initiated by named-chroot should be affected by my revised named script, when I’ve overridden every named service option I could find.

If you’re a systemd expert, please help me make this work.

My answer:

Why don’t you just mask the service? This prevents it from starting or being used in any way.

# systemctl mask named
Created symlink /etc/systemd/system/named.service → /dev/null.

# systemctl start named
Failed to start named.service: Unit named.service is masked.

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.