summaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/systemd/systemd-systemctl
diff options
context:
space:
mode:
authorRadu Moisan <radu.moisan@intel.com>2013-01-19 22:47:07 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-01-20 12:45:00 +0000
commit6a8a48b4d0d0b9b8d8af46cae11245bcb870bbc3 (patch)
treee1c5228c385c0e8618394c063598aa1cb710d66e /meta/recipes-core/systemd/systemd-systemctl
parent06e262c9b4c406b886db6ca8eee55ab441599151 (diff)
downloadopenembedded-core-6a8a48b4d0d0b9b8d8af46cae11245bcb870bbc3.tar.gz
systemd: add systemd recipes
Add systemd recipes and associated support recipes. Mostly based on meta-oe/meta-systemd, so almost all credit should go to: Andreas Müller <schnitzeltony@googlemail.com> Denis 'GNUtoo' Carikli <GNUtoo@no-log.org> Holger Hans Peter Freyther <holger@moiji-mobile.com> Khem Raj <raj.khem@gmail.com> Koen Kooi <koen@dominion.thruhere.net> Martin Jansa <Martin.Jansa@gmail.com> Signed-off-by: Radu Moisan <radu.moisan@intel.com> Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/recipes-core/systemd/systemd-systemctl')
-rwxr-xr-xmeta/recipes-core/systemd/systemd-systemctl/systemctl126
1 files changed, 126 insertions, 0 deletions
diff --git a/meta/recipes-core/systemd/systemd-systemctl/systemctl b/meta/recipes-core/systemd/systemd-systemctl/systemctl
new file mode 100755
index 0000000000..d71c7eda8b
--- /dev/null
+++ b/meta/recipes-core/systemd/systemd-systemctl/systemctl
@@ -0,0 +1,126 @@
+#!/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"
+
+ # create the required symbolic links
+ wanted_by=$(grep WantedBy $ROOT/$service_file \
+ | sed 's,WantedBy=,,g' \
+ | tr ',' '\n' \
+ | grep '\(\.target$\)\|\(\.service$\)')
+
+ 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=$(grep Alias $ROOT/$service_file \
+ | sed 's,Alias=,,g' \
+ | tr ',' '\n' \
+ | grep '\.service$')
+
+ 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=$(grep Also $ROOT/$service_file \
+ | sed 's,Also=,,g' \
+ | 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