You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
systemctl enable on linked service: 'Failed to execute operation: Too many levels of symbolic links' #3010
NOTE: Do not submit bug reports about anything but the two most recently released systemd versions upstream!
Used distribution
Ubuntu 16.04, 4.4.0-15-generic
In case of bug report: Expected behaviour you didn't see
After linking service via systemctl link from /home/developer directory and enabling it via systemctl enable I was expecting that the service should start on boot.
In case of bug report: Unexpected behaviour you saw
Enabling linked service causes to: 'Failed to execute operation: Too many levels of symbolic links'
In case of bug report: Steps to reproduce the problem
cat.service
[Unit]
Description=Service for populating desktop with cats.
[Service]
ExecStart=/bin/cat
[Install]
WantedBy=multi-user.target
$ sudo systemctl link /home/developer/cat.service
Created symlink from /etc/systemd/system/cat.service to /home/developer/cat.service.
$ sudo systemctl status cat.service
● cat.service - Service for populating desktop with cats.
Loaded: loaded (/home/developer/cat.service; linked
Active: inactive (dead)
$ sudo systemctl start cat.service
$ sudo systemctl is-enabled cat.service
linked
$ sudo systemctl enable cat.service
Failed to execute operation: Too many levels of symbolic links
$ ls -l /etc/systemd/system/multi-user.target.wants/ | grep -i 'cat'
(empty)
Looks like systemctl link places symlink in /etc/systemd/system, however if I place cat.service into /lib/systemd/system and then systemctl enable it, symlink will be created in /etc/systemd/system/multi-user.target.wants/.
Reacted by Lucy Park, Nicolas Graf, Doug Smith, Roman K, silverwind, Angelos Pikoulas, Nicolas Hennion, sakthi7, E Messulam and Aaron Meese
Related to this: If you directly enable a unit file with full path, it actually creates the symlinks, but then spits out a wrong error message:
# systemctl enable /tmp/foo.service
Created symlink from /etc/systemd/system/multi-user.target.wants/foo.service to /tmp/foo.service.
Created symlink from /etc/systemd/system/foo.service to /tmp/foo.service.
The unit files have no [Install] section. They are not meant to be enabled
using systemctl.
Possible reasons for having this kind of units are:
1) A unit may be statically enabled by being symlinked from another unit's
.wants/ or .requires/ directory.
2) A unit's purpose may be to act as a helper for some other unit which has
a requirement dependency on it.
3) A unit may be started when needed via activation (socket, path, timer,
D-Bus, udev, scripted systemctl call, ...).
I tried with @poettering 's large patch in PR #2973; it largely behaves the same way with systemctl enable /tmp/foo.service, and it's even worse when using --global:
# systemctl --global enable /tmp/foo.service
Assertion 'a' failed at src/basic/path-util.c:389, function path_compare(). Aborting.
Aborted (core dumped)
(I'm using --global as that makes it much easier to test modified systemctls without having to patch/install/reexec pid 1)
The "too many levels of symbolic links" error in the original report just seems to be a missing flag:
--- a/src/shared/install.c
+++ b/src/shared/install.c
@@ -1811,7 +1811,7 @@ int unit_file_enable(
return r;
STRV_FOREACH(f, files) {
- r = install_info_discover(scope, &c, root_dir, &paths, *f, SEARCH_LOAD, &i);
+ r = install_info_discover(scope, &c, root_dir, &paths, *f, SEARCH_LOAD|SEARCH_FOLLOW_CONFIG_SYMLINKS, &i);
if (r < 0)
return r;
if (i->type == UNIT_FILE_TYPE_MASKED)
With that, systemctl enable on a symlinked unit now actually creates the correct symlinks, but later fails with the "The unit files have no [Install] section" bogus error like in my first comment. I. e. this is now exactly equivalent to not doing systemctl link first and doing systemctl enable /some/path/myunit.service directly.
I'm trying to understand the expectations of the code in src/shared/install.c: I think install_info_symlink_wants() is supposed to return the number of units it actually enabled, i. e. 1 if we created one enablement symlink. But it currently returns 0 even after success, which causes the "0" return to propagate back through install_info_apply() → install_context_apply() → unit_file_enable(), and in the latter carries_install_info == 0 and thus systemctl enable prints that error message. On the other end, create_symlink() always just returns 0 on success (or negative on error), while it seems to me that all callers of create_symlink() expect that to return > 0 if it actually did something.
So apparently, fixing create_symlink() to return 1 if it did something, and continue to return 0 if the link already exists (with the same target) seems to fix it:
With the above two changes everything passes now. This breaks one test in ./test-install-root, so I'll look into that and propose a pull request for discussing this further, which is easier with by-line comments.
That test-install-root test case is covering exactly this issue:
* c) a unit file in /opt, that is linked into
* /etc/systemd/system, and where "enable" should result in
* -ELOOP, since using information from /etc to generate
* information in /etc should not be allowed.
I think this is a typo and was meaning to say "using information from /opt to generate information in /etc", and it does
where /etc/systemd/system/linked3.service → /opt/linked3.service.
So it seems that this is intentionally forbidden (even though the error message there is terrible). If we don't want to support unit symlinks from /etc/ to somewhere else (/opt in test-install-root, /tmp/ in my unit-config test, or /var/ in the bug report that I got), why do we offer systemctl link in the first place?
Depending on the answer, I'll either adjust the test case or add a comprehensible error message. Thanks!
systemctl enable foo.service should not be allowed if foo.service is a symlink in /etc/. This currently causes the "Too many levels of symbolic links" error message which ought to be improved.
systemctl enable or link on a full path should both be allowed.
Reacted by paitonic, qupeng, Jiří Kozlovský, Mir Adnan, lome lee, Laurie Bamber and Ben Davis
I fixed the bogus "No [Install] section" warning when enabling a unit with full path in PR #3016 (that also has a link to the now committed unit-test test case).
Let's keep this open for the part that systemctl enable foo.service prints out that bad "too many levels of symbolic links" error; @poettering wanted to fix that in his mega- PR #2973, to avoid touching the same code in two PRs.
I was here earlier looking for answers and figured it out, thought I'd post here to help anyone else that ends up in my shoes, and although I may have missed it, I haven't seen it anywhere spelled out in simple terms.
systemd works fine with symlinks, I was just using it wrong, and that's the reason I was getting the "too many levels of symlinks" error.
Just remember that if you ever disable the service or timer, all relative symlinks are removed (as @Celadora mentioned above), so you will need to re-enable with the full path as you did in the example above.
If you create the symlinks in /etc/systemd/system manually as in the example below, and then try to enable the timer, systemd tries to make a symlink in /etc/systemd/system/timers.target.wants/ to the timer file in /etc/systemd/system, and fails becuase it's symlinking to a symlink.
Reacted by Gerardwx, wblotevogel, simo, VirtualWolf, ghiaia, Giovanni Totaro - aka Vanni, sigmundholm, cerealito, Jiří Kozlovský, Brian Sidebotham and 33 more
Reacted by Thomas Mansencal, Matt Mueller, Thibaut Lemesle, semenovtm and Ralph Hart
Reacted by JuangaSocib, Kayvan Arianpour, Rico Moorman, YangChao, Thomas Mansencal, iBet7o, Matt Mueller and oharakouhei
$ systemctl link /home/vagrant/Git/hello_timers/systemd/[email protected]
Failed to execute operation: Unit name [email protected] is missing the instance name.
$ systemctl enable /home/vagrant/Git/hello_timers/systemd/[email protected]
Failed to execute operation: No such file or directory
Is this a bug? I want to use the @ parameter to inject the user for my services (since systemd --user is disabled in RHEL7 )
@bbkane this issue was about the error "Failed to execute operation: Too many levels of symbolic links", which is not what you are experiencing. According to your errors, you are trying to work with files that don't exist. Your support questions about systemd are better suited to the Unix & Linux StackExchange site. If you tag your question with [systemd], I follow that tag there. But you should check and provide evidence that the referenced files actually exist!
@markstos This is a tangent- apologies for that. I posted here because the method used by @dlford here didn't work for template files. I'll create a minimal example, put it on StackExchange, and edit this post with the link. Thanks!
@markstos so I reproduced the issue, created a question and GitHub repo with code to do it, and, finally, right before posting it, found #661 which says it's fixed in systemd 231. Unfortunately, Centos7 is stuck on systemd 219... I'll just have to cp the files. Thanks for the help.
I would not recommend attempting to upgrade `systemd` by "just cp'ing
files". Other parts of the system may depend on the specific behavior of a
particular version. It's also a good reminder to always mention what
version of software you are running when reporting bugs.
cp the [email protected]/timer files into /etc/systemd/system, then enabling them (as opposed to enabling them from my home directory), not systemd libraries or anything. Thanks for the help.
Just in case anyone else reads @bbkane's comment that the bug with templated files is fixed since systemd 231. I'm on Debian Stretch with systemd 232 and it still seems to exist:
[email protected] is a templated file, which is supposed to be supplied with a username (like aktau) in my case.
Full path enabling doesn't work (because the template instance isn't a path).
# systemctl enable $HOME/homesrv/systemd/[email protected]
Failed to enable unit: File /home/aktau/homesrv/systemd/[email protected]: No such file or directory
Without the parameter "works", but of course doesn't provide anything that runs.
# systemctl enable $HOME/homesrv/systemd/[email protected]
Created symlink /etc/systemd/system/[email protected] → /home/aktau/homesrv/systemd/[email protected].
The unit files have no installation config (WantedBy, RequiredBy, Also, Alias
settings in the [Install] section, and DefaultInstance for template units).
This means they are not meant to be enabled using systemctl.
Possible reasons for having this kind of units are:
1) A unit may be statically enabled by being symlinked from another unit's
.wants/ or .requires/ directory.
2) A unit's purpose may be to act as a helper for some other unit which has
a requirement dependency on it.
3) A unit may be started when needed via activation (socket, path, timer,
D-Bus, udev, scripted systemctl call, ...).
4) In case of template units, the unit is meant to be enabled with some
instance name specified.
Perhaps if I try a regular relative enable afterwards?
The only working alternative I've found is to cp the [email protected] timer file into /etc/systemd/system as @bbkane says, even on the systemd version where this is supposed to work.
Can anyone tell me if I'm holding this patch wrong?
I wanted to block sshd on a server of mine, so I masked it via systemctl, afterwards I needed to re-enable the service, so I proceeded to unmask it via normal procedure, however no systemd file were found.
A search with find / -name "sshd.service" revealed that there was only one file in /var/lib/systemd/deb-systemd-helper-enabled/sshd.service, and of course systemctl status and the other commands failed.
I then proceeded to apt install --reinstall openssh-server to no avail, followed by one final apt remove --purge openssh-server and apt install openssh-server again (backing up the config of course).
That worked, sort of - now I get this issue's title error.
Current situation:
file /etc/systemd/system/sshd.service
/etc/systemd/system/sshd.service: symbolic link to /lib/systemd/system/ssh.service
file /lib/systemd/system/ssh.service
/lib/systemd/system/ssh.service: ASCII text
systemctl status sshd.service
ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
Active: active (running) since [...]
file /etc/systemd/system/multi-user.target.wants/ssh.service
/etc/systemd/system/multi-user.target.wants/ssh.service: symbolic link to /lib/systemd/system/ssh.service
systemctl enable sshd.service
Failed to enable unit: Too many levels of symbolic links
systemctl disable sshd.service
Removed /etc/systemd/system/multi-user.target.wants/ssh.service.
Removed /etc/systemd/system/sshd.service.
systemctl enable sshd.service
Failed to enable unit: Unit file sshd.service does not exist.
ln -s /lib/systemd/system/ssh.service /etc/systemd/system/sshd.service
ln -s /lib/systemd/system/ssh.service /etc/systemd/system/multi-user.target.wants/ssh.service
systemctl daemon-reload
systemctl status sshd.service
ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
Active: active (running) since [...]
At this point I don't even know if this is an error related to openssh-server and/or if this issue is the right one to post this about.
If not, excuse me in advance, and please let me know where to post this issue in.
Thanks!
@bryanpedini this is more suitable for some debian forum. Version 241 is old, we only support the two latest versions upstream. Debian has special compilation settings to support split-usr and also that code has been changed a lot since 241.
Activity
martinpitt commentedon Apr 11, 2016
Related to this: If you directly enable a unit file with full path, it actually creates the symlinks, but then spits out a wrong error message:
martinpitt commentedon Apr 11, 2016
I tried with @poettering 's large patch in PR #2973; it largely behaves the same way with
systemctl enable /tmp/foo.service, and it's even worse when using--global:(I'm using
--globalas that makes it much easier to test modifiedsystemctls without having to patch/install/reexec pid 1)martinpitt commentedon Apr 11, 2016
I created https://gist.github.com/martinpitt/d65cf665066056cbf5ba366338b03f23 as a test case to reproduce this.
martinpitt commentedon Apr 11, 2016
The "too many levels of symbolic links" error in the original report just seems to be a missing flag:
With that,
systemctl enableon a symlinked unit now actually creates the correct symlinks, but later fails with the "The unit files have no [Install] section" bogus error like in my first comment. I. e. this is now exactly equivalent to not doingsystemctl linkfirst and doingsystemctl enable /some/path/myunit.servicedirectly.I'm trying to understand the expectations of the code in
src/shared/install.c: I thinkinstall_info_symlink_wants()is supposed to return the number of units it actually enabled, i. e. 1 if we created one enablement symlink. But it currently returns 0 even after success, which causes the "0" return to propagate back throughinstall_info_apply()→install_context_apply()→unit_file_enable(), and in the lattercarries_install_info == 0and thus systemctl enable prints that error message. On the other end,create_symlink()always just returns 0 on success (or negative on error), while it seems to me that all callers ofcreate_symlink()expect that to return > 0 if it actually did something.So apparently, fixing
create_symlink()to return 1 if it did something, and continue to return0if the link already exists (with the same target) seems to fix it:Am I on the right track here?
martinpitt commentedon Apr 11, 2016
I refined the "unit-config" tests to test "link+disable" and "link+enable+disable" separately: https://gist.github.com/martinpitt/dfb97e938f45ce1d079193cd414fb97b.
With the above two changes everything passes now. This breaks one test in
./test-install-root, so I'll look into that and propose a pull request for discussing this further, which is easier with by-line comments.martinpitt commentedon Apr 11, 2016
That test-install-root test case is covering exactly this issue:
I think this is a typo and was meaning to say "using information from /opt to generate information in /etc", and it does
where
/etc/systemd/system/linked3.service → /opt/linked3.service.So it seems that this is intentionally forbidden (even though the error message there is terrible). If we don't want to support unit symlinks from
/etc/to somewhere else (/optintest-install-root,/tmp/in myunit-configtest, or/var/in the bug report that I got), why do we offersystemctl linkin the first place?Depending on the answer, I'll either adjust the test case or add a comprehensible error message. Thanks!
martinpitt commentedon Apr 11, 2016
Discussed with @poettering:
systemctl enable foo.serviceshould not be allowed iffoo.serviceis a symlink in/etc/. This currently causes the "Too many levels of symbolic links" error message which ought to be improved.systemctl enableorlinkon a full path should both be allowed.martinpitt commentedon Apr 11, 2016
I fixed the bogus "No [Install] section" warning when enabling a unit with full path in PR #3016 (that also has a link to the now committed
unit-testtest case).Let's keep this open for the part that
systemctl enable foo.serviceprints out that bad "too many levels of symbolic links" error; @poettering wanted to fix that in his mega- PR #2973, to avoid touching the same code in two PRs.core: make sure we generate a nicer error when a linked unit is attem…
13 remaining items
Celadora commentedon Jan 15, 2017
I was able to work around this by using "systemctl daemon-reload" after placing the symbolic link in /etc/systemd/system
The only problem is that when you disable the service (systemctl disable [service]) the symbolic link is removed.
Hope this helps!
dlford commentedon Feb 25, 2017
I was here earlier looking for answers and figured it out, thought I'd post here to help anyone else that ends up in my shoes, and although I may have missed it, I haven't seen it anywhere spelled out in simple terms.
systemd works fine with symlinks, I was just using it wrong, and that's the reason I was getting the "too many levels of symlinks" error.
This works:
The above example creates all the symlinks needed:
Just remember that if you ever disable the service or timer, all relative symlinks are removed (as @Celadora mentioned above), so you will need to re-enable with the full path as you did in the example above.
If you create the symlinks in /etc/systemd/system manually as in the example below, and then try to enable the timer, systemd tries to make a symlink in /etc/systemd/system/timers.target.wants/ to the timer file in /etc/systemd/system, and fails becuase it's symlinking to a symlink.
This does not work:
keszybz commentedon Feb 27, 2017
That's unrelated. Like @msekletar wrote, it's a known issue (though I cannot find an upstream bug report).
bbkane commentedon Jan 4, 2018
I can't link / enable template services:
Is this a bug? I want to use the @ parameter to inject the user for my services (since
systemd --useris disabled in RHEL7 )markstos commentedon Jan 4, 2018
@bbkane this issue was about the error "Failed to execute operation: Too many levels of symbolic links", which is not what you are experiencing. According to your errors, you are trying to work with files that don't exist. Your support questions about
systemdare better suited to the Unix & Linux StackExchange site. If you tag your question with [systemd], I follow that tag there. But you should check and provide evidence that the referenced files actually exist!bbkane commentedon Jan 4, 2018
@markstos This is a tangent- apologies for that. I posted here because the method used by @dlford here didn't work for template files. I'll create a minimal example, put it on StackExchange, and edit this post with the link. Thanks!
bbkane commentedon Jan 5, 2018
@markstos so I reproduced the issue, created a question and GitHub repo with code to do it, and, finally, right before posting it, found #661 which says it's fixed in systemd 231. Unfortunately, Centos7 is stuck on systemd 219... I'll just have to cp the files. Thanks for the help.
markstos commentedon Jan 5, 2018
bbkane commentedon Jan 5, 2018
cpthe [email protected]/timer files into/etc/systemd/system, then enabling them (as opposed to enabling them from my home directory), not systemd libraries or anything. Thanks for the help.aktau commentedon Jun 24, 2018
Just in case anyone else reads @bbkane's comment that the bug with templated files is fixed since systemd 231. I'm on Debian Stretch with systemd 232 and it still seems to exist:
[email protected]is a templated file, which is supposed to be supplied with a username (likeaktau) in my case.Full path enabling doesn't work (because the template instance isn't a path).
Without the parameter "works", but of course doesn't provide anything that runs.
Perhaps if I try a regular relative enable afterwards?
No dice.
The only working alternative I've found is to
cpthe [email protected] timer file into/etc/systemd/systemas @bbkane says, even on the systemd version where this is supposed to work.Can anyone tell me if I'm holding this patch wrong?
Fix systemctl enable on linked service issue
bryanpedini commentedon Jan 29, 2021
Sorry to dig up an old thread, but...
I'm on Debian 10 stable
Linux <hostname> 4.19.0-13-amd64 #1 SMP Debian 4.19.160-2 (2020-11-28) x86_64 GNU/LinuxI wanted to block
sshdon a server of mine, so Imasked it viasystemctl, afterwards I needed to re-enable the service, so I proceeded tounmaskit via normal procedure, however no systemd file were found.A search with
find / -name "sshd.service"revealed that there was only one file in/var/lib/systemd/deb-systemd-helper-enabled/sshd.service, and of coursesystemctl statusand the other commands failed.I then proceeded to
apt install --reinstall openssh-serverto no avail, followed by one finalapt remove --purge openssh-serverandapt install openssh-serveragain (backing up the config of course).That worked, sort of - now I get this issue's title error.
Current situation:
At this point I don't even know if this is an error related to
openssh-serverand/or if this issue is the right one to post this about.If not, excuse me in advance, and please let me know where to post this issue in.
Thanks!
keszybz commentedon Jan 29, 2021
@bryanpedini this is more suitable for some debian forum. Version 241 is old, we only support the two latest versions upstream. Debian has special compilation settings to support split-usr and also that code has been changed a lot since 241.
bryanpedini commentedon Jan 29, 2021
I see, thank you for the suggestion.
I see, completely understand, thank you anyway!