Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot run systemctl disable --now on a template unit #15620

Closed
ondrejbudai opened this issue Apr 28, 2020 · 6 comments · Fixed by #31243
Closed

Cannot run systemctl disable --now on a template unit #15620

ondrejbudai opened this issue Apr 28, 2020 · 6 comments · Fixed by #31243
Labels
RFE 🎁 Request for Enhancement, i.e. a feature request systemctl

Comments

@ondrejbudai
Copy link

ondrejbudai commented Apr 28, 2020

systemd version the issue has been seen with

245

Used distribution

Fedora 32

Expected behaviour you didn't see

systemctl disable --now osbuild-worker@.service disables and stops all services spawned from a template unit.

Unexpected behaviour you saw

When I run systemctl disable --now osbuild-worker@.service, I got:
Failed to stop osbuild-worker@.service: Unit name osbuild-worker@.service is missing the instance name. See system logs and 'systemctl status osbuild-worker@.service' for details

I tried running systemctl disable --now "osbuild-worker@*.service" and got:
Glob pattern passed to enable, but globs are not supported for this. Invalid unit name "osbuild-worker@*.service" escaped as "osbuild-worker@\x2a.service".

Steps to reproduce the problem

  1. Create a template unit:
$ cat /usr/lib/systemd/system/osbuild-worker@.service
[Unit]
Description=OSBuild Composer Worker (%i)
Requires=osbuild-composer.socket

[Service]
Type=simple
ExecStart=/usr/libexec/osbuild-composer/osbuild-worker
  1. Try disabling it and stopping in one step:
systemctl disable --now osbuild-worker@.service

I originally discovered this issue when trying to get the systemd_preun RPM macro to get working with a template unit. The systemd_preun macro uses systemctl disable --now which makes it unusable for a template unit.

The workaround I found is to use systemctl disable and systemctl stop separately like this:

systemctl --no-reload disable osbuild-worker@.service
systemctl stop "osbuild-worker@*.service"

This issue was originally reported in #9862 but imho it got accidentally closed.

@AlexAegis
Copy link

AlexAegis commented Apr 16, 2022

Just to let everyone know, this issue is still around in version 250

systemctl disable --user --now 'barrier@*'
Glob pattern passed to enable, but globs are not supported for this.
Invalid unit name "barrier@*" escaped as "barrier@\x2a".

@scheuref
Copy link

scheuref commented Jul 13, 2022

that's annoying...
how can we disable a pattern of services with a simple command?

systemctl status ceph-osd@*.service # => works
systemctl stop ceph-osd@*.service # => works
systemctl disable ceph-osd@*.service # => does not work... why no consistent behavior?

edit 1:

systemctl stop ceph-osd.target # => works
systemctl disable ceph-osd.target ceph.target # => no error, but all ceph-osd@* are still started after rebooting (because of their symlinks in /etc/systemd/system/ceph.target.wants/)

edit 2:

solution 1: using a text file to list all instances
systemctl list-units -t service --state active --no-pager --full --plain --no-legend "ceph-*" | awk '/ceph-/ {print $1}' | tee /etc/opt/ceph-service.txt
cat /etc/opt/ceph-service.txt | while read i; do echo $i; systemctl disable --now $i; sleep 10; done
#reboot
cat /etc/opt/ceph-service.txt | while read i; do echo $i; systemctl enable --now $i; sleep 10; done

solution 2: masking all instances
systemctl stop ceph-osd.target
systemctl mask $(systemctl list-units -t service --all --no-pager --full --plain --no-legend "ceph-osd*" | awk '/ceph-/ {print $1}')
#reboot
systemctl unmask $(systemctl list-units -t service --all --no-pager --full --plain --no-legend "ceph-osd*" | awk '/ceph-/ {print $1}')
#nok: systemctl start ceph-osd.target
#https://serverfault.com/questions/734123/systemd-restart-all-instances-of-an-instantiated-service-at-once
systemctl start --all "ceph-osd@*"

solution 3 (best): masking the template
systemctl stop ceph-osd.target
#nok: systemctl mask ceph-osd@.service # Failed to mask unit: File /etc/systemd/system/ceph-osd@.service already exists.
#https://github.com/systemd/systemd/issues/12084#issuecomment-802468029
mkdir -vp /etc/systemd/system.control/; ln -vs /dev/null /etc/systemd/system.control/ceph-osd@.service; systemctl daemon-reload
#reboot
rm -v /etc/systemd/system.control/ceph-osd@.service; systemctl daemon-reload
systemctl start --all "ceph-osd@*"

@ferdnyc
Copy link
Contributor

ferdnyc commented May 25, 2023

@scheuref

systemctl disable unit@.service actually works — it's only when the --now is added in, that it produces an error. (In either case, it does also disable all instances of unit@*.service, although it doesn't mass stop them even if --now is present on the command.)

It's the mass-stop, more than the mass-disable, functionality that's really the problem. Mass-disabling instantiated templates works fine with unit@.service, at least in systemd 253.4:

$ sudo systemctl enable --now akmods@6.2.15-300.fc38.x86_64.service
Created symlink /etc/systemd/system/multi-user.target.wants/akmods@6.2.15-300.fc38.x86_64.service → /usr/lib/systemd/system/akmods@.service.

$ sudo systemctl list-units akmods@\*.service                      
  UNIT                                  LOAD   ACTIVE SUB    DESCRIPTION       >
  akmods@6.2.15-300.fc38.x86_64.service loaded active exited Builds and install>

$ sudo systemctl disable akmods@.service
Removed "/etc/systemd/system/multi-user.target.wants/akmods@6.2.15-300.fc38.x86_64.service".

$ sudo systemctl list-units akmods@\*.service                      
  UNIT                                  LOAD   ACTIVE SUB    DESCRIPTION       >
  akmods@6.2.15-300.fc38.x86_64.service loaded active exited Builds and install>

$ sudo systemctl stop akmods@6.2.15-300.fc38.x86_64.service

$ sudo systemctl list-units akmods@\*.service              
  UNIT LOAD ACTIVE SUB DESCRIPTION
0 loaded units listed. Pass --all to see loaded but inactive units, too.

$ sudo systemctl enable --now akmods@6.2.15-300.fc38.x86_64.service
Created symlink /etc/systemd/system/multi-user.target.wants/akmods@6.2.15-300.fc38.x86_64.service → /usr/lib/systemd/system/akmods@.service.

$ sudo systemctl disable --now akmods@.service
Removed "/etc/systemd/system/multi-user.target.wants/akmods@6.2.15-300.fc38.x86_64.service".
Failed to stop akmods@.service: Unit name akmods@.service is missing the instance name.
See system logs and 'systemctl status akmods@.service' for details.

$ sudo systemctl list-units akmods@\*.service                      
  UNIT                                  LOAD   ACTIVE SUB    DESCRIPTION       >
  akmods@6.2.15-300.fc38.x86_64.service loaded active exited Builds and install>

@ferdnyc
Copy link
Contributor

ferdnyc commented May 25, 2023

This is also unfortunate, because /usr/lib/systemd/systemd-update-helper attempts to call systemctl disable --now on its arguments whenever its remove-system-units subcommand is used. Which means that /usr/lib/systemd/systemd-update-helper remove-system-units akmods@.service will return an error, and fail to stop any instantiated units of the template (though it will disable them).

