[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [SOLVED] Systemd: how to add a service to rescue.target



On 19/09/25 at 19:44, Greg Wooledge wrote:
On Fri, Sep 19, 2025 at 16:51:32 +0000, stefano prina wrote:
    Hello,
    So he have to :
    1. edit the Daemon unit file
    2. systemctl daemon-reload
    3. run systemctl enable <service>  again
    Am I right?

Don't edit the unit file.  Create a drop-in override file instead.

The "systemctl edit" command will start that process for you.  Or, if
you like, you can manually create the appropriately named subdirectory
under /etc/systemd/system/ and create a *.conf file inside it.
Either way, the file should contain only the lines you need, which are
just:

[Install]
WantedBy=rescue.target

I edited the gpm.service using "systemctl edit" it generates the file:

~# cat /etc/systemd/system/gpm.service.d/override.conf
[Install]
WantedBy=multi-user.target rescue.target

according to manual page systemd.unit(5) I added the rescue.target separated by a space:

WantedBy=, RequiredBy=, UpheldBy=
This option may be used more than once, or a space-separated list of unit names may be given. A symbolic link is created in the .wants/, .requires/, or .upholds/ directory of each of the listed units when this unit is installed by systemctl enable. This has the effect of a dependency of type Wants=, Requires=, or Upholds= being added from the listed unit to the current unit. See the description of the mentioned dependency types in the [Unit] section for details.
<Omitted>


According to the man page (systemctl(1)), after doing an "edit", the
configuration is automatically reloaded, so step 2 shouldn't be
necessary, but it certainly won't hurt.

Yes, I didn't perform any daemon-reload.


I don't think step 3 is needed, or even desired.  Maybe I'm wrong?

Yes it's needed, running "systemctl enable" it gives:

~# systemctl enable gpm.service
Synchronizing state of gpm.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable gpm
Created symlink '/etc/systemd/system/rescue.target.wants/gpm.service' → '/usr/lib/systemd/system/gpm.service'.

Notice that it creates the symlink for the rescue.target

I'm not inclined to test this right now, since it entails rebooting
and is therefore highly disruptive.

Now I don't reboot anymore, I use "systemctl isolate" instead to switch between rescue.target and graphical.target . From the desktop (KDE) I switch to virtual console by pressing Ctrl-Alt-F3 then I login as root and I type:

~# systemctl isolate rescue.target

to test the mouse and now it works! Of course when you switch to rescue.target all you have in the desktop it's shutdown, so be careful when you do it.

Thanks again, kind regards.
--
Franco Martelli


Reply to: