* [PATCH V2 1/3] systemd-systemctl: add option to manage user services
2016-09-08 9:34 [PATCH V2 0/3] systemd: add support to manage user units Chen Qi
@ 2016-09-08 9:34 ` Chen Qi
2016-09-08 9:34 ` [PATCH V2 2/3] systemd.bbclass: add support " Chen Qi
2016-09-08 9:34 ` [PATCH V2 3/3] pulseaudio: fix to manage user services corretly Chen Qi
2 siblings, 0 replies; 4+ messages in thread
From: Chen Qi @ 2016-09-08 9:34 UTC (permalink / raw)
To: openembedded-core
Add '--global' option to our own systemctl script to manage user services.
[YOCTO #7800]
Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
---
.../systemd/systemd-systemctl/systemctl | 45 ++++++++++++++--------
1 file changed, 28 insertions(+), 17 deletions(-)
diff --git a/meta/recipes-core/systemd/systemd-systemctl/systemctl b/meta/recipes-core/systemd/systemd-systemctl/systemctl
index efad14c..17a7277 100755
--- a/meta/recipes-core/systemd/systemd-systemctl/systemctl
+++ b/meta/recipes-core/systemd/systemd-systemctl/systemctl
@@ -2,7 +2,8 @@
echo "Started $0 $*"
ROOT=
-
+USER_SERVICE=no
+location=system
# parse command line params
action=
while [ $# != 0 ]; do
@@ -46,6 +47,11 @@ while [ $# != 0 ]; do
cmd_args="0"
shift
;;
+ --global)
+ USER_SERVICE=yes
+ cmd_args="0"
+ shift
+ ;;
*)
if [ "$cmd_args" = "1" ]; then
services="$services $opt"
@@ -57,8 +63,13 @@ while [ $# != 0 ]; do
;;
esac
done
+
+if [ "$USER_SERVICE" = "yes" ]; then
+ location=user
+fi
+
if [ "$action" = "preset" -a "$service_file" = "" ]; then
- services=$(for f in `find $ROOT/etc/systemd/system $ROOT/lib/systemd/system $ROOT/usr/lib/systemd/system -type f 2>1`; do basename $f; done)
+ services=$(for f in `find $ROOT/etc/systemd/$location $ROOT/lib/systemd/$location $ROOT/usr/lib/systemd/$location -type f 2>1`; do basename $f; done)
services="$services $opt"
presetall=1
fi
@@ -68,10 +79,10 @@ for service in $services; do
action="preset"
fi
if [ "$action" = "mask" ]; then
- if [ ! -d $ROOT/etc/systemd/system/ ]; then
- mkdir -p $ROOT/etc/systemd/system/
+ if [ ! -d $ROOT/etc/systemd/$location/ ]; then
+ mkdir -p $ROOT/etc/systemd/$location/
fi
- cmd="ln -s /dev/null $ROOT/etc/systemd/system/$service"
+ cmd="ln -s /dev/null $ROOT/etc/systemd/$location/$service"
echo "$cmd"
$cmd
exit 0
@@ -92,9 +103,9 @@ for service in $services; do
fi
# find service file
- for p in $ROOT/etc/systemd/system \
- $ROOT/lib/systemd/system \
- $ROOT/usr/lib/systemd/system; do
+ for p in $ROOT/etc/systemd/$location \
+ $ROOT/lib/systemd/$location \
+ $ROOT/usr/lib/systemd/$location; do
if [ -e $p/$service_base_file ]; then
service_file=$p/$service_base_file
service_file=${service_file##$ROOT}
@@ -151,18 +162,18 @@ for service in $services; do
enable_service=$(echo $service | sed "s/@/@$(echo $default_instance | sed 's/\\/\\\\/g')/")
fi
fi
- mkdir -p $ROOT/etc/systemd/system/$r.$suffix
- ln -s $service_file $ROOT/etc/systemd/system/$r.$suffix/$enable_service
+ mkdir -p $ROOT/etc/systemd/$location/$r.$suffix
+ ln -s $service_file $ROOT/etc/systemd/$location/$r.$suffix/$enable_service
echo "Enabled $enable_service for $r."
else
if [ "$service_template" = true -a "$instance_specified" = false ]; then
- disable_service="$ROOT/etc/systemd/system/$r.$suffix/`echo $service | sed 's/@/@*/'`"
+ disable_service="$ROOT/etc/systemd/$location/$r.$suffix/`echo $service | sed 's/@/@*/'`"
else
- disable_service="$ROOT/etc/systemd/system/$r.$suffix/$service"
+ disable_service="$ROOT/etc/systemd/$location/$r.$suffix/$service"
fi
rm -f $disable_service
- [ -d $ROOT/etc/systemd/system/$r.$suffix ] && rmdir --ignore-fail-on-non-empty -p $ROOT/etc/systemd/system/$r.$suffix
- echo "Disabled ${disable_service##$ROOT/etc/systemd/system/$r.$suffix/} for $r."
+ [ -d $ROOT/etc/systemd/$location/$r.$suffix ] && rmdir --ignore-fail-on-non-empty -p $ROOT/etc/systemd/$location/$r.$suffix
+ echo "Disabled ${disable_service##$ROOT/etc/systemd/$location/$r.$suffix/} for $r."
fi
done
done
@@ -174,11 +185,11 @@ for service in $services; do
for r in $alias; do
if [ "$action" = "enable" ]; then
- mkdir -p $ROOT/etc/systemd/system
- ln -s $service_file $ROOT/etc/systemd/system/$r
+ mkdir -p $ROOT/etc/systemd/$location
+ ln -s $service_file $ROOT/etc/systemd/$location/$r
echo "Enabled $service for $alias."
else
- rm -f $ROOT/etc/systemd/system/$r
+ rm -f $ROOT/etc/systemd/$location/$r
echo "Disabled $service for $alias."
fi
done
--
1.9.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH V2 2/3] systemd.bbclass: add support to manage user services
2016-09-08 9:34 [PATCH V2 0/3] systemd: add support to manage user units Chen Qi
2016-09-08 9:34 ` [PATCH V2 1/3] systemd-systemctl: add option to manage user services Chen Qi
@ 2016-09-08 9:34 ` Chen Qi
2016-09-08 9:34 ` [PATCH V2 3/3] pulseaudio: fix to manage user services corretly Chen Qi
2 siblings, 0 replies; 4+ messages in thread
From: Chen Qi @ 2016-09-08 9:34 UTC (permalink / raw)
To: openembedded-core
Add new variable SYSTEMD_USER_SERVICE and SYSTEM_USER_AUTO_ENABLE
to manage user services. Their usage is like SYSTEMD_SERVICE and
SYSTEMD_AUTO_ENABLE.
[YOCTO #7800]
Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
---
meta/classes/systemd.bbclass | 41 +++++++++++++++++++++++++++++------------
1 file changed, 29 insertions(+), 12 deletions(-)
diff --git a/meta/classes/systemd.bbclass b/meta/classes/systemd.bbclass
index db7873f..b6a4176 100644
--- a/meta/classes/systemd.bbclass
+++ b/meta/classes/systemd.bbclass
@@ -7,6 +7,7 @@ SYSTEMD_PACKAGES_class-nativesdk ?= ""
# Whether to enable or disable the services on installation.
SYSTEMD_AUTO_ENABLE ??= "enable"
+SYSTEMD_USER_AUTO_ENABLE ??= "enable"
# This class will be included in any recipe that supports systemd init scripts,
# even if systemd is not in DISTRO_FEATURES. As such don't make any changes
@@ -29,10 +30,17 @@ if [ -n "$D" ]; then
fi
if type systemctl >/dev/null 2>/dev/null; then
- systemctl $OPTS ${SYSTEMD_AUTO_ENABLE} ${SYSTEMD_SERVICE}
-
- if [ -z "$D" -a "${SYSTEMD_AUTO_ENABLE}" = "enable" ]; then
- systemctl restart ${SYSTEMD_SERVICE}
+ if [ "${SYSTEMD_SERVICE}" != "" ]; then
+ systemctl $OPTS ${SYSTEMD_AUTO_ENABLE} ${SYSTEMD_SERVICE}
+ if [ -z "$D" -a "${SYSTEMD_AUTO_ENABLE}" = "enable" ]; then
+ systemctl restart ${SYSTEMD_SERVICE}
+ fi
+ fi
+ if [ "${SYSTEMD_USER_SERVICE}" != "" ]; then
+ systemctl $OPTS --global ${SYSTEMD_USER_AUTO_ENABLE} ${SYSTEMD_USER_SERVICE}
+ if [ -z "$D" -a "${SYSTEMD_USER_AUTO_ENABLE}" = "enable" ]; then
+ systemctl --global restart ${SYSTEMD_USER_SERVICE}
+ fi
fi
fi
}
@@ -45,11 +53,18 @@ if [ -n "$D" ]; then
fi
if type systemctl >/dev/null 2>/dev/null; then
- if [ -z "$D" ]; then
- systemctl stop ${SYSTEMD_SERVICE}
+ if [ "${SYSTEMD_SERVICE}" != "" ]; then
+ if [ -z "$D" ]; then
+ systemctl stop ${SYSTEMD_SERVICE}
+ fi
+ systemctl $OPTS disable ${SYSTEMD_SERVICE}
+ fi
+ if [ "${SYSTEMD_USER_SERVICE}" != "" ]; then
+ if [ -z "$D" ]; then
+ systemctl --global stop ${SYSTEMD_USER_SERVICE}
+ fi
+ systemctl $OPTS --global disable ${SYSTEMD_USER_SERVICE}
fi
-
- systemctl $OPTS disable ${SYSTEMD_SERVICE}
fi
}
@@ -139,12 +154,14 @@ python systemd_populate_packages() {
def systemd_check_services():
searchpaths = [oe.path.join(d.getVar("sysconfdir", True), "systemd", "system"),]
searchpaths.append(d.getVar("systemd_system_unitdir", True))
+ searchpaths.append(oe.path.join(d.getVar("sysconfdir", True), "systemd", "user"))
+ searchpaths.append(d.getVar("systemd_user_unitdir", True))
systemd_packages = d.getVar('SYSTEMD_PACKAGES', True)
keys = 'Also'
# scan for all in SYSTEMD_SERVICE[]
for pkg_systemd in systemd_packages.split():
- for service in get_package_var(d, 'SYSTEMD_SERVICE', pkg_systemd).split():
+ for service in (get_package_var(d, 'SYSTEMD_SERVICE', pkg_systemd) + get_package_var(d, 'SYSTEMD_USER_SERVICE', pkg_systemd)).split():
path_found = ''
# Deal with adding, for example, 'ifplugd@eth0.service' from
@@ -165,14 +182,14 @@ python systemd_populate_packages() {
if path_found != '':
systemd_add_files_and_parse(pkg_systemd, path_found, service, keys)
else:
- raise bb.build.FuncFailed("SYSTEMD_SERVICE_%s value %s does not exist" % \
- (pkg_systemd, service))
+ raise bb.build.FuncFailed("SYSTEMD_SERVICE_%s or SYSTEMD_USER_SERVICE_%s value %s does not exist" % \
+ (pkg_systemd, pkg_systemd, service))
# Run all modifications once when creating package
if os.path.exists(d.getVar("D", True)):
for pkg in d.getVar('SYSTEMD_PACKAGES', True).split():
systemd_check_package(pkg)
- if d.getVar('SYSTEMD_SERVICE_' + pkg, True):
+ if d.getVar('SYSTEMD_SERVICE_' + pkg, True) or d.getVar('SYSTEMD_USER_SERVICE_' + pkg, True):
systemd_generate_package_scripts(pkg)
systemd_check_services()
}
--
1.9.1
^ permalink raw reply related [flat|nested] 4+ messages in thread