2020-03-04 12:35:06 +03:00
#!/usr/bin/env bash
2019-04-01 17:51:55 +03: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 20:39:41 +03:00
set -eux
2019-04-01 17:51:55 +03:00
set -o pipefail
2021-04-08 01:09:55 +03:00
cat >/etc/systemd/system/testservice.service <<EOF
2019-04-01 17:51:55 +03:00
[ Service]
ConfigurationDirectory = testservice
RuntimeDirectory = testservice
StateDirectory = testservice
CacheDirectory = testservice
LogsDirectory = testservice
RuntimeDirectoryPreserve = yes
ExecStart = /bin/sleep infinity
Type = exec
EOF
systemctl daemon-reload
2021-04-08 00:24:25 +03:00
test ! -e /etc/testservice
test ! -e /run/testservice
test ! -e /var/lib/testservice
test ! -e /var/cache/testservice
test ! -e /var/log/testservice
2019-04-01 17:51:55 +03:00
systemctl start testservice
test -d /etc/testservice
test -d /run/testservice
test -d /var/lib/testservice
test -d /var/cache/testservice
test -d /var/log/testservice
2021-04-08 02:27:33 +03:00
systemctl clean testservice && { echo 'unexpected success' ; exit 1; }
2019-04-01 17:51:55 +03:00
systemctl stop testservice
test -d /etc/testservice
test -d /run/testservice
test -d /var/lib/testservice
test -d /var/cache/testservice
test -d /var/log/testservice
systemctl clean testservice --what= configuration
2021-04-08 00:24:25 +03:00
test ! -e /etc/testservice
2019-04-01 17:51:55 +03:00
test -d /run/testservice
test -d /var/lib/testservice
test -d /var/cache/testservice
test -d /var/log/testservice
systemctl clean testservice
2021-04-08 00:24:25 +03:00
test ! -e /etc/testservice
test ! -e /run/testservice
2019-04-01 17:51:55 +03:00
test -d /var/lib/testservice
2021-04-08 00:24:25 +03:00
test ! -e /var/cache/testservice
2019-04-01 17:51:55 +03:00
test -d /var/log/testservice
systemctl clean testservice --what= logs
2021-04-08 00:24:25 +03:00
test ! -e /etc/testservice
test ! -e /run/testservice
2019-04-01 17:51:55 +03:00
test -d /var/lib/testservice
2021-04-08 00:24:25 +03:00
test ! -e /var/cache/testservice
test ! -e /var/log/testservice
2019-04-01 17:51:55 +03:00
systemctl clean testservice --what= all
2021-04-08 00:24:25 +03:00
test ! -e /etc/testservice
test ! -e /run/testservice
test ! -e /var/lib/testservice
test ! -e /var/cache/testservice
test ! -e /var/log/testservice
2019-04-01 17:51:55 +03:00
2021-04-08 01:09:55 +03:00
cat >/etc/systemd/system/testservice.service <<EOF
2019-08-25 10:27:33 +03:00
[ Service]
DynamicUser = yes
ConfigurationDirectory = testservice
RuntimeDirectory = testservice
StateDirectory = testservice
CacheDirectory = testservice
LogsDirectory = testservice
RuntimeDirectoryPreserve = yes
ExecStart = /bin/sleep infinity
Type = exec
EOF
systemctl daemon-reload
2021-04-08 00:24:25 +03:00
test ! -e /etc/testservice
test ! -e /run/testservice
test ! -e /var/lib/testservice
test ! -e /var/cache/testservice
test ! -e /var/log/testservice
2019-08-25 10:27:33 +03:00
systemctl restart testservice
test -d /etc/testservice
test -d /run/private/testservice
test -d /var/lib/private/testservice
test -d /var/cache/private/testservice
test -d /var/log/private/testservice
test -L /run/testservice
test -L /var/lib/testservice
test -L /var/cache/testservice
test -L /var/log/testservice
2021-04-08 02:27:33 +03:00
systemctl clean testservice && { echo 'unexpected success' ; exit 1; }
2019-08-25 10:27:33 +03:00
systemctl stop testservice
test -d /etc/testservice
test -d /run/private/testservice
test -d /var/lib/private/testservice
test -d /var/cache/private/testservice
test -d /var/log/private/testservice
test -L /run/testservice
test -L /var/lib/testservice
test -L /var/cache/testservice
test -L /var/log/testservice
systemctl clean testservice --what= configuration
2021-04-08 00:24:25 +03:00
test ! -d /etc/testservice
2019-08-25 10:27:33 +03:00
test -d /run/private/testservice
test -d /var/lib/private/testservice
test -d /var/cache/private/testservice
test -d /var/log/private/testservice
test -L /run/testservice
test -L /var/lib/testservice
test -L /var/cache/testservice
test -L /var/log/testservice
systemctl clean testservice
2021-04-08 00:24:25 +03:00
test ! -d /etc/testservice
test ! -d /run/private/testservice
2019-08-25 10:27:33 +03:00
test -d /var/lib/private/testservice
2021-04-08 00:24:25 +03:00
test ! -d /var/cache/private/testservice
2019-08-25 10:27:33 +03:00
test -d /var/log/private/testservice
2021-04-08 00:24:25 +03:00
test ! -L /run/testservice
2019-08-25 10:27:33 +03:00
test -L /var/lib/testservice
2021-04-08 00:24:25 +03:00
test ! -L /var/cache/testservice
2019-08-25 10:27:33 +03:00
test -L /var/log/testservice
systemctl clean testservice --what= logs
2021-04-08 00:24:25 +03:00
test ! -d /etc/testservice
test ! -d /run/private/testservice
2019-08-25 10:27:33 +03:00
test -d /var/lib/private/testservice
2021-04-08 00:24:25 +03:00
test ! -d /var/cache/private/testservice
test ! -d /var/log/private/testservice
test ! -L /run/testservice
2019-08-25 10:27:33 +03:00
test -L /var/lib/testservice
2021-04-08 00:24:25 +03:00
test ! -L /var/cache/testservice
test ! -L /var/log/testservice
2019-08-25 10:27:33 +03:00
systemctl clean testservice --what= all
2021-04-08 00:24:25 +03:00
test ! -d /etc/testservice
test ! -d /run/private/testservice
test ! -d /var/lib/private/testservice
test ! -d /var/cache/private/testservice
test ! -d /var/log/private/testservice
test ! -L /run/testservice
test ! -L /var/lib/testservice
test ! -L /var/cache/testservice
test ! -L /var/log/testservice
2019-08-25 10:27:33 +03:00
2021-04-08 01:09:55 +03:00
cat >/etc/systemd/system/tmp-hoge.mount <<EOF
2019-08-31 10:30:12 +03:00
[ Mount]
What = tmpfs
Type = tmpfs
ConfigurationDirectory = hoge
RuntimeDirectory = hoge
StateDirectory = hoge
CacheDirectory = hoge
LogsDirectory = hoge
EOF
systemctl daemon-reload
2021-04-08 00:24:25 +03: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 10:30:12 +03: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
2021-04-08 02:27:33 +03:00
systemctl clean tmp-hoge.mount && { echo 'unexpected success' ; exit 1; }
2019-08-31 10:30:12 +03: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-08 00:24:25 +03:00
test ! -d /run/hoge
2019-08-31 10:30:12 +03: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-08 00:24:25 +03:00
test ! -d /etc/hoge
test ! -d /run/hoge
2019-08-31 10:30:12 +03:00
test -d /var/lib/hoge
test -d /var/cache/hoge
test -d /var/log/hoge
systemctl clean tmp-hoge.mount
2021-04-08 00:24:25 +03:00
test ! -d /etc/hoge
test ! -d /run/hoge
2019-08-31 10:30:12 +03:00
test -d /var/lib/hoge
2021-04-08 00:24:25 +03:00
test ! -d /var/cache/hoge
2019-08-31 10:30:12 +03:00
test -d /var/log/hoge
systemctl clean tmp-hoge.mount --what= logs
2021-04-08 00:24:25 +03:00
test ! -d /etc/hoge
test ! -d /run/hoge
2019-08-31 10:30:12 +03:00
test -d /var/lib/hoge
2021-04-08 00:24:25 +03:00
test ! -d /var/cache/hoge
test ! -d /var/log/hoge
2019-08-31 10:30:12 +03:00
systemctl clean tmp-hoge.mount --what= all
2021-04-08 00:24:25 +03: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 10:30:12 +03:00
2021-04-08 01:09:55 +03:00
cat >/etc/systemd/system/testservice.socket <<EOF
2019-08-31 10:30:12 +03:00
[ Socket]
ListenSequentialPacket = /run/testservice.socket
RemoveOnStop = yes
ExecStartPre = true
ConfigurationDirectory = testsocket
RuntimeDirectory = testsocket
StateDirectory = testsocket
CacheDirectory = testsocket
LogsDirectory = testsocket
EOF
systemctl daemon-reload
2021-04-08 00:24:25 +03:00
test ! -e /etc/testsocket
test ! -e /run/testsocket
test ! -e /var/lib/testsocket
test ! -e /var/cache/testsocket
test ! -e /var/log/testsocket
2019-08-31 10:30:12 +03:00
systemctl start testservice.socket
test -d /etc/testsocket
2021-04-08 01:09:38 +03:00
test -d /run/testsocket
2019-08-31 10:30:12 +03:00
test -d /var/lib/testsocket
test -d /var/cache/testsocket
test -d /var/log/testsocket
2021-04-08 02:27:33 +03:00
systemctl clean testservice.socket && { echo 'unexpected success' ; exit 1; }
2019-08-31 10:30:12 +03:00
systemctl stop testservice.socket
test -d /etc/testsocket
2021-04-08 00:24:25 +03:00
test ! -d /run/testsocket
2019-08-31 10:30:12 +03:00
test -d /var/lib/testsocket
test -d /var/cache/testsocket
test -d /var/log/testsocket
systemctl clean testservice.socket --what= configuration
2021-04-08 00:24:25 +03:00
test ! -e /etc/testsocket
test ! -d /run/testsocket
2019-08-31 10:30:12 +03:00
test -d /var/lib/testsocket
test -d /var/cache/testsocket
test -d /var/log/testsocket
systemctl clean testservice.socket
2021-04-08 00:24:25 +03:00
test ! -e /etc/testsocket
test ! -e /run/testsocket
2019-08-31 10:30:12 +03:00
test -d /var/lib/testsocket
2021-04-08 00:24:25 +03:00
test ! -e /var/cache/testsocket
2019-08-31 10:30:12 +03:00
test -d /var/log/testsocket
systemctl clean testservice.socket --what= logs
2021-04-08 00:24:25 +03:00
test ! -e /etc/testsocket
test ! -e /run/testsocket
2019-08-31 10:30:12 +03:00
test -d /var/lib/testsocket
2021-04-08 00:24:25 +03:00
test ! -e /var/cache/testsocket
test ! -e /var/log/testsocket
2019-08-31 10:30:12 +03:00
systemctl clean testservice.socket --what= all
2021-04-08 00:24:25 +03:00
test ! -e /etc/testsocket
test ! -e /run/testsocket
test ! -e /var/lib/testsocket
test ! -e /var/cache/testsocket
test ! -e /var/log/testsocket
2019-08-31 10:30:12 +03:00
2021-04-08 01:09:55 +03:00
echo OK >/testok
2019-04-01 17:51:55 +03:00
exit 0