Patchwork [6/9] systemd: allow postinsts to run without systemd being present

login
register
mail settings
Submitter Ross Burton
Date March 11, 2013, 8:07 p.m.
Message ID <4ad7ea263a05fb3c1960623760340549a20c849c.1363031776.git.ross.burton@intel.com>
Download mbox | patch
Permalink /patch/45991/
State New
Headers show

Comments

Ross Burton - March 11, 2013, 8:07 p.m.
These fragments may be used on a system that didn't actually boot with systemd,
so check for systemctl first, and don't force systemd to be installed.

Signed-off-by: Ross Burton <ross.burton@intel.com>
---
 meta/classes/systemd.bbclass |   27 +++++++++++----------------
 1 file changed, 11 insertions(+), 16 deletions(-)
Enrico Scholz - March 12, 2013, 10:36 a.m.
Ross Burton <ross.burton-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
writes:

> These fragments may be used on a system that didn't actually boot with
> systemd, so check for systemctl first, and don't force systemd to be
> installed.

Checking for existence of programs in scriplets is a bad hack which
might hide real problems and the scriplets are getting more complicated
by this.

Placing scriplets and related files into separate subpackages is a much
cleaner solution.


> +if which systemctl >/dev/null; then

check with the shell builtin 'type $prog' is more portable and does not
require the external 'which' program.



Enrico
Ross Burton - March 19, 2013, 11:23 a.m.
On 12 March 2013 10:36, Enrico Scholz <enrico.scholz@sigma-chemnitz.de> wrote:
>> +if which systemctl >/dev/null; then
>
> check with the shell builtin 'type $prog' is more portable and does not
> require the external 'which' program.

Tried that (type -p systemctl), and failed on the host.  Really not
sure why to be honest.

Ross
Ross Burton - March 19, 2013, 11:39 a.m.
On 12 March 2013 10:36, Enrico Scholz <enrico.scholz@sigma-chemnitz.de> wrote:
> Checking for existence of programs in scriplets is a bad hack which
> might hide real problems and the scriplets are getting more complicated
> by this.
>
> Placing scriplets and related files into separate subpackages is a much
> cleaner solution.

Sure, but then you're just substituting one ugly hack for bigger
problems including upgrade paths, which aren't actually solvable in a
general way.

Ross
Enrico Scholz - March 19, 2013, 12:09 p.m.
"Burton, Ross" <ross.burton@intel.com> writes:

>>> +if which systemctl >/dev/null; then
>>
>> check with the shell builtin 'type $prog' is more portable and does not
>> require the external 'which' program.
>
> Tried that (type -p systemctl)

'type systemctl'; 'type -p ...' is a bashism.



Enrico
Ross Burton - March 19, 2013, 12:11 p.m.
On 19 March 2013 12:09, Enrico Scholz <enrico.scholz@sigma-chemnitz.de> wrote:
> 'type systemctl'; 'type -p ...' is a bashism.

Pretty sure I tried both, and busybox source shows it won't error out
on "-p".  I'll try again.

Ross
Enrico Scholz - March 19, 2013, 12:12 p.m.
"Burton, Ross" <ross.burton@intel.com> writes:

>> Checking for existence of programs in scriplets is a bad hack which
>> might hide real problems and the scriplets are getting more complicated
>> by this.
>>
>> Placing scriplets and related files into separate subpackages is a much
>> cleaner solution.
>
> Sure, but then you're just substituting one ugly hack for bigger
> problems including upgrade 

What is the problem with subpackages and upgrade paths?


Enrico
Enrico Scholz - March 19, 2013, 1 p.m.
"Burton, Ross" <ross.burton-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
writes:

>> 'type systemctl'; 'type -p ...' is a bashism.
>
> Pretty sure I tried both, and busybox source shows it won't error out
> on "-p".

But 'dash' on host will fail.


Enrico

Patch

diff --git a/meta/classes/systemd.bbclass b/meta/classes/systemd.bbclass
index 564cd72..f622f9c 100644
--- a/meta/classes/systemd.bbclass
+++ b/meta/classes/systemd.bbclass
@@ -24,19 +24,23 @@  if [ -n "$D" ]; then
     OPTS="--root=$D"
 fi
 
-systemctl $OPTS ${SYSTEMD_AUTO_ENABLE} ${SYSTEMD_SERVICE}
+if which systemctl >/dev/null; then
+	systemctl $OPTS ${SYSTEMD_AUTO_ENABLE} ${SYSTEMD_SERVICE}
 
-if [ -z "$D" -a "${SYSTEMD_AUTO_ENABLE}" = "enable" ]; then
-    systemctl start ${SYSTEMD_SERVICE}
+	if [ -z "$D" -a "${SYSTEMD_AUTO_ENABLE}" = "enable" ]; then
+		systemctl start ${SYSTEMD_SERVICE}
+	fi
 fi
 }
 
 systemd_prerm() {
-if [ -z "$D" ]; then
-    systemctl stop ${SYSTEMD_SERVICE}
-fi
+if which systemctl >/dev/null; then
+	if [ -z "$D" ]; then
+		systemctl stop ${SYSTEMD_SERVICE}
+	fi
 
-systemctl disable ${SYSTEMD_SERVICE}
+	systemctl disable ${SYSTEMD_SERVICE}
+fi
 }
 
 python systemd_populate_packages() {
@@ -56,14 +60,6 @@  python systemd_populate_packages() {
             bb.error('%s does not appear in package list, please add it' % pkg_systemd)
 
 
-    # Add a runtime dependency on systemd to pkg
-    def systemd_add_rdepends(pkg):
-        rdepends = d.getVar('RDEPENDS_' + pkg, True) or ""
-        if not 'systemd' in rdepends.split():
-            rdepends = '%s %s' % (rdepends, 'systemd')
-        d.setVar('RDEPENDS_' + pkg, rdepends)
-
-
     def systemd_generate_package_scripts(pkg):
         bb.debug(1, 'adding systemd calls to postinst/postrm for %s' % pkg)
 
@@ -156,7 +152,6 @@  python systemd_populate_packages() {
             systemd_check_package(pkg)
             if d.getVar('SYSTEMD_SERVICE_' + pkg, True):
                 systemd_generate_package_scripts(pkg)
-                systemd_add_rdepends(pkg)
         systemd_check_services()
 }