From: Peter Urbanec <openembedded-devel@urbanec.net>
To: OE Core <openembedded-core@lists.openembedded.org>
Subject: [PATCH 2/2] update-rc.d.bbclass: Better handling of package upgrades.
Date: Wed, 15 Oct 2014 22:49:53 +1100 [thread overview]
Message-ID: <543E5F61.2090500@urbanec.net> (raw)
update-rc.d.bbclass provides default implementations of prerm, postrm,
preinst and postinst. Unfortunately these default implementations don't
deal with package upgrades as well as they could.
For example, if "opkg upgrade" contains init-ifupdown, in the list of
packages to upgrade, the default prerm and preinst scripts will stop
networking while all the packages are being downloaded, unpacked and
installed. Networking is not brought back up again until the postinst
script from the new init-ifupdown package is called. That only happens
after all the packages have been downloaded, unpacked and installed.
This leaves a window where any package that needs to be downloaded after
init-ifupdown was encountered will fail because networking is down.
This patch fixes the problem by delaying the restart of the old service
during an upgrade until postinst. In the case of a package removal, the
service will still be stopped in prerm.
Signed-off-by: Peter Urbanec <openembedded-devel@urbanec.net>
---
meta/classes/update-rc.d.bbclass | 73 ++++++++++++++++++++++++----------------
1 file changed, 44 insertions(+), 29 deletions(-)
diff --git a/meta/classes/update-rc.d.bbclass b/meta/classes/update-rc.d.bbclass
index bc1aa7d..fcb82fe 100644
--- a/meta/classes/update-rc.d.bbclass
+++ b/meta/classes/update-rc.d.bbclass
@@ -14,45 +14,60 @@ INITSCRIPT_PARAMS ?= "defaults"
INIT_D_DIR = "${sysconfdir}/init.d"
-updatercd_preinst() {
-if [ -z "$D" -a -f "${INIT_D_DIR}/${INITSCRIPT_NAME}" ]; then
- ${INIT_D_DIR}/${INITSCRIPT_NAME} stop
+# pre/postrm scripts come from old package, pre/postinst scripts come from
+# new package. See https://wiki.debian.org/MaintainerScripts for dpkg
+# diagrams. opkg uses a subset, which lacks most of the error handling.
+
+# Old package, step 1
+updatercd_prerm() {
+if [ -z "$D" ]; then
+ if [ "$1" != "upgrade" ] ; then
+ ${INIT_D_DIR}/${INITSCRIPT_NAME} stop
+ fi
+ OPT="-f"
+else
+ OPT="-f -r $D"
fi
if type update-rc.d >/dev/null 2>/dev/null; then
- if [ -n "$D" ]; then
- OPT="-f -r $D"
- else
- OPT="-f"
- fi
- update-rc.d $OPT ${INITSCRIPT_NAME} remove
+ update-rc.d $OPT ${INITSCRIPT_NAME} remove
fi
}
-updatercd_postinst() {
-if type update-rc.d >/dev/null 2>/dev/null; then
- if [ -n "$D" ]; then
- OPT="-r $D"
- else
- OPT="-s"
- fi
- update-rc.d $OPT ${INITSCRIPT_NAME} ${INITSCRIPT_PARAMS}
-fi
+# New package, step 2
+updatercd_preinst() {
+case "$1" in
+ upgrade)
+ ;;
+ *)
+ ;;
+esac
}
-updatercd_prerm() {
-if [ -z "$D" ]; then
- ${INIT_D_DIR}/${INITSCRIPT_NAME} stop
-fi
+# Old package, step 3
+updatercd_postrm() {
+case "$1" in
+ upgrade)
+ ;;
+ *)
+ ;;
+esac
}
-updatercd_postrm() {
+# New package, step 4
+# This step runs after all packages have been through steps 1-3. We need to
+# delay service restarts during upgrade until here, otherwise we could end
+# up in situations, like networking going down in the middle of "opkg upgrade",
+# thus resulting in failures to fetch further packages.
+updatercd_postinst() {
+if [ -z "$D" ]; then
+ # This will catch the upgrade case and result in a restart.
+ ${INIT_D_DIR}/${INITSCRIPT_NAME} stop
+ OPT="-s"
+else
+ OPT="-r $D"
+fi
if type update-rc.d >/dev/null 2>/dev/null; then
- if [ -n "$D" ]; then
- OPT="-r $D"
- else
- OPT=""
- fi
- update-rc.d $OPT ${INITSCRIPT_NAME} remove
+ update-rc.d $OPT ${INITSCRIPT_NAME} ${INITSCRIPT_PARAMS}
fi
}
-- 2.1.2
next reply other threads:[~2014-10-15 11:49 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-15 11:49 Peter Urbanec [this message]
2014-10-16 18:51 ` [PATCH 2/2] update-rc.d.bbclass: Better handling of package upgrades Andreas Oberritter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=543E5F61.2090500@urbanec.net \
--to=openembedded-devel@urbanec.net \
--cc=openembedded-core@lists.openembedded.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox