Skip to content

wrappers/internal: Disable and re-enable daemons to refresh XXX.wants#16685

Open
sergio-costas wants to merge 1 commit intocanonical:masterfrom
sergio-costas:disable-and-reenable-daemons-to-refresh-xxx.wants
Open

wrappers/internal: Disable and re-enable daemons to refresh XXX.wants#16685
sergio-costas wants to merge 1 commit intocanonical:masterfrom
sergio-costas:disable-and-reenable-daemons-to-refresh-xxx.wants

Conversation

@sergio-costas
Copy link
Contributor

This is the first of three PRs to replace #16601

If the WantedBy entry in the Install section of a .service file changes from default to graphical-session, the soft link at /etc/systemd/user/default.target.wants must be deleted and a new one at /etc/systemd/user/graphical-session.target.wants must be created for those user daemons that have changed. But this must be done only to those daemons that are enabled, to avoid enabling daemons that the user manually disabled.

This can happen in two cases:

  • snapd is updated from the old versions that didn't support graphical-session target to a new version that supports it, so all the currently user services already installed will have their .service files updated with the new WantedBy entry.
  • a snap with an user service is updated, and the new version have added or removed the desktop plug in any of the user services.

In both cases, a systemctl --user reenable SERVICE-NAME must be run to update the symlinks at /etc/systemd/user/default.target.wants and /etc/systemd/user/graphical-session.target.wants folders, but only if it is globally enabled. That command removes the symlinks at the wrong places and re-creates them in the right places.

This patch does that, but only for globally-enabled (preset) user daemons. Locally-enabled daemons (thus, with their symlinks placed at $HOME/.config/systemd/user/XXXXX.target.wants`) aren't modified. That is a task for another PR.

Thanks for helping us make a better snapd!
Have you signed the license agreement and read the contribution guide?

If the `WantedBy` entry in the `Install` section of a .service
file changes from `default` to `graphical-session`, the soft
link at `/etc/systemd/user/default.target.wants` must be deleted
and a new one at `/etc/systemd/user/graphical-session.target.wants`
must be created for those user daemons that have changed.
But this must be done only to those daemons that are enabled,
to avoid enabling daemons that the user manually disabled.

This can happen in two cases:

* snapd is updated from the old versions that didn't support
  `graphical-session` target to a new version that supports it,
  so all the currently user services already installed will have
  their .service files updated with the new WantedBy entry.
* a snap with an user service is updated, and the new version
  have added or removed the `desktop` plug in any of the user
  services.

In both cases, a `systemctl --user reenable SERVICE-NAME` must
be run to update the symlinks at `/etc/systemd/user/default.target.wants`
and `/etc/systemd/user/graphical-session.target.wants` folders,
but only if it is globally enabled. That command removes the
symlinks at the wrong places and re-creates them in the right
places.

This patch does that, but only for globally-enabled (preset)
user daemons. Locally-enabled daemons (thus, with their symlinks
placed at $HOME/.config/systemd/user/XXXXX.target.wants`) aren't
modified. That is a task for another PR.
@codecov
Copy link

codecov bot commented Feb 27, 2026

Codecov Report

❌ Patch coverage is 14.52991% with 100 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.56%. Comparing base (8d929ea) to head (d503421).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
usersession/agent/rest_api.go 0.00% 54 Missing ⚠️
wrappers/services.go 0.00% 42 Missing ⚠️
systemd/emulation.go 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #16685      +/-   ##
==========================================
+ Coverage   77.52%   77.56%   +0.03%     
==========================================
  Files        1359     1353       -6     
  Lines      187225   187212      -13     
  Branches     2446     2446              
==========================================
+ Hits       145152   145205      +53     
+ Misses      33298    33241      -57     
+ Partials     8775     8766       -9     
Flag Coverage Δ
unittests 77.56% <14.52%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
Copy link

Fri Feb 27 10:42:22 UTC 2026
The following results are from: https://github.com/canonical/snapd/actions/runs/22480359078

Failures:

Executing:

  • openstack:debian-12-64:tests/main/cgroup-devices-v2
  • openstack:ubuntu-core-18-64:tests/core/services
  • openstack:ubuntu-core-24-64:tests/main/snap-user-service-restart-on-upgrade
  • openstack:ubuntu-core-24-64:tests/main/dbus-activation-name-conflict
  • openstack:ubuntu-core-24-64:tests/main/snap-user-service-start-on-install
  • openstack:ubuntu-25.10-64:tests/unit/go:clang
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-snapd-startup
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-smoke-home:deny_session
  • openstack:ubuntu-24.04-64:tests/main/interface-allow-auto-connection:unset

Restoring:

  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-snapd-startup
  • openstack:ubuntu-25.10-64:tests/main/
  • openstack:ubuntu-25.10-64:

Skipped tests from snapd-testing-skip

  • openstack:ubuntu-24.04-64:tests/main/i18n

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant