2020-03-04 09:35:06 +00:00
#!/usr/bin/env bash
2021-10-17 18:13:06 +02:00
# SPDX-License-Identifier: LGPL-2.1-or-later
2019-04-01 16:51:55 +02:00
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh
2021-04-09 19:39:41 +02:00
set -eux
2019-04-01 16:51:55 +02:00
set -o pipefail
2023-05-16 18:50:43 +02:00
# Test unit configuration/state/cache/log/runtime data cleanup
2023-05-16 19:56:30 +02:00
at_exit( ) {
set +e
rm -fr /{ etc,run,var/lib,var/cache,var/log} /test-service
rm -fr /{ etc,run,var/lib,var/cache,var/log} /private/test-service
rm -fr /{ etc,run,var/lib,var/cache,var/log} /hoge
rm -fr /{ etc,run,var/lib,var/cache,var/log} /test-socket
}
trap at_exit EXIT
2023-04-29 09:10:11 +09:00
cat >/run/systemd/system/test-service.service <<EOF
2019-04-01 16:51:55 +02:00
[ Service]
2023-03-31 18:42:38 +02:00
ConfigurationDirectory = test-service
RuntimeDirectory = test-service
StateDirectory = test-service
CacheDirectory = test-service
LogsDirectory = test-service
2019-04-01 16:51:55 +02:00
RuntimeDirectoryPreserve = yes
2024-01-04 15:24:52 +01:00
ExecStart = sleep infinity
2019-04-01 16:51:55 +02:00
Type = exec
EOF
systemctl daemon-reload
2023-03-31 18:42:38 +02:00
test ! -e /etc/test-service
test ! -e /run/test-service
test ! -e /var/lib/test-service
test ! -e /var/cache/test-service
test ! -e /var/log/test-service
2019-04-01 16:51:55 +02:00
2023-03-31 18:42:38 +02:00
systemctl start test-service
2019-04-01 16:51:55 +02:00
2023-03-31 18:42:38 +02:00
test -d /etc/test-service
test -d /run/test-service
test -d /var/lib/test-service
test -d /var/cache/test-service
test -d /var/log/test-service
2019-04-01 16:51:55 +02:00
2023-04-05 15:50:42 +02:00
( ! systemctl clean test-service)
2019-04-01 16:51:55 +02:00
2023-03-31 18:42:38 +02:00
systemctl stop test-service
2019-04-01 16:51:55 +02:00
2023-03-31 18:42:38 +02:00
test -d /etc/test-service
test -d /run/test-service
test -d /var/lib/test-service
test -d /var/cache/test-service
test -d /var/log/test-service
2019-04-01 16:51:55 +02:00
2023-03-31 18:42:38 +02:00
systemctl clean test-service --what= configuration
2019-04-01 16:51:55 +02:00
2023-03-31 18:42:38 +02:00
test ! -e /etc/test-service
test -d /run/test-service
test -d /var/lib/test-service
test -d /var/cache/test-service
test -d /var/log/test-service
2019-04-01 16:51:55 +02:00
2023-03-31 18:42:38 +02:00
systemctl clean test-service
2019-04-01 16:51:55 +02:00
2023-03-31 18:42:38 +02:00
test ! -e /etc/test-service
test ! -e /run/test-service
test -d /var/lib/test-service
test ! -e /var/cache/test-service
test -d /var/log/test-service
2019-04-01 16:51:55 +02:00
2023-03-31 18:42:38 +02:00
systemctl clean test-service --what= logs
2019-04-01 16:51:55 +02:00
2023-03-31 18:42:38 +02:00
test ! -e /etc/test-service
test ! -e /run/test-service
test -d /var/lib/test-service
test ! -e /var/cache/test-service
test ! -e /var/log/test-service
2019-04-01 16:51:55 +02:00
2023-03-31 18:42:38 +02:00
systemctl clean test-service --what= all
2019-04-01 16:51:55 +02:00
2023-03-31 18:42:38 +02:00
test ! -e /etc/test-service
test ! -e /run/test-service
test ! -e /var/lib/test-service
test ! -e /var/cache/test-service
test ! -e /var/log/test-service
2019-04-01 16:51:55 +02:00
2023-04-29 09:10:11 +09:00
cat >/run/systemd/system/test-service.service <<EOF
2019-08-25 16:27:33 +09:00
[ Service]
DynamicUser = yes
2023-03-31 18:42:38 +02:00
ConfigurationDirectory = test-service
RuntimeDirectory = test-service
StateDirectory = test-service
CacheDirectory = test-service
LogsDirectory = test-service
2019-08-25 16:27:33 +09:00
RuntimeDirectoryPreserve = yes
2024-01-04 15:24:52 +01:00
ExecStart = sleep infinity
2019-08-25 16:27:33 +09:00
Type = exec
EOF
systemctl daemon-reload
2023-03-31 18:42:38 +02:00
test ! -e /etc/test-service
test ! -e /run/test-service
test ! -e /var/lib/test-service
test ! -e /var/cache/test-service
test ! -e /var/log/test-service
systemctl restart test-service
test -d /etc/test-service
test -d /run/private/test-service
test -d /var/lib/private/test-service
test -d /var/cache/private/test-service
test -d /var/log/private/test-service
test -L /run/test-service
test -L /var/lib/test-service
test -L /var/cache/test-service
test -L /var/log/test-service
2023-04-05 15:50:42 +02:00
( ! systemctl clean test-service)
2023-03-31 18:42:38 +02:00
systemctl stop test-service
test -d /etc/test-service
test -d /run/private/test-service
test -d /var/lib/private/test-service
test -d /var/cache/private/test-service
test -d /var/log/private/test-service
test -L /run/test-service
test -L /var/lib/test-service
test -L /var/cache/test-service
test -L /var/log/test-service
systemctl clean test-service --what= configuration
test ! -d /etc/test-service
test -d /run/private/test-service
test -d /var/lib/private/test-service
test -d /var/cache/private/test-service
test -d /var/log/private/test-service
test -L /run/test-service
test -L /var/lib/test-service
test -L /var/cache/test-service
test -L /var/log/test-service
systemctl clean test-service
test ! -d /etc/test-service
test ! -d /run/private/test-service
test -d /var/lib/private/test-service
test ! -d /var/cache/private/test-service
test -d /var/log/private/test-service
test ! -L /run/test-service
test -L /var/lib/test-service
test ! -L /var/cache/test-service
test -L /var/log/test-service
systemctl clean test-service --what= logs
test ! -d /etc/test-service
test ! -d /run/private/test-service
test -d /var/lib/private/test-service
test ! -d /var/cache/private/test-service
test ! -d /var/log/private/test-service
test ! -L /run/test-service
test -L /var/lib/test-service
test ! -L /var/cache/test-service
test ! -L /var/log/test-service
systemctl clean test-service --what= all
test ! -d /etc/test-service
test ! -d /run/private/test-service
test ! -d /var/lib/private/test-service
test ! -d /var/cache/private/test-service
test ! -d /var/log/private/test-service
test ! -L /run/test-service
test ! -L /var/lib/test-service
test ! -L /var/cache/test-service
test ! -L /var/log/test-service
2019-08-25 16:27:33 +09:00
2023-04-29 09:10:11 +09:00
cat >/run/systemd/system/tmp-hoge.mount <<EOF
2019-08-31 09:30:12 +02:00
[ Mount]
What = tmpfs
Type = tmpfs
ConfigurationDirectory = hoge
RuntimeDirectory = hoge
StateDirectory = hoge
CacheDirectory = hoge
LogsDirectory = hoge
EOF
systemctl daemon-reload
2021-04-07 23:24:25 +02:00
test ! -e /etc/hoge
test ! -e /run/hoge
test ! -e /var/lib/hoge
test ! -e /var/cache/hoge
test ! -e /var/log/hoge
2019-08-31 09:30:12 +02:00
systemctl start tmp-hoge.mount
test -d /etc/hoge
test -d /run/hoge
test -d /var/lib/hoge
test -d /var/cache/hoge
test -d /var/log/hoge
2023-04-05 15:50:42 +02:00
( ! systemctl clean tmp-hoge.mount)
2019-08-31 09:30:12 +02:00
test -d /etc/hoge
test -d /run/hoge
test -d /var/lib/hoge
test -d /var/cache/hoge
test -d /var/log/hoge
systemctl stop tmp-hoge.mount
test -d /etc/hoge
2021-04-07 23:24:25 +02:00
test ! -d /run/hoge
2019-08-31 09:30:12 +02:00
test -d /var/lib/hoge
test -d /var/cache/hoge
test -d /var/log/hoge
systemctl clean tmp-hoge.mount --what= configuration
2021-04-07 23:24:25 +02:00
test ! -d /etc/hoge
test ! -d /run/hoge
2019-08-31 09:30:12 +02:00
test -d /var/lib/hoge
test -d /var/cache/hoge
test -d /var/log/hoge
systemctl clean tmp-hoge.mount
2021-04-07 23:24:25 +02:00
test ! -d /etc/hoge
test ! -d /run/hoge
2019-08-31 09:30:12 +02:00
test -d /var/lib/hoge
2021-04-07 23:24:25 +02:00
test ! -d /var/cache/hoge
2019-08-31 09:30:12 +02:00
test -d /var/log/hoge
systemctl clean tmp-hoge.mount --what= logs
2021-04-07 23:24:25 +02:00
test ! -d /etc/hoge
test ! -d /run/hoge
2019-08-31 09:30:12 +02:00
test -d /var/lib/hoge
2021-04-07 23:24:25 +02:00
test ! -d /var/cache/hoge
test ! -d /var/log/hoge
2019-08-31 09:30:12 +02:00
systemctl clean tmp-hoge.mount --what= all
2021-04-07 23:24:25 +02:00
test ! -d /etc/hoge
test ! -d /run/hoge
test ! -d /var/lib/hoge
test ! -d /var/cache/hoge
test ! -d /var/log/hoge
2019-08-31 09:30:12 +02:00
2023-04-29 09:10:11 +09:00
cat >/run/systemd/system/test-service.socket <<EOF
2019-08-31 09:30:12 +02:00
[ Socket]
2023-03-31 18:42:38 +02:00
ListenSequentialPacket = /run/test-service.socket
2019-08-31 09:30:12 +02:00
RemoveOnStop = yes
ExecStartPre = true
2023-03-31 18:42:38 +02:00
ConfigurationDirectory = test-socket
RuntimeDirectory = test-socket
StateDirectory = test-socket
CacheDirectory = test-socket
LogsDirectory = test-socket
2019-08-31 09:30:12 +02:00
EOF
systemctl daemon-reload
2023-03-31 18:42:38 +02:00
test ! -e /etc/test-socket
test ! -e /run/test-socket
test ! -e /var/lib/test-socket
test ! -e /var/cache/test-socket
test ! -e /var/log/test-socket
2019-08-31 09:30:12 +02:00
2023-03-31 18:42:38 +02:00
systemctl start test-service.socket
2019-08-31 09:30:12 +02:00
2023-03-31 18:42:38 +02:00
test -d /etc/test-socket
test -d /run/test-socket
test -d /var/lib/test-socket
test -d /var/cache/test-socket
test -d /var/log/test-socket
2019-08-31 09:30:12 +02:00
2023-04-05 15:50:42 +02:00
( ! systemctl clean test-service.socket)
2019-08-31 09:30:12 +02:00
2023-03-31 18:42:38 +02:00
systemctl stop test-service.socket
2019-08-31 09:30:12 +02:00
2023-03-31 18:42:38 +02:00
test -d /etc/test-socket
test ! -d /run/test-socket
test -d /var/lib/test-socket
test -d /var/cache/test-socket
test -d /var/log/test-socket
2019-08-31 09:30:12 +02:00
2023-03-31 18:42:38 +02:00
systemctl clean test-service.socket --what= configuration
2019-08-31 09:30:12 +02:00
2023-03-31 18:42:38 +02:00
test ! -e /etc/test-socket
test ! -d /run/test-socket
test -d /var/lib/test-socket
test -d /var/cache/test-socket
test -d /var/log/test-socket
2019-08-31 09:30:12 +02:00
2023-03-31 18:42:38 +02:00
systemctl clean test-service.socket
2019-08-31 09:30:12 +02:00
2023-03-31 18:42:38 +02:00
test ! -e /etc/test-socket
test ! -e /run/test-socket
test -d /var/lib/test-socket
test ! -e /var/cache/test-socket
test -d /var/log/test-socket
2019-08-31 09:30:12 +02:00
2023-03-31 18:42:38 +02:00
systemctl clean test-service.socket --what= logs
2019-08-31 09:30:12 +02:00
2023-03-31 18:42:38 +02:00
test ! -e /etc/test-socket
test ! -e /run/test-socket
test -d /var/lib/test-socket
test ! -e /var/cache/test-socket
test ! -e /var/log/test-socket
2019-08-31 09:30:12 +02:00
2023-03-31 18:42:38 +02:00
systemctl clean test-service.socket --what= all
2019-08-31 09:30:12 +02:00
2023-03-31 18:42:38 +02:00
test ! -e /etc/test-socket
test ! -e /run/test-socket
test ! -e /var/lib/test-socket
test ! -e /var/cache/test-socket
test ! -e /var/log/test-socket