Patchwork systemd.bbclass: restart service in postinst, not start

login
register
mail settings
Submitter Ross Burton
Date April 9, 2013, 3:48 p.m.
Message ID <1365522501-7439-1-git-send-email-ross.burton@intel.com>
Download mbox | patch
Permalink /patch/47727/
State Accepted
Commit f6ae87e838685bd28c44512b3fd97bc5ad8127a7
Headers show

Comments

Ross Burton - April 9, 2013, 3:48 p.m.
When upgrading packages it's possible that the service is already running
because opkg doesn't actually execute the prerm hooks on upgrades, which is
where the service should be stopped.

Handle this case by restarting in postinst instead of starting.  If the service
isn't already running then this doesn't make a difference, but if it is running
then the service will be restarted.

[ YOCTO #4213 ]

Signed-off-by: Ross Burton <ross.burton@intel.com>
---
 meta/classes/systemd.bbclass |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Koen Kooi - April 10, 2013, 5:46 a.m.
Op 9 apr. 2013, om 17:48 heeft Ross Burton <ross.burton@intel.com> het volgende geschreven:

> When upgrading packages it's possible that the service is already running
> because opkg doesn't actually execute the prerm hooks on upgrades, which is
> where the service should be stopped.
> 
> Handle this case by restarting in postinst instead of starting.  If the service
> isn't already running then this doesn't make a difference, but if it is running
> then the service will be restarted.

In the specific case of upgrades you'll need to add a

	systemctl --system daemon-reload

to catch changed unit files as well.

regards,

Koen
Ross Burton - April 10, 2013, 9:08 a.m.
On 10 April 2013 06:46, Koen Kooi <koen@dominion.thruhere.net> wrote:
> In the specific case of upgrades you'll need to add a
>
>         systemctl --system daemon-reload
>
> to catch changed unit files as well.

Good catch, thanks.

I'm not entirely optimistic about opkg postinsts being able to tell
the difference between upgrades and fresh installs, so I suspect we'll
just have to always do this.

Ross

Patch

diff --git a/meta/classes/systemd.bbclass b/meta/classes/systemd.bbclass
index 69eeb9e..8084251 100644
--- a/meta/classes/systemd.bbclass
+++ b/meta/classes/systemd.bbclass
@@ -31,7 +31,7 @@  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 start ${SYSTEMD_SERVICE}
+		systemctl restart ${SYSTEMD_SERVICE}
 	fi
 fi
 }