Skip to content

Commit

Permalink
wrappers: do not reload activation units
Browse files Browse the repository at this point in the history
  • Loading branch information
Meulengracht committed Nov 14, 2024
1 parent e83b8eb commit f3e960c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 36 deletions.
82 changes: 47 additions & 35 deletions tests/main/services-socket-activation/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,56 +13,68 @@ restore: |
execute: |
[ -f /etc/systemd/system/snap.socket-activation.sleep-daemon.sock.socket ]
[ -S /var/snap/socket-activation/common/socket ]
verify_status() {
local ENABLED="$1"
local MAIN_ACTIVE="$2"
local ACT_ACTIVE="$3"
echo "Checking that services are listed correctly"
snap services | cat -n > svcs.txt
MATCH " 1\s+Service\s+Startup\s+Current\s+Notes$" < svcs.txt
MATCH " 2\s+socket-activation.sleep-daemon\s+${ENABLED}\s+${MAIN_ACTIVE}\s+socket-activated$" < svcs.txt
echo "Check that systemctl for the main unit is as expected"
systemctl show --property=UnitFileState snap.socket-activation.sleep-daemon.service | grep "static"
systemctl show --property=ActiveState snap.socket-activation.sleep-daemon.service | grep "ActiveState=${MAIN_ACTIVE}"
echo "Check that systemctl for the socket is looking correct too"
systemctl show --property=UnitFileState snap.socket-activation.sleep-daemon.sock.socket | grep "${ENABLED}"
systemctl show --property=ActiveState snap.socket-activation.sleep-daemon.sock.socket | grep "ActiveState=${ACT_ACTIVE}"
}
# verify default behavior on install is that the main service
# is inactive but enabled, and socket is active
verify_status "enabled" "inactive" "active"
# this will fail, but still start the service
echo "Start the primary unit, emulate that the trigger has run"
curl -D- --verbose --max-time 1 --unix-socket /var/snap/socket-activation/common/socket http://localhost/foo || true
# verify that the main service is now active
verify_status "enabled" "active" "active"
# test normal restart
snap restart socket-activation
echo "Checking that services are listed correctly"
snap services | cat -n > svcs.txt
MATCH " 1\s+Service\s+Startup\s+Current\s+Notes$" < svcs.txt
MATCH " 2\s+socket-activation.sleep-daemon\s+enabled\s+inactive\s+socket-activated$" < svcs.txt
verify_status "enabled" "active" "active"
echo "Checking that the service is reported as static"
systemctl show --property=UnitFileState snap.socket-activation.sleep-daemon.service | grep "static"
# test --reload restart, with --reload we expect different behavior
# because of systemd. Verify that systemd is acting like we expect
# as well
snap restart --reload socket-activation
echo "Checking that service activation unit is reported as enabled and running"
systemctl show --property=UnitFileState snap.socket-activation.sleep-daemon.sock.socket | grep "enabled"
systemctl show --property=ActiveState snap.socket-activation.sleep-daemon.sock.socket | grep "ActiveState=active"
verify_status "enabled" "active" "active"
systemctl reload-or-restart snap.socket-activation.sleep-daemon.sock.socket 2>&1 | MATCH "Job failed"
echo "Testing that we can stop will not disable the service"
snap stop socket-activation.sleep-daemon
systemctl show --property=UnitFileState snap.socket-activation.sleep-daemon.sock.socket | grep "enabled"
systemctl show --property=ActiveState snap.socket-activation.sleep-daemon.sock.socket | grep "ActiveState=inactive"
verify_status "enabled" "inactive" "inactive"
echo "Testing that we can correctly disable activations"
snap stop --disable socket-activation.sleep-daemon
echo "Verifying that service is now listed as disabled"
snap services | cat -n > svcs.txt
MATCH " 1\s+Service\s+Startup\s+Current\s+Notes$" < svcs.txt
MATCH " 2\s+socket-activation.sleep-daemon\s+disabled\s+inactive\s+socket-activated$" < svcs.txt
echo "Checking that service activation unit is reported as disabled and inactive"
systemctl show --property=UnitFileState snap.socket-activation.sleep-daemon.sock.socket | grep "disabled"
systemctl show --property=ActiveState snap.socket-activation.sleep-daemon.sock.socket | grep "ActiveState=inactive"
verify_status "disabled" "inactive" "inactive"
echo "Starting the service will start the socket unit, but not enable"
snap start socket-activation.sleep-daemon
echo "Checking that services are listed as expected"
snap services | cat -n > svcs.txt
MATCH " 1\s+Service\s+Startup\s+Current\s+Notes$" < svcs.txt
MATCH " 2\s+socket-activation.sleep-daemon\s+disabled\s+inactive\s+socket-activated$" < svcs.txt
echo "Checking that service activation unit is reported as disabled and active"
systemctl show --property=UnitFileState snap.socket-activation.sleep-daemon.sock.socket | grep "disabled"
systemctl show --property=ActiveState snap.socket-activation.sleep-daemon.sock.socket | grep "ActiveState=active"
verify_status "disabled" "inactive" "active"
echo "Enable service and verify its listed as enabled"
snap start --enable socket-activation.sleep-daemon
echo "Checking that services are listed correctly"
snap services | cat -n > svcs.txt
MATCH " 1\s+Service\s+Startup\s+Current\s+Notes$" < svcs.txt
MATCH " 2\s+socket-activation.sleep-daemon\s+enabled\s+inactive\s+socket-activated$" < svcs.txt
echo "Checking that service activation unit is reported as enabled and active again"
systemctl show --property=UnitFileState snap.socket-activation.sleep-daemon.sock.socket | grep "enabled"
systemctl show --property=ActiveState snap.socket-activation.sleep-daemon.sock.socket | grep "ActiveState=active"
verify_status "enabled" "inactive" "active"
5 changes: 4 additions & 1 deletion wrappers/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -1231,7 +1231,10 @@ func restartServicesByStatus(svcsSts []*internal.ServiceStatus, explicitServices
var unitsToRestart []string

// If the service is activated, then we must also consider it's activators
if len(st.ActivatorUnitStatuses()) != 0 {
// as long as we are not requesting a reload. For activated units reload
// is not a supported action. In that case treat it like a non-activated
// service.
if len(st.ActivatorUnitStatuses()) != 0 && !opts.Reload {

Check warning on line 1237 in wrappers/services.go

View check run for this annotation

Codecov / codecov/patch

wrappers/services.go#L1234-L1237

Added lines #L1234 - L1237 were not covered by tests
// Restart any activators first and operate normally on these
for _, act := range st.ActivatorUnitStatuses() {
// Use the primary name here for shouldRestart, as the caller
Expand Down

0 comments on commit f3e960c

Please sign in to comment.