From patchwork Mon Jan 11 22:07:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Roederer X-Patchwork-Id: 1424846 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=geroedel.de Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=nXSykh6K; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DF7Dn2PcHz9sWj for ; Tue, 12 Jan 2021 09:10:16 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe :List-Id:Subject:MIME-Version:References:In-Reply-To:Message-Id:Date:To:From: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=zMfFMWmx+THkpjmgK8TCC+wOOdb2Ic59YOCG8JuF9h0=; b=nXSykh6KIssT1mAVeBqCOojUr0 U4fRZaze7ZaPwcY67fXGehjYfU47z2JocV+D731TlP+kcM417xs13hr7Gj7SUJMQ1UD9pHTB+AfGF kpcqp9MXXKxOJb8vM37cjkm5b3fxV4/n3t3JLGJmxTo75W38/6y4IF1qEQ2RNDcWYnPfu5MXCU+ac 0fjciIqNO2/7NPtoLlMwjKcRQ7sL9P7W7X8f8opcCZR6Wj6nOF6p1P18hH7feL6ELKPGDCiLwm8me BXKpKvC6eu9HqEmR/hKkQkY2tx/OLZCbTyMIasCtT7NIpVDBG4m73ymFeUAnJnGwDRr5ezvLpndyF LO3EgIkw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kz5Lo-0000LD-CJ; Mon, 11 Jan 2021 22:07:48 +0000 Received: from [2a02:180:2:aa:1::b3] (helo=dazzle.geroedel.de) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kz5Lk-0000JV-V0 for openwrt-devel@lists.openwrt.org; Mon, 11 Jan 2021 22:07:46 +0000 Received: from [192.168.15.2] (helo=feeble.bln.roederer.dhs.org) by dazzle.geroedel.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1kz5Le-0000vQ-Qd for openwrt-devel@lists.openwrt.org; Mon, 11 Jan 2021 23:07:40 +0100 Received: from build.bln.roederer.dhs.org ([192.168.8.5] helo=build) by feeble.bln.roederer.dhs.org with smtp (Exim 4.92) (envelope-from ) id 1kz5Le-00042v-Dn for openwrt-devel@lists.openwrt.org; Mon, 11 Jan 2021 23:07:38 +0100 Received: (nullmailer pid 23132 invoked by uid 10000); Mon, 11 Jan 2021 22:07:45 -0000 From: Sven Roederer To: openwrt-devel@lists.openwrt.org Date: Mon, 11 Jan 2021 23:07:26 +0100 Message-Id: <20210111220726.23069-1-devel-sven@geroedel.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <86fd296ede0f91d157e675fa3d64d77a@dev.tdt.de> References: <86fd296ede0f91d157e675fa3d64d77a@dev.tdt.de> MIME-Version: 1.0 X-Spam_score: -2.9 X-Spam_score_int: -28 X-Spam_bar: -- X-Spam_report: Spam detection software, running on the system "dazzle", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see @@CONTACT_ADDRESS@@ for details. Content preview: Restore the status of the system-services after sysupgrade. Create a file with the status of all known services and keep it during upgrade. After upgrade run a uci-default script to restore every sing [...] Content analysis details: (-2.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-SA-Exim-Connect-IP: 192.168.15.2 X-SA-Exim-Mail-From: devel-sven@geroedel.de X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dazzle X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.2 Subject: [PATCH v2] base-files: restore status of system-services after sysupgrade X-SA-Exim-Version: 4.2.1 (built Tue, 02 Aug 2016 21:08:31 +0000) X-SA-Exim-Scanned: Yes (on dazzle.geroedel.de) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210111_170745_165669_26F80DAA X-CRM114-Status: GOOD ( 22.84 ) X-Spam-Score: 1.3 (+) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (1.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 1.3 RDNS_NONE Delivered to internal network by a host with no rDNS X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org Restore the status of the system-services after sysupgrade. Create a file with the status of all known services and keep it during upgrade. After upgrade run a uci-default script to restore every single service. The list of the service status will be stored in etc/backup folder also and formated as: /etc/init.d/ {enable|disable} When upgrading with an generic image all system services are enabled by default which is usually not expected and can cause trouble. The default behavior can be flipped with the "-s" option of sysupgrade. Signed-off-by: Sven Roederer --- This v2 includes the feedback from the mailinglist: * entangles this feature from "storing the packagelist" * adds a option for disabling to sysupgrade * makes it enabled by default * includes the glue-script to restore the services after upgrade I was not able to test on a real system yet. package/base-files/Makefile | 2 +- .../uci-defaults/14_restore-services-state | 3 ++ package/base-files/files/sbin/sysupgrade | 38 ++++++++++++++----- 3 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 package/base-files/files/etc/uci-defaults/14_restore-services-state diff --git a/package/base-files/Makefile b/package/base-files/Makefile index f18f221129..5a9bacba13 100644 --- a/package/base-files/Makefile +++ b/package/base-files/Makefile @@ -12,7 +12,7 @@ include $(INCLUDE_DIR)/version.mk include $(INCLUDE_DIR)/feeds.mk PKG_NAME:=base-files -PKG_RELEASE:=246 +PKG_RELEASE:=247 PKG_FLAGS:=nonshared PKG_FILE_DEPENDS:=$(PLATFORM_DIR)/ $(GENERIC_PLATFORM_DIR)/base-files/ diff --git a/package/base-files/files/etc/uci-defaults/14_restore-services-state b/package/base-files/files/etc/uci-defaults/14_restore-services-state new file mode 100644 index 0000000000..d0085f3f80 --- /dev/null +++ b/package/base-files/files/etc/uci-defaults/14_restore-services-state @@ -0,0 +1,3 @@ +SERVICE_STATUS=/etc/backup/service_status.txt + +[ -e ${SERVICE_STATUS} ] && . ${SERVICE_STATUS} diff --git a/package/base-files/files/sbin/sysupgrade b/package/base-files/files/sbin/sysupgrade index 50f4e08e44..068ec27e3d 100755 --- a/package/base-files/files/sbin/sysupgrade +++ b/package/base-files/files/sbin/sysupgrade @@ -15,6 +15,7 @@ export SAVE_OVERLAY_PATH= export SAVE_PARTITIONS=1 export SAVE_INSTALLED_PKGS=0 export SKIP_UNCHANGED=1 +export SAVE_SERVICE_STATUS=1 export CONF_IMAGE= export CONF_BACKUP_LIST=0 export CONF_BACKUP= @@ -35,6 +36,7 @@ while [ -n "$1" ]; do -c) export SAVE_OVERLAY=1 SAVE_OVERLAY_PATH=/etc;; -o) export SAVE_OVERLAY=1 SAVE_OVERLAY_PATH=/;; -p) export SAVE_PARTITIONS=0;; + -s) export SAVE_SERVICE_STATUS=0;; -k) export SAVE_INSTALLED_PKGS=1;; -U) export SKIP_UNCHANGED=0;; -b|--create-backup) export CONF_BACKUP="$2" NEED_IMAGE=1; shift;; @@ -57,13 +59,14 @@ export CONFFILES=/tmp/sysupgrade.conffiles export CONF_TAR=/tmp/sysupgrade.tgz export ETCBACKUP_DIR=/etc/backup export INSTALLED_PACKAGES=${ETCBACKUP_DIR}/installed_packages.txt +export SERVICE_STATUS=${ETCBACKUP_DIR}/service_status.txt IMAGE="$1" [ -z "$IMAGE" -a -z "$NEED_IMAGE" -a $CONF_BACKUP_LIST -eq 0 -o $HELP -gt 0 ] && { cat <...] - $0 [-q] [-i] [-c] [-U] [-o] [-k] + $0 [-q] [-i] [-c] [-U] [-o] [-s] [-k] upgrade-option: -f restore configuration from .tar.gz (file or url) @@ -75,6 +78,7 @@ upgrade-option: (this is a modification of Freifunk Berlin to unset -u) -n do not save configuration over reflash -p do not attempt to restore the partition table after flash. + -s do not attempt to restore the status of the services. -k include in backup a list of current installed packages at $INSTALLED_PACKAGES -T | --test @@ -231,8 +235,7 @@ do_save_conffiles() { run_hooks "$CONFFILES" $sysupgrade_init_conffiles ask_bool 0 "Edit config file list" && vi "$CONFFILES" - if [ "$SAVE_INSTALLED_PKGS" -eq 1 ]; then - echo "${INSTALLED_PACKAGES}" >> "$CONFFILES" + if [ "$SAVE_INSTALLED_PKGS" -eq 1 ] || [ "$SAVE_SERVICE_STATUS" -eq 1 ]; then mkdir -p "$ETCBACKUP_DIR" # Avoid touching filesystem on each backup RAMFS="$(mktemp -d -t sysupgrade.XXXXXX)" @@ -243,13 +246,28 @@ do_save_conffiles() { ask_bool 0 "Abort" && exit } - # Format: pkg-name{rom,overlay,unkown} - # rom is used for pkgs in /rom, even if updated later - find /usr/lib/opkg/info -name "*.control" \( \ - \( -exec test -f /rom/{} \; -exec echo {} rom \; \) -o \ - \( -exec test -f /overlay/upper/{} \; -exec echo {} overlay \; \) -o \ - \( -exec echo {} unknown \; \) \ - \) | sed -e 's,.*/,,;s/\.control /\t/' > ${INSTALLED_PACKAGES} + if [ "$SAVE_INSTALLED_PKGS" -eq 1 ]; then + echo "${INSTALLED_PACKAGES}" >> "$CONFFILES" + # Format: pkg-name{rom,overlay,unkown} + # rom is used for pkgs in /rom, even if updated later + find /usr/lib/opkg/info -name "*.control" \( \ + \( -exec test -f /rom/{} \; -exec echo {} rom \; \) -o \ + \( -exec test -f /overlay/upper/{} \; -exec echo {} overlay \; \) -o \ + \( -exec echo {} unknown \; \) \ + \) | sed -e 's,.*/,,;s/\.control /\t/' > ${INSTALLED_PACKAGES} + fi + + if [ "$SAVE_SERVICE_STATUS" -eq 1 ]; then + echo "${SERVICE_STATUS}" >> "$CONFFILES" + # Format: /etc/init.d/servicename {enable,disable} + rm -f ${SERVICE_STATUS} + for service in /etc/init.d/* ; do \ + ${service} enabled && \ + echo >> ${SERVICE_STATUS} "$service" "enable" || \ + echo >> ${SERVICE_STATUS} "$service" "disable" \ + ; \ + done + fi fi v "Saving config files..."