0

Can someone give an example of an unit file in the "alias" state?

The docs says: "The name is an alias (symlink to another unit file)"

However, from what I understand, if the unit file is not enabled, and it is a symlink, it's either a symlink to a file outside of systemd reach (and thus in the state "linked"), or a symlink to a file inside systemd reach (and thus in the state "indirect").

EDIT: To be more specific, let's say I have this example service:

$ cat myservice.sh 
while true
do
echo "Looping"
sleep 30
done

And the unit file:

$ cat myservice.service
[Unit]
Description=Example Service.

[Service]
Type=simple
ExecStart=/bin/bash ~/myservice.sh

[Install]
WantedBy=multi-user.target

What should I do if I want to make an alias of myservice.service, that is an unit myalias.service -> myservice.service such that the output of systemctl is-enabled myalias is alias?

1 Answer 1

1

systemd.special(7) lists several units which should be aliased.

One example from the man page is:

   default.target
      The default unit systemd starts at bootup. Usually, this should be
      aliased (symlinked) to multi-user.target or graphical.target. See
      bootup(7) for more discussion.

      The default unit systemd starts at bootup can be overridden with the 
      systemd.unit= kernel command line option, or more conveniently, with 
      the short names like single, rescue, 1, 3, 5, ...; see systemd(1).

If I inspect the unit file on Debian testing, I see:

$ systemctl cat default.target
# /lib/systemd/system/graphical.target
#  SPDX-License-Identifier: LGPL-2.1+
#
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

[Unit]
Description=Graphical Interface
Documentation=man:systemd.special(7)
Requires=multi-user.target
Wants=display-manager.service
Conflicts=rescue.service rescue.target
After=multi-user.target rescue.service rescue.target display-manager.service
AllowIsolate=yes

$ systemctl status default.target
● graphical.target - Graphical Interface
     Loaded: loaded (/lib/systemd/system/graphical.target; static)
     Active: active since Tue 2020-08-18 08:01:45 CEST; 4 days ago
       Docs: man:systemd.special(7)

Aug 18 08:01:45 stewbian systemd[1]: Reached target Graphical Interface.

$ systemctl is-enabled default.target
alias

If we want to see other aliases alias, we can ls the directory and grep all links which are not masks:

$ ls -l /lib/systemd/system/ | grep -e '^l' | grep -v '/dev/null'
lrwxrwxrwx [email protected] -> [email protected]
lrwxrwxrwx ctrl-alt-del.target -> reboot.target
lrwxrwxrwx dbus-org.freedesktop.hostname1.service -> systemd-hostnamed.service
lrwxrwxrwx dbus-org.freedesktop.locale1.service -> systemd-localed.service
lrwxrwxrwx dbus-org.freedesktop.login1.service -> systemd-logind.service
lrwxrwxrwx dbus-org.freedesktop.timedate1.service -> systemd-timedated.service
lrwxrwxrwx default.target -> graphical.target
lrwxrwxrwx gdm3.service -> gdm.service
lrwxrwxrwx kmod.service -> systemd-modules-load.service
lrwxrwxrwx plymouth-log.service -> plymouth-read-write.service
lrwxrwxrwx plymouth.service -> plymouth-quit.service
lrwxrwxrwx procps.service -> systemd-sysctl.service
lrwxrwxrwx runlevel0.target -> poweroff.target
lrwxrwxrwx runlevel1.target -> rescue.target
lrwxrwxrwx runlevel2.target -> multi-user.target
lrwxrwxrwx runlevel3.target -> multi-user.target
lrwxrwxrwx runlevel4.target -> multi-user.target
lrwxrwxrwx runlevel5.target -> graphical.target
lrwxrwxrwx runlevel6.target -> reboot.target
lrwxrwxrwx speech-dispatcher.service -> speech-dispatcherd.service
lrwxrwxrwx udev.service -> systemd-udevd.service

The only example on my machine of a service that is not static is speech-dispatcher.service:

$ systemctl is-enabled speech-dispatcher.service
alias
$ systemctl status speech-dispatcher.service
● speech-dispatcherd.service - Speech-Dispatcher, common interface to speech synthesizers
     Loaded: loaded (/lib/systemd/system/speech-dispatcherd.service; disabled; vendor preset: enabled)
     Active: inactive (dead)

You'll notice that it's disabled. If I enable it I get:

$ systemctl enable speech-dispatcher.service
Synchronizing state of speech-dispatcher.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable speech-dispatcher
Created symlink /etc/systemd/system/speech-dispatcher.service → /lib/systemd/system/speech-dispatcherd.service.
Created symlink /etc/systemd/system/multi-user.target.wants/speech-dispatcherd.service → /lib/systemd/system/speech-dispatcherd.service.

$ systemctl status speech-dispatcher.service
● speech-dispatcherd.service - Speech-Dispatcher, common interface to speech synthesizers
     Loaded: loaded (/lib/systemd/system/speech-dispatcherd.service; enabled; vendor preset: enabled)
     Active: inactive (dead)

stew ~ $ systemctl is-enabled speech-dispatcher.service
alias
5
  • But if I do systemctl is-enabled default.target I get static. I wanted an example in which that command output was alias. Commented Aug 22, 2020 at 6:52
  • In the answer above, you can also see gdm3.service -> gdm.service. If I systemctl is-enabled gdm3.service I get alias. Will edit the answer
    – Stewart
    Commented Aug 22, 2020 at 6:55
  • From systemctl is-enabled procps.service I get static. And from ls... I get procps.service -> systemd-sysctl.service. In fact I get static or disabled from most of the symlinks, I don't understand... Commented Aug 22, 2020 at 7:09
  • In that case, most of your symlink units are static or disabled. Try enabling one to see what it's like. I updated the answer with the only non-static unit on my machine.
    – Stewart
    Commented Aug 22, 2020 at 7:11
  • I had smartmontools.service in disabled state, but after systemctl enable smartmontools the state become enabled. I practically tried all the symlinks in my system, result it's either static, or indirect, or enabled, or disabled (which become enabled). I edited the question, if I wanted to make my example of an alias what should I do? Commented Aug 22, 2020 at 7:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .