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

@felagund

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐛Programming errors, that need preferential fixinginstallpid1

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions