mirror of
https://git.yoctoproject.org/poky
synced 2026-02-24 02:19:39 +01:00
The Alias and WantedBy directives can accept all valid unit types when using the systemctl from systemd. And since the systemctl script should match the behavior of systemd as much as possible, add the current set of unit types listed at http://www.freedesktop.org/software/systemd/man/systemd.unit.html to the Alias and WantedBy directives. The deficiency was exposed when trying to use: Alias=default.target in a foo.target. No symlink was created by running "systemctl enable foo.target" during the package's postinst. (From OE-Core rev: 374b9c37b3310cf2a3373633197ca7ba21f6d1bd) Signed-off-by: Randy Witt <rewitt@declaratino.com> Signed-off-by: Saul Wold <sgw@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2.8 KiB
Executable File
2.8 KiB
Executable File
#!/bin/sh echo "Started $0 $*"
ROOT=
parse command line params
action= while [ $# != 0 ]; do opt="$1"
case "$opt" in
enable)
shift
action="$opt"
services="$1"
cmd_args="1"
shift
;;
disable)
shift
action="$opt"
services="$1"
cmd_args="1"
shift
;;
mask)
shift
action="$opt"
services="$1"
cmd_args="1"
shift
;;
--root=*)
ROOT=${opt##--root=}
cmd_args="0"
shift
;;
*)
if [ "$cmd_args" = "1" ]; then
services="$services $opt"
shift
else
echo "'$opt' is an unkown option; exiting with error"
exit 1
fi
;;
esac
done
for service in $services; do if [ "$action" = "mask" ]; then if [ ! -d $ROOT/etc/systemd/system/ ]; then mkdir -p $ROOT/etc/systemd/system/ fi cmd="ln -s /dev/null $ROOT/etc/systemd/system/$service" echo "$cmd" $cmd exit 0 fi
echo "Try to find location of $service..."
# find service file
for p in $ROOT/etc/systemd/system \
$ROOT/lib/systemd/system \
$ROOT/usr/lib/systemd/system; do
if [ -e $p/$service ]; then
service_file=$p/$service
service_file=${service_file##$ROOT}
fi
done
if [ -z "$service_file" ]; then
echo "'$service' couldn't be found; exiting with error"
exit 1
fi
echo "Found $service in $service_file"
# If any new unit types are added to systemd they should be added
# to this regular expression.
unit_types_re='\.\(service\|socket\|device\|mount\|automount\|swap\|target\|path\|timer\|snapshot\)$'
# create the required symbolic links
wanted_by=$(sed '/^WantedBy[[:space:]]*=/s,[^=]*=,,p;d' "$ROOT/$service_file" \
| tr ',' '\n' \
| grep "$unit_types_re")
for r in $wanted_by; do
echo "WantedBy=$r found in $service"
if [ "$action" = "enable" ]; then
mkdir -p $ROOT/etc/systemd/system/$r.wants
ln -s $service_file $ROOT/etc/systemd/system/$r.wants
echo "Enabled $service for $wanted_by."
else
rm -f $ROOT/etc/systemd/system/$r.wants/$service
rmdir --ignore-fail-on-non-empty -p $ROOT/etc/systemd/system/$r.wants
echo "Disabled $service for $wanted_by."
fi
done
# create the required symbolic 'Alias' links
alias=$(sed '/^Alias[[:space:]]*=/s,[^=]*=,,p;d' "$ROOT/$service_file" \
| tr ',' '\n' \
| grep "$unit_types_re")
for r in $alias; do
if [ "$action" = "enable" ]; then
mkdir -p $ROOT/etc/systemd/system
ln -s $service_file $ROOT/etc/systemd/system/$r
echo "Enabled $service for $alias."
else
rm -f $ROOT/etc/systemd/system/$r
echo "Disabled $service for $alias."
fi
done
# call us for the other required scripts
also=$(sed '/^Also[[:space:]]*=/s,[^=]*=,,p;d' "$ROOT/$service_file" \
| tr ',' '\n')
for a in $also; do
echo "Also=$a found in $service"
if [ "$action" = "enable" ]; then
$0 --root=$ROOT enable $a
fi
done
done