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 with an absolute path as argument cannot be used to create template instances #661
It is not possible to properly enable a service file that has been symlinked in via systemctl enable.
Take the following example:
cat > test.unit <<EOF[Unit]Description=Test[Service]ExecStart=/bin/sleep infinity[Install]WantedBy=multi-user.targetEOF
sudo systemctl link $PWD/test.unit
sudo systemctl enable test.unit # Failed to execute operation: No such file or directory
Note that you can enable it by specifying the full path
sudo systemctl enable$PWD/test.unit # symlinks from multi-user.target.wants to $PWD/test.unit
This links directly to the local file. This strategy doesn't work for templated files:
cat >[email protected]<<EOF[Unit]Description=Test %i[Service]ExecStart=/bin/sleep infinity[Install]WantedBy=multi-user.targetEOF
sudo systemctl link $PWD/test.unit
sudo systemctl enable$PWD/[email protected]# Failed to execute operation: No such file or directory
It seems that it should be able to enable in both cases once it has been linked in without specifying the full path. The enable code could either follow the symlink and link directly to the linked file, or it could just symlink to the symlink and systemd could follow them during startup.
Reacted by Mark Stosberg, Romain Lalaut and Robert Kielty
The idea was that "link" only makes a unit available in the search paths and "enable" also hooks it in. i.e. "enable" is kind of a superset of "link", as it does the same work if you pass a path, plus some more...
But yeah the template issue you point out is a real issue that this logic cannot cover. Yuck.
changed the title [-]systemctl link followed by systemctl enable fails for templated services[/-][+]systemctl enable with an absolute path as argument cannot be used to create template instances[/+]on Jul 22, 2015
Why are you putting that unit file there? This is not standard. Add your
favorite unit files to systemd directory located usually in
/etc/systemd/system path(redhat default path). I think it's not a good idea
to manage symlinked path. After all I think systemd can support symlink if
you use it in the systemd directory planned to store unit files.
On Jul 22, 2015 10:45 PM, "Vish Ishaya" [email protected] wrote:
It is not possible to properly enable a service file that has been
symlinked in via systemctl enable.
Take the following example file
cat > test.unit <<EOF[Unit]Description=Test[Service]ExecStart=/bin/sleep infinity[Install]WantedBy=multi-user.targetEOF
sudo systemctl link $PWD/test.unit
sudo systemctl enable test.unit # Failed to execute operation: No such file or directory
Note that you can enable it by specifying the full path
sudo systemctl enable $PWD/test.unit #symlinks directly to from multi-user.target.wants to $PWD
This links directly to the local file and this strategy doesn't work for
templated files:
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl link $PWD/test.unit
sudo systemctl enable $PWD/[email protected] # Failed to execute operation: No such file or directory
It seems that it should be able to enable in both cases once it has been
linked in without specifying the full path. The enable code could either
follow the symlink and link directly to the linked file, or it could just
symlink to the symlink and systemd could follow them during startup.
—
Reply to this email directly or view it on GitHub #661.
On Wed, 22.07.15 11:49, S.Mohammad Emami Razavi ***@***.***) wrote:
Why are you putting that unit file there? This is not standard. Add your
favorite unit files to systemd directory located usually in
/etc/systemd/system path(redhat default path). I think it's not a good idea
to manage symlinked path. After all I think systemd can support symlink if
you use it in the systemd directory planned to store unit files.
In general I think we really should ensure that we support in systemd
a scheme nicely where you install a 3rd party unit file somewhere in
/opt or so, and then make it available to systemd with just "systemctl
link" or "systemctl enable", so that 3rd party stuff doesn't litter
/usr (which is private property of the OS vendor), and doesn't add
anything but symlinks to the 3rd party unit files to /etc.
Or in other words: I think what @vishvananda is trying to do is
something we explicitly should support to cover nicely for 3rd party
software, that is neither written by the owner of the machine nor
supplied by the original vendor of the OS but by some 3rd party ISV.
Reacted by Mark Stosberg, James Lawrence, Edward Gow, Alex, Jeremy Davis, Robert Kielty, vasiliymojam and Histalek
Therefore it can be labeled as a feature to implement. Can not it?
On Wed, Jul 22, 2015 at 11:34 PM, Lennart Poettering < [email protected]> wrote:
On Wed, 22.07.15 11:49, S.Mohammad Emami Razavi ([email protected])
wrote:
Why are you putting that unit file there? This is not standard. Add your
favorite unit files to systemd directory located usually in
/etc/systemd/system path(redhat default path). I think it's not a good
idea
to manage symlinked path. After all I think systemd can support symlink
if
you use it in the systemd directory planned to store unit files.
In general I think we really should ensure that we support in systemd
a scheme nicely where you install a 3rd party unit file somewhere in
/opt or so, and then make it available to systemd with just "systemctl
link" or "systemctl enable", so that 3rd party stuff doesn't litter
/usr (which is private property of the OS vendor), and doesn't add
anything but symlinks to the 3rd party unit files to /etc.
Or in other words: I think what @vishvananda is trying to do is
something we explicitly should support to cover nicely for 3rd party
software, that is neither written by the owner of the machine nor
supplied by the original vendor of the OS but by some 3rd party ISV.
—
Reply to this email directly or view it on GitHub #661 (comment).
~/tryit$ systemctl --user enable $(pwd)/serviceB.service
Created symlink from /home/me/.config/systemd/user/[email protected] to /home/me/tryit/serviceB.service.
Created symlink from /home/me/.config/systemd/user/[email protected] to /home/me/tryit/serviceB.service.
Created symlink from /home/me/.config/systemd/user/serviceBalias.service to /home/me/tryit/serviceB.service.
Created symlink from /home/me/.config/systemd/user/serviceB.service to /home/me/tryit/serviceB.service.
~/tryit$ systemctl --user list-unit-files
UNIT FILE STATE
serviceB.path linked
LIS_import_failure.service linked
serviceB.service enabled
[email protected] bad
[email protected] bad
serviceBalias.service enabled
So the template instance aliases serviceB@... do not get enabled while an alias w/o the @ does. If instance aliases would function then this issue could be worked around. In order to allow general use of template instance units, which would be much better than having the feature work in some cases and not others, this issue needs to be fixed.
I tested this again, and things seem fine. (With #22649. W/o it at least systemctl link ./some.service will be broken.)
The original report:
sudo systemctl link $PWD/test.unit sudo systemctl enable $PWD/[email protected]
Those two can never work, because we don't know what the type of the unit is. Systemd logic requires that the name of a service unit must end in .service. If a symlink was created manually with ln -s --relative test.unit /etc/systemd/system/test.service, then systemd would know that it's a service and not care about the target file name.
But if the unit is renamed to test4.service, those all work as expected:
$ sudo systemctl link $PWD/test4.service
$ sudo systemctl link ./test4.service
$ sudo systemctl link --root=/ $PWD/test4.service
$ sudo systemctl link --root=/ ./test4.service
(and disable removes the symlink again.)
$ sudo systemctl link --root=/ test4.service Non-absolute paths are not allowed when --root is used: test4.service
$ sudo systemctl link test4.service Link argument does contain at least one directory separator: test4.service
This is correct. [email protected] and [email protected] are not valid aliases of serviceB.service because a unit cannot simultaneously have and not have an instance. Thus serviceBalias.service is the only alias that should be created.
$ sudo systemctl disable ./serviceB.serviceWarning: Can't execute disable on the unit file path. Proceeding with the unit name.Removed "/etc/systemd/system/serviceBalias.service".Removed "/etc/systemd/system/serviceB.service".
$ sudo systemctl enable --root=/ ./serviceB.service[email protected]: symlink target name type "serviceB.service" does not match source, rejecting.[email protected]: symlink target name type "serviceB.service" does not match source, rejecting.Created symlink /etc/systemd/system/serviceBalias.service → /home/zbyszek/src/systemd/serviceB.service.Created symlink /etc/systemd/system/serviceB.service → /home/zbyszek/src/systemd/serviceB.service.
$ sudo systemctl disable serviceB.service Removed "/etc/systemd/system/serviceBalias.service".Removed "/etc/systemd/system/serviceB.service".
So all the examples listed seem to behave fine with git tip. I'll close this again.
--
There is a minor issue: the symlinks that are created often link to the resolved symlink target:
$ sudo systemctl enable --root=/ ./serviceB.service
...
Created symlink /etc/systemd/system/serviceBalias.service → /home/zbyszek/src/systemd/serviceB.service.
$ sudo systemctl link --root=/ ./[email protected]
Created symlink /etc/systemd/system/[email protected] → /home/zbyszek/src/systemd/[email protected].
$ sudo systemctl enable --root=/ [email protected]
Created symlink /etc/systemd/system/multi-user.target.wants/[email protected] → /home/zbyszek/src/systemd/[email protected].
Created symlink /etc/systemd/system/[email protected] → /home/zbyszek/src/systemd/[email protected].
It'd be nicer to link to the symlink, i.e. have /etc/systemd/system/serviceBalias.service → serviceB.service, and /etc/systemd/system/multi-user.target.wants/[email protected] → [email protected], and /etc/systemd/system/[email protected] → … not even created at all. But this is a separate issue.
Activity
poettering commentedon Jul 22, 2015
The idea was that "link" only makes a unit available in the search paths and "enable" also hooks it in. i.e. "enable" is kind of a superset of "link", as it does the same work if you pass a path, plus some more...
But yeah the template issue you point out is a real issue that this logic cannot cover. Yuck.
[-]systemctl link followed by systemctl enable fails for templated services[/-][+]systemctl enable with an absolute path as argument cannot be used to create template instances[/+]emamirazavi commentedon Jul 22, 2015
Why are you putting that unit file there? This is not standard. Add your
favorite unit files to systemd directory located usually in
/etc/systemd/system path(redhat default path). I think it's not a good idea
to manage symlinked path. After all I think systemd can support symlink if
you use it in the systemd directory planned to store unit files.
On Jul 22, 2015 10:45 PM, "Vish Ishaya" [email protected] wrote:
poettering commentedon Jul 22, 2015
emamirazavi commentedon Jul 22, 2015
Therefore it can be labeled as a feature to implement. Can not it?
On Wed, Jul 22, 2015 at 11:34 PM, Lennart Poettering <
[email protected]> wrote:
poettering commentedon Jul 22, 2015
Well, what @vishvananda pointed out is more than an RFE, since the current logic is not delivering what it was supposed to deliver.
keszybz commentedon Feb 18, 2017
This now works correctly with recent git. There were a bunch of fixes, mostly before v232, so I won't link to specific commits.
Tested:
All work as expected.
markstos commentedon Feb 22, 2017
Thank you for this feature!
aktau commentedon Jun 24, 2018
How far did you test the templated versions?
I'm asking in relation to #3010 (comment), where it seems that for me this does not work (when I have to supply a parameter).
keszybz commentedon Jun 25, 2018
It seems to work with
--root=/(i.e. on the client side), but not without (i.e. through pid1).elgow commentedon Jan 14, 2019
Related to this issue, template instances can't be created using aliases to work around this bug. For example
So the template instance aliases
serviceB@...do not get enabled while an alias w/o the@does. If instance aliases would function then this issue could be worked around. In order to allow general use of template instance units, which would be much better than having the feature work in some cases and not others, this issue needs to be fixed.keszybz commentedon Mar 3, 2022
I tested this again, and things seem fine. (With #22649. W/o it at least
systemctl link ./some.servicewill be broken.)The original report:
Those two can never work, because we don't know what the type of the unit is. Systemd logic requires that the name of a service unit must end in
.service. If a symlink was created manually withln -s --relative test.unit /etc/systemd/system/test.service, then systemd would know that it's a service and not care about the target file name.But if the unit is renamed to
test4.service, those all work as expected:(and
disableremoves the symlink again.)Those should not work, so this is good.
serviceB.servicefrom the previous comment:This is correct.
[email protected]and[email protected]are not valid aliases ofserviceB.servicebecause a unit cannot simultaneously have and not have an instance. ThusserviceBalias.serviceis the only alias that should be created.So all the examples listed seem to behave fine with git tip. I'll close this again.
--
There is a minor issue: the symlinks that are created often link to the resolved symlink target:
It'd be nicer to link to the symlink, i.e. have
/etc/systemd/system/serviceBalias.service → serviceB.service, and/etc/systemd/system/multi-user.target.wants/[email protected] → [email protected], and/etc/systemd/system/[email protected] → …not even created at all. But this is a separate issue.