diff options
| -rwxr-xr-x | meta/recipes-core/systemd/systemd-systemctl/systemctl | 45 |
1 files changed, 37 insertions, 8 deletions
diff --git a/meta/recipes-core/systemd/systemd-systemctl/systemctl b/meta/recipes-core/systemd/systemd-systemctl/systemctl index b37f27abfb..2e632b00bc 100755 --- a/meta/recipes-core/systemd/systemd-systemctl/systemctl +++ b/meta/recipes-core/systemd/systemd-systemctl/systemctl | |||
| @@ -77,18 +77,31 @@ for service in $services; do | |||
| 77 | exit 0 | 77 | exit 0 |
| 78 | fi | 78 | fi |
| 79 | 79 | ||
| 80 | echo "Try to find location of $service..." | 80 | service_base_file=`echo $service | sed 's/\(@\).*\(\.[^.]\+\)/\1\2/'` |
| 81 | if [ -z `echo $service | sed '/@/p;d'` ]; then | ||
| 82 | echo "Try to find location of $service..." | ||
| 83 | service_template=false | ||
| 84 | else | ||
| 85 | echo "Try to find location of template $service_base_file of instance $service..." | ||
| 86 | service_template=true | ||
| 87 | if [ -z `echo $service | sed 's/^.\+@\(.*\)\.[^.]\+/\1/'` ]; then | ||
| 88 | instance_specified=false | ||
| 89 | else | ||
| 90 | instance_specified=true | ||
| 91 | fi | ||
| 92 | fi | ||
| 93 | |||
| 81 | # find service file | 94 | # find service file |
| 82 | for p in $ROOT/etc/systemd/system \ | 95 | for p in $ROOT/etc/systemd/system \ |
| 83 | $ROOT/lib/systemd/system \ | 96 | $ROOT/lib/systemd/system \ |
| 84 | $ROOT/usr/lib/systemd/system; do | 97 | $ROOT/usr/lib/systemd/system; do |
| 85 | if [ -e $p/$service ]; then | 98 | if [ -e $p/$service_base_file ]; then |
| 86 | service_file=$p/$service | 99 | service_file=$p/$service_base_file |
| 87 | service_file=${service_file##$ROOT} | 100 | service_file=${service_file##$ROOT} |
| 88 | fi | 101 | fi |
| 89 | done | 102 | done |
| 90 | if [ -z "$service_file" ]; then | 103 | if [ -z "$service_file" ]; then |
| 91 | echo "'$service' couldn't be found; exiting with error" | 104 | echo "'$service_base_file' couldn't be found; exiting with error" |
| 92 | exit 1 | 105 | exit 1 |
| 93 | fi | 106 | fi |
| 94 | echo "Found $service in $service_file" | 107 | echo "Found $service in $service_file" |
| @@ -115,13 +128,29 @@ for service in $services; do | |||
| 115 | for r in $wanted_by; do | 128 | for r in $wanted_by; do |
| 116 | echo "WantedBy=$r found in $service" | 129 | echo "WantedBy=$r found in $service" |
| 117 | if [ "$action" = "enable" ]; then | 130 | if [ "$action" = "enable" ]; then |
| 131 | enable_service=$service | ||
| 132 | if [ "$service_template" = true -a "$instance_specified" = false ]; then | ||
| 133 | default_instance=$(sed '/^DefaultInstance[[:space:]]*=/s,[^=]*=,,p;d' "$ROOT/$service_file") | ||
| 134 | if [ -z $default_instance ]; then | ||
| 135 | echo "Template unit without instance or DefaultInstance directive, nothing to enable" | ||
| 136 | continue | ||
| 137 | else | ||
| 138 | echo "Found DefaultInstance $default_instance, enabling it" | ||
| 139 | enable_service=$(echo $service | sed "s/@/@$default_instance/") | ||
| 140 | fi | ||
| 141 | fi | ||
| 118 | mkdir -p $ROOT/etc/systemd/system/$r.wants | 142 | mkdir -p $ROOT/etc/systemd/system/$r.wants |
| 119 | ln -s $service_file $ROOT/etc/systemd/system/$r.wants | 143 | ln -s $service_file $ROOT/etc/systemd/system/$r.wants/$enable_service |
| 120 | echo "Enabled $service for $wanted_by." | 144 | echo "Enabled $enable_service for $wanted_by." |
| 121 | else | 145 | else |
| 122 | rm -f $ROOT/etc/systemd/system/$r.wants/$service | 146 | if [ "$service_template" = true -a "$instance_specified" = false ]; then |
| 147 | disable_service="$ROOT/etc/systemd/system/$r.wants/`echo $service | sed 's/@/@*/'`" | ||
| 148 | else | ||
| 149 | disable_service="$ROOT/etc/systemd/system/$r.wants/$service" | ||
| 150 | fi | ||
| 151 | rm -f $disable_service | ||
| 123 | rmdir --ignore-fail-on-non-empty -p $ROOT/etc/systemd/system/$r.wants | 152 | rmdir --ignore-fail-on-non-empty -p $ROOT/etc/systemd/system/$r.wants |
| 124 | echo "Disabled $service for $wanted_by." | 153 | echo "Disabled ${disable_service##$ROOT/etc/systemd/system/$r.wants/} for $wanted_by." |
| 125 | fi | 154 | fi |
| 126 | done | 155 | done |
| 127 | 156 | ||
