Skip to content

A service file symbolically linked from a directory inside systemd path can be enabled and then gives bad error when started #22000

Closed

Description

@felagund

systemd version the issue has been seen with

248.3 (real hardware) and 249.5 (in Virtualbox)

Used distribution

Kubuntu 21.10 and 22.04 (in Virtualbox)

Linux kernel version used

Linux GreenOne 5.13.0-22-generic #22-Ubuntu SMP Fri Nov 5 13:21:36 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
Linux kubuntu 5.13.0-19-generic #19-Ubuntu SMP Thu Oct 7 21:58:00 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

CPU architecture issue was seen on

Intel i9-9880H anbd virtualbox

We create a unit file in home directory and link it to systemd path. It refuses to enable the unit file saying symbolic links are not supported. I am not sure why that is the case but at least the warning is meaningful. Now try to make a unit file in a subdirectory of systemd path (for example /etc/systemd/system/myown.d). It will enable the service file and when you try to run the file, the error is misleading.

I guess the correct behaviour would be catching that systemd is dealing with a linked file already at enabling phase.

Run this as root:

cd ~
cat > test.service <<EOF
[Unit]
Description=Test

[Service]
ExecStart=/bin/sleep infinity

[Install]
WantedBy=multi-user.target
EOF
ln -s test.service /etc/systemd/system/test.service
systemctl daemon-reload
systemctl enable test.service

It gives:

Failed to enable unit: Refusing to operate on alias name or linked unit file: test.service

Now run this:

rm /etc/systemd/system/test.service
cd /etc/systemd/system
mkdir myown.d
cp ~/test.service myown.d/
ln -s myown.d/test.service test.service
systemctl daemon-reload
systemctl enable test.service

it gives:

Created symlink /etc/systemd/system/multi-user.target.wants/test.service → /etc/systemd/system/myown.d/test.service.

Now run

systemctl start test.service

and we get:

Failed to start test.service: Unit test.service not found.

Activity

  1. felagund commented on Jan 4, 2022

    @felagund
    ContributorAuthor

    Not sure if this is not somehow related: #661

  2. added
    bug 🐛
    on Jan 5, 2022
  3. added this to the v251 milestone on Jan 5, 2022
  4. yuwata commented on Jan 5, 2022

    @yuwata
    Member

    Confirmed that v250 still has the issue.

  5. added a commit that references this issue on Mar 3, 2022
    93b6d6a
  6. linked a pull request that will close this issueFixups to the unit enablement logic #22649on Mar 24, 2022
  7. added 2 commits that reference this issue on Mar 29, 2022
    dc737b9
    047d37d
  8. volter commented on Sep 8, 2022

    @volter

    I feel that this is still present in systemd 251. Any unit file I symlink is considered "bad" in systemctl list-unit-files.

  9. yuwata commented on Sep 8, 2022

    @yuwata
    Member

    @volter Then, please open a new issue page with debugging logs. Thank you.

  10. barosl commented on Sep 22, 2022

    @barosl

    I feel that this is still present in systemd 251. Any unit file I symlink is considered "bad" in systemctl list-unit-files.

    @volter Did you give the symbolic link the same name as the original file? I found that when those two have different names, systemd reports the state of the unit as bad. Interestingly, even in that case I could start the service, although enabling the service failed. I wonder where this behavior is documented?

  11. volter commented on Sep 22, 2022

    @volter

    I used the systemctl-link command, which I guess gives the same names. In my setup, I resolved the problem by moving the directory containing the units out of /etc/systemd/system. The new issue yuwata requested actually exists: #24605

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐛installpid1

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions