]> code.ossystems Code Review - openembedded-core.git/commitdiff
systemd-systemctl: add handling of template unit files
authorTomas Novotny <tomas@novotny.cz>
Fri, 12 Dec 2014 15:50:51 +0000 (16:50 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Fri, 19 Dec 2014 17:54:14 +0000 (17:54 +0000)
Template unit files (those with '@' in their names) are not handled with
native version of systemctl. This is usually not a problem, as the
native systemctl fails and systemctl command is executed during first
boot. But some early boot template units may fail during first boot
because opkg configure for first boot is pulled too late for them
(although I encouter it only with some of my services, not with oe-core
ones).

Handling of template unit files is same as in original systemctl. Also
DefaultInstance directive in template is respected. As with original
systemctl, enabling of template without instance and DefaultInstance
does nothing.

Signed-off-by: Tomas Novotny <tomas@novotny.cz>
Signed-off-by: Ross Burton <ross.burton@intel.com>
meta/recipes-core/systemd/systemd-systemctl/systemctl

index b37f27abfb25173101d2fbdadd6805cc6d62375b..2e632b00bc3e4e7b57952f996a3112e8b019ea72 100755 (executable)
@@ -77,18 +77,31 @@ for service in $services; do
                exit 0
        fi
 
-       echo "Try to find location of $service..."
+       service_base_file=`echo $service | sed 's/\(@\).*\(\.[^.]\+\)/\1\2/'`
+       if [ -z `echo $service | sed '/@/p;d'` ]; then
+               echo "Try to find location of $service..."
+               service_template=false
+       else
+               echo "Try to find location of template $service_base_file of instance $service..."
+               service_template=true
+               if [ -z `echo $service | sed 's/^.\+@\(.*\)\.[^.]\+/\1/'` ]; then
+                       instance_specified=false
+               else
+                       instance_specified=true
+               fi
+       fi
+
        # 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
+               if [ -e $p/$service_base_file ]; then
+                       service_file=$p/$service_base_file
                        service_file=${service_file##$ROOT}
                fi
        done
        if [ -z "$service_file" ]; then
-               echo "'$service' couldn't be found; exiting with error"
+               echo "'$service_base_file' couldn't be found; exiting with error"
                exit 1
        fi
        echo "Found $service in $service_file"
@@ -115,13 +128,29 @@ for service in $services; do
        for r in $wanted_by; do
                echo "WantedBy=$r found in $service"
                if [ "$action" = "enable" ]; then
+                       enable_service=$service
+                       if [ "$service_template" = true -a "$instance_specified" = false ]; then
+                               default_instance=$(sed '/^DefaultInstance[[:space:]]*=/s,[^=]*=,,p;d' "$ROOT/$service_file")
+                               if [ -z $default_instance ]; then
+                                       echo "Template unit without instance or DefaultInstance directive, nothing to enable"
+                                       continue
+                               else
+                                       echo "Found DefaultInstance $default_instance, enabling it"
+                                       enable_service=$(echo $service | sed "s/@/@$default_instance/")
+                               fi
+                       fi
                        mkdir -p $ROOT/etc/systemd/system/$r.wants
-                       ln -s $service_file $ROOT/etc/systemd/system/$r.wants
-                       echo "Enabled $service for $wanted_by."
+                       ln -s $service_file $ROOT/etc/systemd/system/$r.wants/$enable_service
+                       echo "Enabled $enable_service for $wanted_by."
                else
-                       rm -f $ROOT/etc/systemd/system/$r.wants/$service
+                       if [ "$service_template" = true -a "$instance_specified" = false ]; then
+                               disable_service="$ROOT/etc/systemd/system/$r.wants/`echo $service | sed 's/@/@*/'`"
+                       else
+                               disable_service="$ROOT/etc/systemd/system/$r.wants/$service"
+                       fi
+                       rm -f $disable_service
                        rmdir --ignore-fail-on-non-empty -p $ROOT/etc/systemd/system/$r.wants
-                       echo "Disabled $service for $wanted_by."
+                       echo "Disabled ${disable_service##$ROOT/etc/systemd/system/$r.wants/} for $wanted_by."
                fi
        done