[OE-core] [PATCH 2/2] update-rc.d.bbclass: Better handling of package upgrades.
Andreas Oberritter
obi at opendreambox.org
Thu Oct 16 18:51:57 UTC 2014
On 15.10.2014 13:49, Peter Urbanec wrote:
> 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.
Hello Peter,
did you read my reply to your initial patch? I don't see any obvious
changes. What's the difference between v1 and this version?
Regards,
Andreas
>
> Signed-off-by: Peter Urbanec <openembedded-devel at 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
>
More information about the Openembedded-core
mailing list