prestist added a commit to prestist/systemd that referenced this issue Jun 30, 2023
While unistalling a RPM using the `preun` macro templated units produce a
warning `Failed to stop $@: Unit name $@ is missing the instance name.`
This issue seems to be caputred by
systemd#15620. To prevent this warning
when using RPM macros, adjust macro to function without `--now` argument.
prestist added a commit to prestist/systemd that referenced this issue Jul 3, 2023
While unistalling a RPM using the `preun` macro templated units produce a
warning `Failed to stop $@: Unit name $@ is missing the instance name.`
This issue seems to be caputred by systemd#15620. To prevent this warning when
using RPM macros, adjust macro to function without `--now` argument.
prestist added a commit to prestist/systemd that referenced this issue Jul 3, 2023
While uninstalling a RPM using the `preun` macro templated units produce a
warning `Failed to stop $@: Unit name $@ is missing the instance name.`
This issue seems to be captured by systemd#15620. To prevent this warning when
using RPM macros adjust macro to function without `--now` argument.
prestist added a commit to prestist/systemd that referenced this issue Jul 3, 2023
While uninstalling a RPM using the `preun` macro templated units produce a
warning `Failed to stop $@: Unit name $@ is missing the instance name.`
This issue seems to be captured by systemd#15620. To prevent this warning when
using RPM macros adjust macro to function without `--now` argument.
prestist added a commit to prestist/systemd that referenced this issue Jul 3, 2023
While uninstalling a RPM using the `preun` macro templated units produce a
warning `Failed to stop $@: Unit name $@ is missing the instance name.`
This issue seems to be captured by systemd#15620. To prevent this warning when
using RPM macros adjust macro to function without `--now` argument.
YHNdnzj added a commit to YHNdnzj/systemd that referenced this issue Feb 7, 2024
YHNdnzj added a commit to YHNdnzj/systemd that referenced this issue Feb 7, 2024
YHNdnzj added a commit to YHNdnzj/systemd that referenced this issue Feb 7, 2024
YHNdnzj added a commit to YHNdnzj/systemd that referenced this issue Feb 7, 2024
YHNdnzj added a commit to YHNdnzj/systemd that referenced this issue Feb 7, 2024
YHNdnzj added a commit to YHNdnzj/systemd that referenced this issue Feb 7, 2024
YHNdnzj added a commit to YHNdnzj/systemd that referenced this issue Feb 7, 2024
YHNdnzj added a commit to YHNdnzj/systemd that referenced this issue Feb 8, 2024
YHNdnzj added a commit to YHNdnzj/systemd that referenced this issue Feb 8, 2024
YHNdnzj added a commit to YHNdnzj/systemd that referenced this issue Feb 8, 2024
YHNdnzj added a commit to YHNdnzj/systemd that referenced this issue Feb 8, 2024
YHNdnzj added a commit to YHNdnzj/systemd that referenced this issue Feb 9, 2024
ayhamthemayhem pushed a commit to neighbourhoodie/nh-systemd that referenced this issue Mar 25, 2024
@GrabbenD
Copy link

GrabbenD commented Apr 23, 2024

Isn't there a better way of masking / disabling services with wildcard in 2024?

  • --all doesn't work for mask/unmask

    $ systemctl mask --all 'getty@tty*.service'
    Glob pattern passed to enable, but globs are not supported for this.
  • --all wont work for disable/enable unless --now is specified (which is a deal breaker in a system which isn't booted/when bootstrapping in chroot)

    System has not been booted with systemd as init system (PID 1). Can't operate.

  • Currently this is the only workaround that I've come across:

    $ cd /etc/systemd/system/getty.target.wants && \
      systemctl mask getty@tty*.service
  • (Sequences are another alternative in this instance. However, wildcards would be cleaner)

    $ systemctl mask getty@tty{1..9}.service

@ferdnyc
Copy link
Contributor

ferdnyc commented Apr 30, 2024

@GrabbenD You're commenting on a closed issue about something that was already fixed. If you think there are issues with how --all or wildcards are handled, I'd suggest opening a new issue documenting the problems. Commenting here is basically just shouting into the void.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFE 🎁 Request for Enhancement, i.e. a feature request systemctl
Development

Successfully merging a pull request may close this issue.

6 participants