2022-03-07 19:15:42 +08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# SPDX-License-Identifier: LGPL-2.1-or-later
|
|
|
|
set -ex
|
|
|
|
|
|
|
|
# Silence warning from running_in_chroot_or_offline()
|
|
|
|
export SYSTEMD_IGNORE_CHROOT=1
|
|
|
|
|
|
|
|
systemctl=${1:-systemctl}
|
2022-03-29 02:03:37 +08:00
|
|
|
systemd_id128=${2:-systemd-id128}
|
2022-03-07 19:15:42 +08:00
|
|
|
|
|
|
|
unset root
|
|
|
|
cleanup() {
|
|
|
|
[ -n "$root" ] && rm -rf "$root"
|
|
|
|
}
|
|
|
|
trap cleanup exit
|
|
|
|
root=$(mktemp -d --tmpdir systemctl-test.XXXXXX)
|
|
|
|
|
|
|
|
islink() {
|
|
|
|
test -h "$1" || return 1
|
|
|
|
test "$(readlink "$1")" = "$2" || return 2
|
|
|
|
}
|
|
|
|
|
2022-03-24 18:52:35 +08:00
|
|
|
: '------enable nonexistent------------------------------------'
|
2022-03-25 22:56:16 +08:00
|
|
|
( ! "$systemctl" --root="$root" enable test1.service )
|
2022-03-07 19:15:42 +08:00
|
|
|
|
2022-03-24 18:52:35 +08:00
|
|
|
: '------basic enablement--------------------------------------'
|
2022-03-07 19:15:42 +08:00
|
|
|
mkdir -p "$root/etc/systemd/system"
|
|
|
|
cat >"$root/etc/systemd/system/test1.service" <<EOF
|
|
|
|
[Install]
|
|
|
|
WantedBy=default.target
|
|
|
|
RequiredBy=special.target
|
|
|
|
EOF
|
|
|
|
|
|
|
|
"$systemctl" --root="$root" enable test1.service
|
|
|
|
test -h "$root/etc/systemd/system/default.target.wants/test1.service"
|
|
|
|
test -h "$root/etc/systemd/system/special.target.requires/test1.service"
|
|
|
|
|
|
|
|
"$systemctl" --root="$root" reenable test1.service
|
|
|
|
test -h "$root/etc/systemd/system/default.target.wants/test1.service"
|
|
|
|
test -h "$root/etc/systemd/system/special.target.requires/test1.service"
|
|
|
|
|
|
|
|
"$systemctl" --root="$root" disable test1.service
|
2022-03-25 22:43:27 +08:00
|
|
|
test ! -h "$root/etc/systemd/system/default.target.wants/test1.service"
|
|
|
|
test ! -h "$root/etc/systemd/system/special.target.requires/test1.service"
|
|
|
|
|
|
|
|
: '------enable when link already exists-----------------------'
|
|
|
|
# We don't read the symlink target, so it's OK for the symlink to point
|
|
|
|
# to something else. We should just silently accept this.
|
|
|
|
|
|
|
|
mkdir -p "$root/etc/systemd/system/default.target.wants"
|
|
|
|
mkdir -p "$root/etc/systemd/system/special.target.requires"
|
|
|
|
ln -s /usr/lib/systemd/system/test1.service "$root/etc/systemd/system/default.target.wants/test1.service"
|
|
|
|
ln -s /usr/lib/systemd/system/test1.service "$root/etc/systemd/system/special.target.requires/test1.service"
|
|
|
|
|
|
|
|
"$systemctl" --root="$root" enable test1.service
|
|
|
|
test -h "$root/etc/systemd/system/default.target.wants/test1.service"
|
|
|
|
test -h "$root/etc/systemd/system/special.target.requires/test1.service"
|
|
|
|
|
|
|
|
"$systemctl" --root="$root" reenable test1.service
|
|
|
|
test -h "$root/etc/systemd/system/default.target.wants/test1.service"
|
|
|
|
test -h "$root/etc/systemd/system/special.target.requires/test1.service"
|
|
|
|
|
|
|
|
"$systemctl" --root="$root" disable test1.service
|
|
|
|
test ! -h "$root/etc/systemd/system/default.target.wants/test1.service"
|
|
|
|
test ! -h "$root/etc/systemd/system/special.target.requires/test1.service"
|
2022-03-07 19:15:42 +08:00
|
|
|
|
2022-03-24 18:52:35 +08:00
|
|
|
: '------suffix guessing---------------------------------------'
|
2022-03-07 19:15:42 +08:00
|
|
|
"$systemctl" --root="$root" enable test1
|
|
|
|
test -h "$root/etc/systemd/system/default.target.wants/test1.service"
|
|
|
|
test -h "$root/etc/systemd/system/special.target.requires/test1.service"
|
|
|
|
|
|
|
|
"$systemctl" --root="$root" reenable test1
|
|
|
|
test -h "$root/etc/systemd/system/default.target.wants/test1.service"
|
|
|
|
test -h "$root/etc/systemd/system/special.target.requires/test1.service"
|
|
|
|
|
|
|
|
"$systemctl" --root="$root" disable test1
|
|
|
|
test ! -e "$root/etc/systemd/system/default.target.wants/test1.service"
|
|
|
|
test ! -e "$root/etc/systemd/system/special.target.requires/test1.service"
|
|
|
|
|
2022-03-24 18:52:35 +08:00
|
|
|
: '-------aliases----------------------------------------------'
|
2022-03-07 19:15:42 +08:00
|
|
|
cat >>"$root/etc/systemd/system/test1.service" <<EOF
|
|
|
|
Alias=test1-goodalias.service
|
|
|
|
Alias=test1@badalias.service
|
|
|
|
Alias=test1-badalias.target
|
|
|
|
Alias=test1-badalias.socket
|
shared/install: return failure when enablement fails, but process as much as possible
So far we'd issue a warning (before this series, just in the logs on the server
side, and before this commit, on stderr on the caller's side), but return
success. It seems that successfull return was introduced by mistake in
aa0f357fd833feecbea6c3e9be80b643e433bced (my fault :( ), which was supposed to
be a refactoring without a functional change. I think it's better to fail,
because if enablement fails, the user will most likely want to diagnose the
issue.
Note that we still do partial enablement, as far as that is possible. So if
e.g. we have [Install] Alias=foo.service foobar, we'll create the symlink
'foo.service', but not 'foobar', since that's not a valid unit name. We'll
print info about the action taken, and about 'foobar' being invalid, and return
failure.
2022-03-10 22:47:12 +08:00
|
|
|
# we have a series of good, bad, and then good again
|
|
|
|
Alias=test1-goodalias2.service
|
2022-03-07 19:15:42 +08:00
|
|
|
EOF
|
|
|
|
|
2022-03-25 22:56:16 +08:00
|
|
|
( ! "$systemctl" --root="$root" enable test1 )
|
shared/install: return failure when enablement fails, but process as much as possible
So far we'd issue a warning (before this series, just in the logs on the server
side, and before this commit, on stderr on the caller's side), but return
success. It seems that successfull return was introduced by mistake in
aa0f357fd833feecbea6c3e9be80b643e433bced (my fault :( ), which was supposed to
be a refactoring without a functional change. I think it's better to fail,
because if enablement fails, the user will most likely want to diagnose the
issue.
Note that we still do partial enablement, as far as that is possible. So if
e.g. we have [Install] Alias=foo.service foobar, we'll create the symlink
'foo.service', but not 'foobar', since that's not a valid unit name. We'll
print info about the action taken, and about 'foobar' being invalid, and return
failure.
2022-03-10 22:47:12 +08:00
|
|
|
test -h "$root/etc/systemd/system/default.target.wants/test1.service"
|
|
|
|
test -h "$root/etc/systemd/system/special.target.requires/test1.service"
|
2022-04-13 04:01:10 +08:00
|
|
|
test ! -e "$root/etc/systemd/system/test1-goodalias.service"
|
shared/install: return failure when enablement fails, but process as much as possible
So far we'd issue a warning (before this series, just in the logs on the server
side, and before this commit, on stderr on the caller's side), but return
success. It seems that successfull return was introduced by mistake in
aa0f357fd833feecbea6c3e9be80b643e433bced (my fault :( ), which was supposed to
be a refactoring without a functional change. I think it's better to fail,
because if enablement fails, the user will most likely want to diagnose the
issue.
Note that we still do partial enablement, as far as that is possible. So if
e.g. we have [Install] Alias=foo.service foobar, we'll create the symlink
'foo.service', but not 'foobar', since that's not a valid unit name. We'll
print info about the action taken, and about 'foobar' being invalid, and return
failure.
2022-03-10 22:47:12 +08:00
|
|
|
test -h "$root/etc/systemd/system/test1-goodalias.service"
|
2022-04-13 04:01:10 +08:00
|
|
|
test ! -e "$root/etc/systemd/system/test1@badalias.service"
|
|
|
|
test ! -e "$root/etc/systemd/system/test1-badalias.target"
|
|
|
|
test ! -e "$root/etc/systemd/system/test1-badalias.socket"
|
shared/install: return failure when enablement fails, but process as much as possible
So far we'd issue a warning (before this series, just in the logs on the server
side, and before this commit, on stderr on the caller's side), but return
success. It seems that successfull return was introduced by mistake in
aa0f357fd833feecbea6c3e9be80b643e433bced (my fault :( ), which was supposed to
be a refactoring without a functional change. I think it's better to fail,
because if enablement fails, the user will most likely want to diagnose the
issue.
Note that we still do partial enablement, as far as that is possible. So if
e.g. we have [Install] Alias=foo.service foobar, we'll create the symlink
'foo.service', but not 'foobar', since that's not a valid unit name. We'll
print info about the action taken, and about 'foobar' being invalid, and return
failure.
2022-03-10 22:47:12 +08:00
|
|
|
test -h "$root/etc/systemd/system/test1-goodalias2.service"
|
|
|
|
|
2022-03-24 18:52:35 +08:00
|
|
|
: '-------aliases in reeanble----------------------------------'
|
2022-03-25 22:56:16 +08:00
|
|
|
( ! "$systemctl" --root="$root" reenable test1 )
|
2022-04-13 04:01:10 +08:00
|
|
|
test -h "$root/etc/systemd/system/default.target.wants/test1.service"
|
|
|
|
test ! -e "$root/etc/systemd/system/test1-goodalias.service"
|
|
|
|
test -h "$root/etc/systemd/system/test1-goodalias.service"
|
2022-03-07 19:15:42 +08:00
|
|
|
|
2022-04-13 04:01:10 +08:00
|
|
|
test ! -e "$root/etc/systemd/system/test1@badalias.service"
|
|
|
|
test ! -e "$root/etc/systemd/system/test1-badalias.target"
|
|
|
|
test ! -e "$root/etc/systemd/system/test1-badalias.socket"
|
2022-03-07 19:15:42 +08:00
|
|
|
|
|
|
|
"$systemctl" --root="$root" disable test1
|
2022-04-13 04:01:10 +08:00
|
|
|
test ! -e "$root/etc/systemd/system/default.target.wants/test1.service"
|
|
|
|
test ! -e "$root/etc/systemd/system/special.target.requires/test1.service"
|
|
|
|
test ! -e "$root/etc/systemd/system/test1-goodalias.service"
|
2022-03-07 19:15:42 +08:00
|
|
|
|
2022-03-25 22:43:27 +08:00
|
|
|
: '-------aliases when link already exists---------------------'
|
|
|
|
cat >"$root/etc/systemd/system/test1a.service" <<EOF
|
|
|
|
[Install]
|
|
|
|
Alias=test1a-alias.service
|
|
|
|
EOF
|
|
|
|
|
|
|
|
ln -s /usr/lib/systemd/system/test1a.service "$root/etc/systemd/system/test1a-alias.service"
|
|
|
|
|
|
|
|
"$systemctl" --root="$root" enable test1a.service
|
|
|
|
test -h "$root/etc/systemd/system/test1a-alias.service"
|
|
|
|
|
|
|
|
"$systemctl" --root="$root" disable test1a.service
|
|
|
|
test ! -h "$root/etc/systemd/system/test1a-alias.service"
|
|
|
|
|
2022-03-24 18:52:35 +08:00
|
|
|
: '-------also units-------------------------------------------'
|
2022-03-07 19:15:42 +08:00
|
|
|
cat >"$root/etc/systemd/system/test2.socket" <<EOF
|
|
|
|
[Install]
|
|
|
|
WantedBy=sockets.target
|
|
|
|
Also=test2.service
|
|
|
|
EOF
|
|
|
|
|
|
|
|
cat >"$root/etc/systemd/system/test2.service" <<EOF
|
|
|
|
[Install]
|
|
|
|
WantedBy=default.target
|
|
|
|
Also=test2.socket
|
|
|
|
EOF
|
|
|
|
|
|
|
|
"$systemctl" --root="$root" reenable test2.service
|
|
|
|
test -h "$root/etc/systemd/system/default.target.wants/test2.service"
|
|
|
|
test -h "$root/etc/systemd/system/sockets.target.wants/test2.socket"
|
|
|
|
|
|
|
|
"$systemctl" --root="$root" reenable test2.socket
|
|
|
|
test -h "$root/etc/systemd/system/default.target.wants/test2.service"
|
|
|
|
test -h "$root/etc/systemd/system/sockets.target.wants/test2.socket"
|
|
|
|
|
|
|
|
"$systemctl" --root="$root" disable test2.socket
|
|
|
|
test ! -e "$root/etc/systemd/system/default.target.wants/test2.service"
|
|
|
|
test ! -e "$root/etc/systemd/system/sockets.target.wants/test2.socket"
|
|
|
|
|
|
|
|
|
2022-03-24 18:52:35 +08:00
|
|
|
: '-------link-------------------------------------------------'
|
2022-03-07 19:15:42 +08:00
|
|
|
# File doesn't exist yet
|
|
|
|
test ! -e "$root/link1.path"
|
2022-03-25 22:56:16 +08:00
|
|
|
( ! "$systemctl" --root="$root" link '/link1.path' )
|
2022-03-07 19:15:42 +08:00
|
|
|
test ! -e "$root/etc/systemd/system/link1.path"
|
|
|
|
|
|
|
|
cat >"$root/link1.path" <<EOF
|
|
|
|
[Install]
|
|
|
|
WantedBy=paths.target
|
|
|
|
EOF
|
|
|
|
|
|
|
|
"$systemctl" --root="$root" link '/link1.path'
|
|
|
|
islink "$root/etc/systemd/system/link1.path" "/link1.path"
|
|
|
|
|
2022-03-24 18:52:35 +08:00
|
|
|
: '-------link already linked same path------------------------'
|
2022-03-07 19:15:42 +08:00
|
|
|
SYSTEMD_LOG_LEVEL=debug "$systemctl" --root="$root" link '/link1.path' # this passes
|
|
|
|
islink "$root/etc/systemd/system/link1.path" "/link1.path"
|
|
|
|
|
2022-03-24 18:52:35 +08:00
|
|
|
: '-------link already linked different path-------------------'
|
2022-03-07 19:15:42 +08:00
|
|
|
mkdir "$root/subdir"
|
|
|
|
cp "$root/link1.path" "$root/subdir/"
|
2022-03-25 22:56:16 +08:00
|
|
|
( ! "$systemctl" --root="$root" link '/subdir/link1.path' )
|
2022-03-07 19:15:42 +08:00
|
|
|
islink "$root/etc/systemd/system/link1.path" "/link1.path"
|
|
|
|
|
2022-03-24 18:52:35 +08:00
|
|
|
: '-------link bad suffix--------------------------------------'
|
2022-03-07 19:15:42 +08:00
|
|
|
cp "$root/link1.path" "$root/subdir/link1.suffix"
|
2022-03-25 22:56:16 +08:00
|
|
|
( ! "$systemctl" --root="$root" link '/subdir/link1.suffix' )
|
2022-03-07 19:15:42 +08:00
|
|
|
test ! -e "$root/etc/systemd/system/link1.suffix"
|
|
|
|
|
2022-03-24 18:52:35 +08:00
|
|
|
: '-------unlink by unit name----------------------------------'
|
2022-03-07 19:15:42 +08:00
|
|
|
"$systemctl" --root="$root" disable 'link1.path'
|
|
|
|
test ! -e "$root/etc/systemd/system/link1.path"
|
|
|
|
|
2022-03-24 18:52:35 +08:00
|
|
|
: '-------unlink by path---------------------------------------'
|
2022-03-07 19:15:42 +08:00
|
|
|
"$systemctl" --root="$root" link '/link1.path'
|
|
|
|
test -h "$root/etc/systemd/system/link1.path"
|
|
|
|
"$systemctl" --root="$root" disable '/link1.path'
|
|
|
|
test ! -e "$root/etc/systemd/system/link1.path"
|
|
|
|
|
2022-03-24 18:52:35 +08:00
|
|
|
: '-------unlink by wrong path---------------------------------'
|
2022-03-07 19:15:42 +08:00
|
|
|
"$systemctl" --root="$root" link '/link1.path'
|
|
|
|
test -h "$root/etc/systemd/system/link1.path"
|
|
|
|
"$systemctl" --root="$root" disable '/subdir/link1.path' # we only care about the name
|
|
|
|
test ! -e "$root/etc/systemd/system/link1.path"
|
|
|
|
|
|
|
|
|
2022-03-24 18:52:35 +08:00
|
|
|
: '-------link and enable--------------------------------------'
|
2022-03-07 19:15:42 +08:00
|
|
|
"$systemctl" --root="$root" enable '/link1.path'
|
|
|
|
islink "$root/etc/systemd/system/link1.path" "/link1.path"
|
2022-04-13 04:01:10 +08:00
|
|
|
islink "$root/etc/systemd/system/paths.target.wants/link1.path" "/link1.path"
|
2022-03-07 19:15:42 +08:00
|
|
|
|
2022-03-24 18:52:35 +08:00
|
|
|
: '-------enable already linked same path----------------------'
|
2022-03-07 19:15:42 +08:00
|
|
|
"$systemctl" --root="$root" enable '/link1.path'
|
|
|
|
islink "$root/etc/systemd/system/link1.path" "/link1.path"
|
2022-04-13 04:01:10 +08:00
|
|
|
islink "$root/etc/systemd/system/paths.target.wants/link1.path" "/link1.path"
|
2022-03-07 19:15:42 +08:00
|
|
|
|
2022-03-24 18:52:35 +08:00
|
|
|
: '-------enable already linked different path-----------------'
|
2022-03-25 22:56:16 +08:00
|
|
|
( ! "$systemctl" --root="$root" enable '/subdir/link1.path' )
|
2022-03-11 21:27:46 +08:00
|
|
|
islink "$root/etc/systemd/system/link1.path" "/link1.path"
|
2022-04-13 04:01:10 +08:00
|
|
|
islink "$root/etc/systemd/system/paths.target.wants/link1.path" "/link1.path"
|
2022-03-07 19:15:42 +08:00
|
|
|
|
2022-03-24 18:52:35 +08:00
|
|
|
: '-------enable bad suffix------------------------------------'
|
2022-03-07 19:15:42 +08:00
|
|
|
cp "$root/link1.path" "$root/subdir/link1.suffix"
|
2022-03-25 22:56:16 +08:00
|
|
|
( ! "$systemctl" --root="$root" enable '/subdir/link1.suffix' )
|
2022-03-07 19:15:42 +08:00
|
|
|
test ! -e "$root/etc/systemd/system/link1.suffix"
|
|
|
|
test ! -e "$root/etc/systemd/system/paths.target.wants/link1.suffix"
|
|
|
|
|
2022-03-24 18:52:35 +08:00
|
|
|
: '-------disable by unit name---------------------------------'
|
2022-03-07 19:15:42 +08:00
|
|
|
"$systemctl" --root="$root" disable 'link1.path'
|
|
|
|
test ! -e "$root/etc/systemd/system/link1.path"
|
|
|
|
test ! -e "$root/etc/systemd/system/paths.target.wants/link1.path"
|
|
|
|
|
2022-03-24 18:52:35 +08:00
|
|
|
: '-------disable by path--------------------------------------'
|
2022-03-07 19:15:42 +08:00
|
|
|
"$systemctl" --root="$root" enable '/link1.path'
|
|
|
|
test -h "$root/etc/systemd/system/link1.path"
|
|
|
|
test -h "$root/etc/systemd/system/paths.target.wants/link1.path"
|
|
|
|
"$systemctl" --root="$root" disable '/link1.path'
|
|
|
|
test ! -e "$root/etc/systemd/system/link1.path"
|
|
|
|
test ! -e "$root/etc/systemd/system/paths.target.wants/link1.path"
|
|
|
|
|
|
|
|
|
2022-03-24 18:52:35 +08:00
|
|
|
: '-------link and enable-------------------------------------'
|
2022-03-07 19:15:42 +08:00
|
|
|
"$systemctl" --root="$root" link '/link1.path'
|
|
|
|
islink "$root/etc/systemd/system/link1.path" "/link1.path"
|
|
|
|
test ! -h "$root/etc/systemd/system/paths.target.wants/link1.path"
|
|
|
|
|
|
|
|
"$systemctl" --root="$root" enable 'link1.path'
|
|
|
|
islink "$root/etc/systemd/system/link1.path" "/link1.path"
|
2022-04-13 04:01:10 +08:00
|
|
|
islink "$root/etc/systemd/system/paths.target.wants/link1.path" "/link1.path"
|
2022-03-07 19:15:42 +08:00
|
|
|
|
2022-03-15 16:44:39 +08:00
|
|
|
"$systemctl" --root="$root" reenable 'link1.path'
|
|
|
|
islink "$root/etc/systemd/system/link1.path" "/link1.path"
|
2022-04-13 04:01:10 +08:00
|
|
|
islink "$root/etc/systemd/system/paths.target.wants/link1.path" "/link1.path"
|
2022-03-07 19:15:42 +08:00
|
|
|
|
2022-03-24 18:52:35 +08:00
|
|
|
: '-------manual link------------------------------------------'
|
2022-03-07 19:15:42 +08:00
|
|
|
cat >"$root/link3.suffix" <<EOF
|
|
|
|
[Install]
|
|
|
|
WantedBy=services.target
|
|
|
|
EOF
|
|
|
|
|
2022-03-17 23:02:10 +08:00
|
|
|
# We wouldn't create such a link ourselves, but it should accept it when present.
|
2022-03-07 19:15:42 +08:00
|
|
|
ln -s "/link3.suffix" "$root/etc/systemd/system/link3.service"
|
|
|
|
|
2022-03-17 23:02:10 +08:00
|
|
|
SYSTEMD_LOG_LEVEL=debug SYSTEMD_LOG_LOCATION=1 "$systemctl" --root="$root" enable 'link3.service'
|
|
|
|
islink "$root/etc/systemd/system/link3.service" "/link3.suffix"
|
2022-04-13 04:01:10 +08:00
|
|
|
islink "$root/etc/systemd/system/services.target.wants/link3.service" "/link3.suffix"
|
2022-03-17 23:02:10 +08:00
|
|
|
|
|
|
|
SYSTEMD_LOG_LEVEL=debug SYSTEMD_LOG_LOCATION=1 "$systemctl" --root="$root" disable 'link3.service'
|
|
|
|
test ! -h "$root/etc/systemd/system/link3.service"
|
|
|
|
test ! -h "$root/etc/systemd/system/services.target.wants/link3.service"
|
2022-03-07 19:15:42 +08:00
|
|
|
|
2022-03-24 18:52:35 +08:00
|
|
|
: '-------enable on masked-------------------------------------'
|
2022-03-07 19:15:42 +08:00
|
|
|
ln -s "/dev/null" "$root/etc/systemd/system/masked.service"
|
2022-03-25 22:56:16 +08:00
|
|
|
( ! "$systemctl" --root="$root" enable 'masked.service' )
|
|
|
|
( ! "$systemctl" --root="$root" enable '/etc/systemd/system/masked.service' )
|
2022-03-07 19:15:42 +08:00
|
|
|
|
2022-03-24 18:52:35 +08:00
|
|
|
: '-------enable on masked alias-------------------------------'
|
2022-03-07 19:15:42 +08:00
|
|
|
test -h "$root/etc/systemd/system/masked.service"
|
|
|
|
ln -s "masked.service" "$root/etc/systemd/system/masked-alias.service"
|
2022-03-25 22:56:16 +08:00
|
|
|
( ! "$systemctl" --root="$root" enable 'masked-alias.service' )
|
|
|
|
( ! "$systemctl" --root="$root" enable '/etc/systemd/system/masked-alias.service' )
|
2022-03-07 19:15:42 +08:00
|
|
|
|
2022-03-24 18:52:35 +08:00
|
|
|
: '-------issue 22000: link in subdirectory--------------------'
|
2022-03-07 19:15:42 +08:00
|
|
|
mkdir -p "$root/etc/systemd/system/myown.d"
|
|
|
|
cat >"$root/etc/systemd/system/link5-also.service" <<EOF
|
|
|
|
[Install]
|
|
|
|
WantedBy=services.target
|
|
|
|
Also=link5.service
|
|
|
|
EOF
|
|
|
|
cat >"$root/etc/systemd/system/myown.d/link5.service" <<EOF
|
|
|
|
[Install]
|
|
|
|
WantedBy=services.target
|
|
|
|
Also=link5-also.service
|
|
|
|
EOF
|
|
|
|
|
2022-03-25 22:56:16 +08:00
|
|
|
( ! "$systemctl" --root="$root" enable 'link5.service' )
|
2022-03-07 19:15:42 +08:00
|
|
|
test ! -h "$root/etc/systemd/system/services.target.wants/link5.service"
|
|
|
|
test ! -h "$root/etc/systemd/system/services.target.wants/link5-also.service"
|
|
|
|
|
|
|
|
"$systemctl" --root="$root" enable 'link5-also.service'
|
|
|
|
test ! -h "$root/etc/systemd/system/services.target.wants/link5.service"
|
2022-04-13 04:01:10 +08:00
|
|
|
islink "$root/etc/systemd/system/services.target.wants/link5-also.service" "/etc/systemd/system/link5-also.service"
|
2022-03-07 19:15:42 +08:00
|
|
|
|
2022-03-24 18:52:35 +08:00
|
|
|
: '-------template enablement----------------------------------'
|
2022-03-07 19:15:42 +08:00
|
|
|
cat >"$root/etc/systemd/system/templ1@.service" <<EOF
|
|
|
|
[Install]
|
|
|
|
WantedBy=services.target
|
|
|
|
EOF
|
|
|
|
|
|
|
|
# No instance here — this can't succeed.
|
2022-03-25 22:56:16 +08:00
|
|
|
( ! "$systemctl" --root="$root" enable 'templ1@.service' )
|
2022-03-07 19:15:42 +08:00
|
|
|
test ! -h "$root/etc/systemd/system/services.target.wants/templ1@.service"
|
|
|
|
|
|
|
|
"$systemctl" --root="$root" enable 'templ1@one.service'
|
|
|
|
test ! -h "$root/etc/systemd/system/services.target.wants/templ1@.service"
|
2022-04-13 04:01:10 +08:00
|
|
|
islink "$root/etc/systemd/system/services.target.wants/templ1@one.service" "/etc/systemd/system/templ1@.service"
|
2022-03-07 19:15:42 +08:00
|
|
|
|
|
|
|
"$systemctl" --root="$root" enable 'templ1@two.service'
|
|
|
|
test ! -h "$root/etc/systemd/system/services.target.wants/templ1@.service"
|
2022-04-13 04:01:10 +08:00
|
|
|
islink "$root/etc/systemd/system/services.target.wants/templ1@one.service" "/etc/systemd/system/templ1@.service"
|
|
|
|
islink "$root/etc/systemd/system/services.target.wants/templ1@two.service" "/etc/systemd/system/templ1@.service"
|
2022-03-07 19:15:42 +08:00
|
|
|
|
|
|
|
"$systemctl" --root="$root" disable 'templ1@one.service'
|
|
|
|
test ! -h "$root/etc/systemd/system/services.target.wants/templ1@.service"
|
|
|
|
test ! -h "$root/etc/systemd/system/services.target.wants/templ1@one.service"
|
2022-04-13 04:01:10 +08:00
|
|
|
islink "$root/etc/systemd/system/services.target.wants/templ1@two.service" "/etc/systemd/system/templ1@.service"
|
2022-03-07 19:15:42 +08:00
|
|
|
|
|
|
|
"$systemctl" --root="$root" disable 'templ1@two.service'
|
|
|
|
test ! -h "$root/etc/systemd/system/services.target.wants/templ1@.service"
|
|
|
|
test ! -h "$root/etc/systemd/system/services.target.wants/templ1@one.service"
|
|
|
|
test ! -h "$root/etc/systemd/system/services.target.wants/templ1@two.service"
|
|
|
|
|
2022-03-24 18:52:35 +08:00
|
|
|
: '-------template enablement w/ default instance--------------'
|
2022-03-15 17:13:18 +08:00
|
|
|
cat >"$root/etc/systemd/system/templ1@.service" <<EOF
|
|
|
|
[Install]
|
|
|
|
# check enablement with
|
|
|
|
WantedBy=services.target services.target
|
|
|
|
RequiredBy=other@templ1.target other@%p.target
|
2022-03-07 19:15:42 +08:00
|
|
|
DefaultInstance=333
|
|
|
|
EOF
|
|
|
|
|
|
|
|
"$systemctl" --root="$root" enable 'templ1@.service'
|
|
|
|
test ! -h "$root/etc/systemd/system/services.target.wants/templ1@.service"
|
2022-04-13 04:01:10 +08:00
|
|
|
islink "$root/etc/systemd/system/services.target.wants/templ1@333.service" "/etc/systemd/system/templ1@.service"
|
|
|
|
islink "$root/etc/systemd/system/other@templ1.target.requires/templ1@333.service" "/etc/systemd/system/templ1@.service"
|
2022-03-07 19:15:42 +08:00
|
|
|
|
|
|
|
"$systemctl" --root="$root" enable 'templ1@one.service'
|
|
|
|
test ! -h "$root/etc/systemd/system/services.target.wants/templ1@.service"
|
2022-04-13 04:01:10 +08:00
|
|
|
islink "$root/etc/systemd/system/services.target.wants/templ1@333.service" "/etc/systemd/system/templ1@.service"
|
|
|
|
islink "$root/etc/systemd/system/other@templ1.target.requires/templ1@333.service" "/etc/systemd/system/templ1@.service"
|
|
|
|
islink "$root/etc/systemd/system/services.target.wants/templ1@one.service" "/etc/systemd/system/templ1@.service"
|
|
|
|
islink "$root/etc/systemd/system/other@templ1.target.requires/templ1@one.service" "/etc/systemd/system/templ1@.service"
|
2022-03-07 19:15:42 +08:00
|
|
|
|
|
|
|
"$systemctl" --root="$root" enable 'templ1@two.service'
|
|
|
|
test ! -h "$root/etc/systemd/system/services.target.wants/templ1@.service"
|
2022-04-13 04:01:10 +08:00
|
|
|
islink "$root/etc/systemd/system/services.target.wants/templ1@333.service" "/etc/systemd/system/templ1@.service"
|
|
|
|
islink "$root/etc/systemd/system/other@templ1.target.requires/templ1@333.service" "/etc/systemd/system/templ1@.service"
|
|
|
|
islink "$root/etc/systemd/system/services.target.wants/templ1@one.service" "/etc/systemd/system/templ1@.service"
|
|
|
|
islink "$root/etc/systemd/system/other@templ1.target.requires/templ1@one.service" "/etc/systemd/system/templ1@.service"
|
|
|
|
islink "$root/etc/systemd/system/services.target.wants/templ1@two.service" "/etc/systemd/system/templ1@.service"
|
|
|
|
islink "$root/etc/systemd/system/other@templ1.target.requires/templ1@two.service" "/etc/systemd/system/templ1@.service"
|
2022-03-07 19:15:42 +08:00
|
|
|
|
|
|
|
"$systemctl" --root="$root" disable 'templ1@one.service'
|
|
|
|
test ! -h "$root/etc/systemd/system/services.target.wants/templ1@.service"
|
2022-04-13 04:01:10 +08:00
|
|
|
islink "$root/etc/systemd/system/services.target.wants/templ1@333.service" "/etc/systemd/system/templ1@.service"
|
|
|
|
islink "$root/etc/systemd/system/other@templ1.target.requires/templ1@333.service" "/etc/systemd/system/templ1@.service"
|
2022-03-07 19:15:42 +08:00
|
|
|
test ! -h "$root/etc/systemd/system/services.target.wants/templ1@one.service"
|
2022-03-15 17:13:18 +08:00
|
|
|
test ! -h "$root/etc/systemd/system/other@templ1.target.requires/templ1@one.service"
|
2022-04-13 04:01:10 +08:00
|
|
|
islink "$root/etc/systemd/system/services.target.wants/templ1@two.service" "/etc/systemd/system/templ1@.service"
|
|
|
|
islink "$root/etc/systemd/system/other@templ1.target.requires/templ1@two.service" "/etc/systemd/system/templ1@.service"
|
2022-03-07 19:15:42 +08:00
|
|
|
|
2022-03-15 17:13:18 +08:00
|
|
|
# disable remaining links here
|
2022-03-07 19:15:42 +08:00
|
|
|
"$systemctl" --root="$root" disable 'templ1@.service'
|
|
|
|
test ! -h "$root/etc/systemd/system/services.target.wants/templ1@.service"
|
|
|
|
test ! -h "$root/etc/systemd/system/services.target.wants/templ1@333.service"
|
2022-03-15 17:13:18 +08:00
|
|
|
test ! -h "$root/etc/systemd/system/other@templ1.target.requires/templ1@333.service"
|
2022-03-07 19:15:42 +08:00
|
|
|
test ! -h "$root/etc/systemd/system/services.target.wants/templ1@one.service"
|
2022-03-15 17:13:18 +08:00
|
|
|
test ! -h "$root/etc/systemd/system/other@templ1.target.requires/templ1@one.service"
|
2022-03-07 19:15:42 +08:00
|
|
|
test ! -h "$root/etc/systemd/system/services.target.wants/templ1@two.service"
|
2022-03-15 17:13:18 +08:00
|
|
|
test ! -h "$root/etc/systemd/system/other@templ1.target.requires/templ1@two.service"
|
2022-03-07 19:15:42 +08:00
|
|
|
|
2022-03-24 18:52:35 +08:00
|
|
|
: '-------removal of relative enablement symlinks--------------'
|
2022-03-16 16:51:24 +08:00
|
|
|
test ! -h "$root/etc/systemd/system/services.target.wants/templ1@.service"
|
|
|
|
ln -s '../templ1@one.service' "$root/etc/systemd/system/services.target.wants/templ1@one.service"
|
|
|
|
ln -s 'templ1@two.service' "$root/etc/systemd/system/services.target.wants/templ1@two.service"
|
|
|
|
ln -s '../templ1@.service' "$root/etc/systemd/system/services.target.wants/templ1@three.service"
|
|
|
|
ln -s 'templ1@.service' "$root/etc/systemd/system/services.target.wants/templ1@four.service"
|
|
|
|
ln -s '/usr/lib/systemd/system/templ1@.service' "$root/etc/systemd/system/services.target.wants/templ1@five.service"
|
|
|
|
ln -s '/etc/systemd/system/templ1@.service' "$root/etc/systemd/system/services.target.wants/templ1@six.service"
|
|
|
|
ln -s '/run/system/templ1@.service' "$root/etc/systemd/system/services.target.wants/templ1@seven.service"
|
|
|
|
|
|
|
|
# this should remove all links
|
|
|
|
"$systemctl" --root="$root" disable 'templ1@.service'
|
|
|
|
test ! -h "$root/etc/systemd/system/services.target.wants/templ1@one.service"
|
|
|
|
test ! -h "$root/etc/systemd/system/services.target.wants/templ1@two.service"
|
|
|
|
test ! -h "$root/etc/systemd/system/services.target.wants/templ1@three.service"
|
|
|
|
test ! -h "$root/etc/systemd/system/services.target.wants/templ1@four.service"
|
|
|
|
test ! -h "$root/etc/systemd/system/services.target.wants/templ1@five.service"
|
|
|
|
test ! -h "$root/etc/systemd/system/services.target.wants/templ1@six.service"
|
|
|
|
test ! -h "$root/etc/systemd/system/services.target.wants/templ1@seven.service"
|
|
|
|
|
2022-03-24 18:52:35 +08:00
|
|
|
: '-------template enablement for another template-------------'
|
2022-03-11 04:33:25 +08:00
|
|
|
cat >"$root/etc/systemd/system/templ2@.service" <<EOF
|
|
|
|
[Install]
|
|
|
|
RequiredBy=another-template@.target
|
|
|
|
EOF
|
|
|
|
|
|
|
|
"$systemctl" --root="$root" enable 'templ2@.service'
|
2022-04-13 04:01:10 +08:00
|
|
|
islink "$root/etc/systemd/system/another-template@.target.requires/templ2@.service" "/etc/systemd/system/templ2@.service"
|
2022-03-11 04:33:25 +08:00
|
|
|
|
|
|
|
"$systemctl" --root="$root" enable 'templ2@two.service'
|
2022-04-13 04:01:10 +08:00
|
|
|
islink "$root/etc/systemd/system/another-template@.target.requires/templ2@.service" "/etc/systemd/system/templ2@.service"
|
|
|
|
islink "$root/etc/systemd/system/another-template@.target.requires/templ2@two.service" "/etc/systemd/system/templ2@.service"
|
2022-03-11 04:33:25 +08:00
|
|
|
|
|
|
|
"$systemctl" --root="$root" disable 'templ2@other.service'
|
2022-04-13 04:01:10 +08:00
|
|
|
islink "$root/etc/systemd/system/another-template@.target.requires/templ2@.service" "/etc/systemd/system/templ2@.service"
|
|
|
|
islink "$root/etc/systemd/system/another-template@.target.requires/templ2@two.service" "/etc/systemd/system/templ2@.service"
|
2022-03-11 04:33:25 +08:00
|
|
|
|
|
|
|
"$systemctl" --root="$root" disable 'templ2@two.service'
|
2022-04-13 04:01:10 +08:00
|
|
|
islink "$root/etc/systemd/system/another-template@.target.requires/templ2@.service" "/etc/systemd/system/templ2@.service"
|
2022-03-11 04:33:25 +08:00
|
|
|
test ! -h "$root/etc/systemd/system/another-template@.target.requires/templ2@two.service"
|
|
|
|
|
|
|
|
"$systemctl" --root="$root" disable 'templ2@.service'
|
|
|
|
test ! -h "$root/etc/systemd/system/another-template@.target.requires/templ2@.service"
|
|
|
|
test ! -h "$root/etc/systemd/system/another-template@.target.requires/templ2@two.service"
|
|
|
|
|
2022-03-24 18:52:35 +08:00
|
|
|
: '-------aliases w/ and w/o instance--------------------------'
|
2022-03-07 19:15:42 +08:00
|
|
|
test ! -e "$root/etc/systemd/system/link4.service"
|
|
|
|
cat >"$root/etc/systemd/system/link4.service" <<EOF
|
|
|
|
[Install]
|
2022-03-11 03:26:59 +08:00
|
|
|
Alias=link4.service
|
2022-03-07 19:15:42 +08:00
|
|
|
Alias=link4@.service
|
|
|
|
Alias=link4@inst.service
|
|
|
|
Alias=link4alias.service
|
|
|
|
Alias=link4alias2.service
|
|
|
|
EOF
|
|
|
|
|
2022-03-25 22:56:16 +08:00
|
|
|
( ! "$systemctl" --root="$root" enable 'link4.service' )
|
2022-03-07 19:15:42 +08:00
|
|
|
test ! -h "$root/etc/systemd/system/link4.service" # this is our file
|
|
|
|
test ! -h "$root/etc/systemd/system/link4@.service"
|
|
|
|
test ! -h "$root/etc/systemd/system/link4@inst.service"
|
2022-04-13 04:01:10 +08:00
|
|
|
islink "$root/etc/systemd/system/link4alias.service" "/etc/systemd/system/link4.service"
|
|
|
|
islink "$root/etc/systemd/system/link4alias2.service" "/etc/systemd/system/link4.service"
|
2022-03-07 19:15:42 +08:00
|
|
|
|
|
|
|
"$systemctl" --root="$root" disable 'link4.service'
|
|
|
|
test ! -h "$root/etc/systemd/system/link4.service"
|
|
|
|
test ! -h "$root/etc/systemd/system/link4@.service"
|
|
|
|
test ! -h "$root/etc/systemd/system/link4@inst.service"
|
|
|
|
test ! -h "$root/etc/systemd/system/link4alias.service"
|
|
|
|
test ! -h "$root/etc/systemd/system/link4alias2.service"
|
|
|
|
|
2022-03-24 18:52:35 +08:00
|
|
|
: '-------systemctl enable on path to unit file----------------'
|
shared/install: return failure when enablement fails, but process as much as possible
So far we'd issue a warning (before this series, just in the logs on the server
side, and before this commit, on stderr on the caller's side), but return
success. It seems that successfull return was introduced by mistake in
aa0f357fd833feecbea6c3e9be80b643e433bced (my fault :( ), which was supposed to
be a refactoring without a functional change. I think it's better to fail,
because if enablement fails, the user will most likely want to diagnose the
issue.
Note that we still do partial enablement, as far as that is possible. So if
e.g. we have [Install] Alias=foo.service foobar, we'll create the symlink
'foo.service', but not 'foobar', since that's not a valid unit name. We'll
print info about the action taken, and about 'foobar' being invalid, and return
failure.
2022-03-10 22:47:12 +08:00
|
|
|
cat >"$root/etc/systemd/system/link4.service" <<EOF
|
|
|
|
[Install]
|
|
|
|
Alias=link4alias.service
|
|
|
|
Alias=link4alias2.service
|
|
|
|
EOF
|
|
|
|
|
2022-03-07 19:15:42 +08:00
|
|
|
# Apparently this works. I'm not sure what to think.
|
|
|
|
"$systemctl" --root="$root" enable '/etc/systemd/system/link4.service'
|
|
|
|
test ! -h "$root/etc/systemd/system/link4.service" # this is our file
|
2022-04-13 04:01:10 +08:00
|
|
|
islink "$root/etc/systemd/system/link4alias.service" "/etc/systemd/system/link4.service"
|
|
|
|
islink "$root/etc/systemd/system/link4alias2.service" "/etc/systemd/system/link4.service"
|
2022-03-07 19:15:42 +08:00
|
|
|
|
|
|
|
"$systemctl" --root="$root" disable '/etc/systemd/system/link4.service'
|
|
|
|
test ! -h "$root/etc/systemd/system/link4.service"
|
|
|
|
test ! -h "$root/etc/systemd/system/link4alias.service"
|
|
|
|
test ! -h "$root/etc/systemd/system/link4alias2.service"
|
|
|
|
|
2022-03-24 18:52:35 +08:00
|
|
|
: '-------issue 661: enable on unit file--------------'
|
2022-03-07 19:15:42 +08:00
|
|
|
test ! -e "$root/etc/systemd/system/link5.service"
|
|
|
|
cat >"$root/etc/systemd/system/link5.service" <<EOF
|
|
|
|
[Install]
|
2022-03-11 03:26:59 +08:00
|
|
|
Alias=link5.service
|
2022-03-07 19:15:42 +08:00
|
|
|
Alias=link5alias.service
|
|
|
|
Alias=link5alias2.service
|
|
|
|
EOF
|
|
|
|
|
|
|
|
"$systemctl" --root="$root" enable 'link5.service'
|
|
|
|
test ! -h "$root/etc/systemd/system/link5.service" # this is our file
|
2022-04-13 04:01:10 +08:00
|
|
|
islink "$root/etc/systemd/system/link5alias.service" "/etc/systemd/system/link5.service"
|
|
|
|
islink "$root/etc/systemd/system/link5alias2.service" "/etc/systemd/system/link5.service"
|
2022-03-07 19:15:42 +08:00
|
|
|
|
|
|
|
"$systemctl" --root="$root" disable 'link5.service'
|
|
|
|
test ! -h "$root/etc/systemd/system/link5alias.service"
|
|
|
|
test ! -h "$root/etc/systemd/system/link5alias2.service"
|
|
|
|
|
2022-03-24 18:52:35 +08:00
|
|
|
: '-------issue 661: link and enable on unit file--------------'
|
2022-03-16 00:45:34 +08:00
|
|
|
test ! -e "$root/etc/systemd/system/link5copy.service"
|
|
|
|
cat >"$root/link5copy.service" <<EOF
|
|
|
|
[Install]
|
|
|
|
Alias=link5copy.service
|
|
|
|
Alias=link5alias.service
|
|
|
|
Alias=link5alias2.service
|
|
|
|
EOF
|
|
|
|
|
|
|
|
test ! -e "$root/etc/systemd/system/link5copy.service"
|
|
|
|
|
|
|
|
"$systemctl" --root="$root" link '/link5copy.service'
|
|
|
|
islink "$root/etc/systemd/system/link5copy.service" '/link5copy.service'
|
|
|
|
test ! -h "$root/etc/systemd/system/link5alias.service"
|
|
|
|
test ! -h "$root/etc/systemd/system/link5alias2.service"
|
|
|
|
|
2022-04-13 04:01:10 +08:00
|
|
|
# FIXME: we must create link5alias2 and link5alias as relative links to link5.service
|
|
|
|
# When they are independent links to /link5.service, systemd doesn't know that
|
|
|
|
# they are aliases, because we do not follow symlinks outside of the search paths.
|
|
|
|
|
2022-03-16 00:45:34 +08:00
|
|
|
"$systemctl" --root="$root" disable 'link5copy.service'
|
|
|
|
test ! -h "$root/etc/systemd/system/link5copy.service"
|
|
|
|
test ! -h "$root/etc/systemd/system/link5alias.service"
|
|
|
|
test ! -h "$root/etc/systemd/system/link5alias2.service"
|
|
|
|
|
|
|
|
"$systemctl" --root="$root" enable '/link5copy.service'
|
|
|
|
islink "$root/etc/systemd/system/link5copy.service" '/link5copy.service'
|
2022-04-13 04:01:10 +08:00
|
|
|
islink "$root/etc/systemd/system/link5alias.service" '/link5copy.service'
|
|
|
|
islink "$root/etc/systemd/system/link5alias2.service" '/link5copy.service'
|
2022-03-16 00:45:34 +08:00
|
|
|
|
|
|
|
"$systemctl" --root="$root" disable 'link5copy.service'
|
|
|
|
test ! -h "$root/etc/systemd/system/link5copy.service"
|
|
|
|
test ! -h "$root/etc/systemd/system/link5alias.service"
|
|
|
|
test ! -h "$root/etc/systemd/system/link5alias2.service"
|
|
|
|
|
2022-03-24 18:52:35 +08:00
|
|
|
: '----issue 19437: plain templates in .wants/ or .requires/---'
|
2022-03-07 19:15:42 +08:00
|
|
|
test ! -e "$root/etc/systemd/system/link5@.path"
|
|
|
|
cat >"$root/etc/systemd/system/link5@.path" <<EOF
|
|
|
|
[Install]
|
|
|
|
WantedBy=target5@.target
|
|
|
|
RequiredBy=target5@.target
|
|
|
|
WantedBy=target5@inst.target
|
|
|
|
RequiredBy=target5@inst.target
|
|
|
|
EOF
|
|
|
|
|
|
|
|
"$systemctl" --root="$root" enable 'link5@.path'
|
|
|
|
test ! -h "$root/etc/systemd/system/link5@.path" # this is our file
|
2022-04-13 04:01:10 +08:00
|
|
|
islink "$root/etc/systemd/system/target5@.target.wants/link5@.path" "/etc/systemd/system/link5@.path"
|
|
|
|
islink "$root/etc/systemd/system/target5@.target.requires/link5@.path" "/etc/systemd/system/link5@.path"
|
|
|
|
islink "$root/etc/systemd/system/target5@inst.target.wants/link5@.path" "/etc/systemd/system/link5@.path"
|
|
|
|
islink "$root/etc/systemd/system/target5@inst.target.requires/link5@.path" "/etc/systemd/system/link5@.path"
|
2022-03-07 19:15:42 +08:00
|
|
|
|
|
|
|
"$systemctl" --root="$root" disable 'link5@.path'
|
|
|
|
test ! -h "$root/etc/systemd/system/link5@.path" # this is our file
|
|
|
|
test ! -h "$root/etc/systemd/system/target5@.target.wants/link5@.path"
|
|
|
|
test ! -h "$root/etc/systemd/system/target5@.target.requires/link5@.path"
|
|
|
|
test ! -h "$root/etc/systemd/system/target5@inst.target.wants/link5@.path"
|
|
|
|
test ! -h "$root/etc/systemd/system/target5@inst.target.requires/link5@.path"
|
|
|
|
|
2022-03-24 18:52:35 +08:00
|
|
|
: '-------removal of symlinks not listed in [Install]----------'
|
2022-03-07 19:15:42 +08:00
|
|
|
# c.f. 66a19d85a533b15ed32f4066ec880b5a8c06babd
|
|
|
|
test ! -e "$root/etc/systemd/system/multilink.mount"
|
|
|
|
cat >"$root/etc/systemd/system/multilink.mount" <<EOF
|
|
|
|
[Install]
|
|
|
|
WantedBy=multilink.target
|
|
|
|
EOF
|
|
|
|
|
|
|
|
mkdir -p "$root/etc/systemd/system/default.target.wants"
|
|
|
|
ln -s ../multilink.mount "$root/etc/systemd/system/default.target.wants/"
|
|
|
|
ln -s ../multilink.mount "$root/etc/systemd/system/multilink-alias.mount"
|
|
|
|
ln -s ../multilink.mount "$root/etc/systemd/system/multilink-badalias.service"
|
|
|
|
|
|
|
|
"$systemctl" --root="$root" disable 'multilink.mount'
|
|
|
|
test -e "$root/etc/systemd/system/multilink.mount" # this is our file
|
|
|
|
test ! -h "$root/etc/systemd/system/default.target.wants/"
|
|
|
|
test ! -h "$root/etc/systemd/system/multilink-alias.mount"
|
|
|
|
test ! -h "$root/etc/systemd/system/multilink-badalias.service"
|
|
|
|
|
2022-03-24 18:52:35 +08:00
|
|
|
: '-------merge 20017: specifiers in the unit file-------------'
|
2022-03-07 19:15:42 +08:00
|
|
|
test ! -e "$root/etc/systemd/system/some-some-link6@.socket"
|
|
|
|
# c.f. de61a04b188f81a85cdb5c64ddb4987dcd9d30d3
|
|
|
|
|
|
|
|
check_alias() {
|
2022-03-24 18:52:35 +08:00
|
|
|
: "------------------ %$1 -------------------------------------"
|
2022-03-07 19:15:42 +08:00
|
|
|
cat >"$root/etc/systemd/system/some-some-link6@.socket" <<EOF
|
|
|
|
[Install]
|
|
|
|
Alias=target@$1:%$1.socket
|
|
|
|
EOF
|
|
|
|
SYSTEMD_LOG_LEVEL=debug "$systemctl" --root="$root" enable 'some-some-link6@.socket' || return 1
|
2022-04-13 04:01:10 +08:00
|
|
|
islink "$root/etc/systemd/system/target@$1:$2.socket" "/etc/systemd/system/some-some-link6@.socket" || return 2
|
2022-03-07 19:15:42 +08:00
|
|
|
}
|
|
|
|
|
2022-03-29 02:20:09 +08:00
|
|
|
# TODO: our architecture names are different than what uname -m returns.
|
|
|
|
# Add something like 'systemd-detect-virt --print-architecture' and use it here.
|
|
|
|
check_alias a "$(uname -m | tr '_' '-')" || :
|
2022-03-07 19:15:42 +08:00
|
|
|
|
2022-03-08 19:08:00 +08:00
|
|
|
test ! -e "$root/etc/os-release"
|
|
|
|
test ! -e "$root/usr/lib/os-release"
|
|
|
|
|
2022-03-25 22:56:16 +08:00
|
|
|
( ! check_alias A '' )
|
|
|
|
( ! check_alias B '' )
|
|
|
|
( ! check_alias M '' )
|
|
|
|
( ! check_alias o '' )
|
|
|
|
( ! check_alias w '' )
|
|
|
|
( ! check_alias W '' )
|
2022-03-08 19:08:00 +08:00
|
|
|
|
|
|
|
cat >"$root/etc/os-release" <<EOF
|
|
|
|
# empty
|
|
|
|
EOF
|
2022-03-07 19:15:42 +08:00
|
|
|
|
2022-03-08 19:08:00 +08:00
|
|
|
check_alias A ''
|
|
|
|
check_alias B ''
|
|
|
|
check_alias M ''
|
|
|
|
check_alias o ''
|
|
|
|
check_alias w ''
|
|
|
|
check_alias W ''
|
|
|
|
|
|
|
|
cat >"$root/etc/os-release" <<EOF
|
|
|
|
ID='the-id'
|
|
|
|
VERSION_ID=39a
|
|
|
|
BUILD_ID=build-id
|
|
|
|
VARIANT_ID=wrong
|
|
|
|
VARIANT_ID=right
|
|
|
|
IMAGE_ID="foobar"
|
|
|
|
IMAGE_VERSION='1-2-3'
|
|
|
|
EOF
|
2022-03-07 19:15:42 +08:00
|
|
|
|
2022-03-08 19:08:00 +08:00
|
|
|
check_alias A '1-2-3'
|
|
|
|
check_alias B 'build-id'
|
|
|
|
check_alias M 'foobar'
|
|
|
|
check_alias o 'the-id'
|
|
|
|
check_alias w '39a'
|
|
|
|
check_alias W 'right'
|
|
|
|
|
2022-03-29 02:03:37 +08:00
|
|
|
check_alias b "$("$systemd_id128" boot-id)"
|
2022-03-07 19:15:42 +08:00
|
|
|
|
2022-03-09 23:06:24 +08:00
|
|
|
# Specifiers not available for [Install]
|
2022-03-25 22:56:16 +08:00
|
|
|
( ! check_alias C '' )
|
|
|
|
( ! check_alias E '' )
|
|
|
|
( ! check_alias f '' )
|
|
|
|
( ! check_alias h '' )
|
|
|
|
( ! check_alias I '' )
|
|
|
|
( ! check_alias J '' )
|
|
|
|
( ! check_alias L '' )
|
|
|
|
( ! check_alias P '' )
|
|
|
|
( ! check_alias s '' )
|
|
|
|
( ! check_alias S '' )
|
|
|
|
( ! check_alias t '' )
|
|
|
|
( ! check_alias T '' )
|
|
|
|
( ! check_alias V '' )
|
2022-03-07 19:15:42 +08:00
|
|
|
|
shared/specifier: fix %u/%U/%g/%G when called as unprivileged user
We would resolve those specifiers to the calling user/group. This is mostly OK
when done in the manager, because the manager generally operates as root
in system mode, and a non-root in user mode. It would still be wrong if
called with --test though. But in systemctl, this would be generally wrong,
since we can call 'systemctl --system' as a normal user, either for testing
or even for actual operation with '--root=…'.
When operating in --global mode, %u/%U/%g/%G should return an error.
The information whether we're operating in system mode, user mode, or global
mode is passed as the data pointer to specifier_group_name(), specifier_user_name(),
specifier_group_id(), specifier_user_id(). We can't use userdata, because
it's already used for other things.
2022-03-10 05:29:19 +08:00
|
|
|
check_alias g root
|
|
|
|
check_alias G 0
|
|
|
|
check_alias u root
|
|
|
|
check_alias U 0
|
2022-03-07 19:15:42 +08:00
|
|
|
|
|
|
|
check_alias i ""
|
|
|
|
|
|
|
|
check_alias j 'link6'
|
|
|
|
|
|
|
|
check_alias l "$(uname -n | sed 's/\..*//')"
|
|
|
|
|
2022-03-08 19:08:00 +08:00
|
|
|
test ! -e "$root/etc/machine-id"
|
2022-03-25 22:56:16 +08:00
|
|
|
( ! check_alias m '' )
|
2022-03-07 19:15:42 +08:00
|
|
|
|
2022-03-29 02:03:37 +08:00
|
|
|
"$systemd_id128" new >"$root/etc/machine-id"
|
2022-03-08 19:08:00 +08:00
|
|
|
check_alias m "$(cat "$root/etc/machine-id")"
|
2022-03-07 19:15:42 +08:00
|
|
|
|
|
|
|
check_alias n 'some-some-link6@.socket'
|
|
|
|
check_alias N 'some-some-link6@'
|
|
|
|
|
|
|
|
check_alias p 'some-some-link6'
|
|
|
|
|
2022-03-30 04:39:08 +08:00
|
|
|
uname -r | grep -q '[^a-zA-Z0-9_.\\-]' || \
|
|
|
|
check_alias v "$(uname -r)"
|
2022-03-07 19:15:42 +08:00
|
|
|
|
2022-03-25 22:56:16 +08:00
|
|
|
# % is not legal in unit name
|
|
|
|
( ! check_alias % '%' )
|
2022-03-07 19:15:42 +08:00
|
|
|
|
2022-03-25 22:56:16 +08:00
|
|
|
# %z is not defined
|
|
|
|
( ! check_alias z 'z' )
|
2022-03-07 19:15:42 +08:00
|
|
|
|
2022-03-24 18:52:35 +08:00
|
|
|
: '-------specifiers in WantedBy-------------------------------'
|
2022-03-11 04:33:25 +08:00
|
|
|
# We don't need to repeat all the tests. Let's do a basic check that specifier
|
|
|
|
# expansion is performed.
|
|
|
|
|
|
|
|
cat >"$root/etc/systemd/system/some-some-link7.socket" <<EOF
|
|
|
|
[Install]
|
|
|
|
WantedBy=target@%p.target
|
|
|
|
WantedBy=another-target@.target
|
|
|
|
RequiredBy=target2@%p.target
|
|
|
|
RequiredBy=another-target2@.target
|
|
|
|
EOF
|
|
|
|
|
|
|
|
"$systemctl" --root="$root" enable 'some-some-link7.socket'
|
2022-04-13 04:01:10 +08:00
|
|
|
islink "$root/etc/systemd/system/target@some-some-link7.target.wants/some-some-link7.socket" "/etc/systemd/system/some-some-link7.socket"
|
|
|
|
islink "$root/etc/systemd/system/another-target@.target.wants/some-some-link7.socket" "/etc/systemd/system/some-some-link7.socket"
|
|
|
|
islink "$root/etc/systemd/system/target2@some-some-link7.target.requires/some-some-link7.socket" "/etc/systemd/system/some-some-link7.socket"
|
|
|
|
islink "$root/etc/systemd/system/another-target2@.target.requires/some-some-link7.socket" "/etc/systemd/system/some-some-link7.socket"
|
2022-03-11 04:33:25 +08:00
|
|
|
|
|
|
|
"$systemctl" --root="$root" disable 'some-some-link7.socket'
|
|
|
|
test ! -h "$root/etc/systemd/system/target@some-some-link7.target.wants/some-some-link7.socket"
|
|
|
|
test ! -h "$root/etc/systemd/system/another-target@.target.wants/some-some-link7.socket"
|
|
|
|
test ! -h "$root/etc/systemd/system/target2@some-some-link7.target.requires/some-some-link7.socket"
|
|
|
|
test ! -h "$root/etc/systemd/system/another-target2@.target.requires/some-some-link7.socket"
|
|
|
|
|
2022-03-07 19:15:42 +08:00
|
|
|
# TODO: repeat the tests above for presets
|
2022-03-08 01:54:50 +08:00
|
|
|
|
2022-03-24 18:52:35 +08:00
|
|
|
: '-------SYSTEMD_OS_RELEASE relative to root-------------------'
|
2022-03-08 01:54:50 +08:00
|
|
|
# check that os-release overwriting works as expected with root
|
|
|
|
test -e "$root/etc/os-release"
|
|
|
|
|
|
|
|
cat >"$root/etc/os-release2" <<EOF
|
|
|
|
ID='the-id2'
|
|
|
|
EOF
|
|
|
|
|
|
|
|
SYSTEMD_OS_RELEASE="$root/etc/os-release2" check_alias o 'the-id2'
|