[openwrt/openwrt] base-files: upgrade: use procd to kill managed daemons

LEDE Commits lede-commits at lists.infradead.org
Sat Jun 12 16:59:38 PDT 2021


aparcar pushed a commit to openwrt/openwrt.git, branch master:
https://git.openwrt.org/b118aba8cbac58a45d4882cd79e18e56c3fbdc70

commit b118aba8cbac58a45d4882cd79e18e56c3fbdc70
Author: Michael Pratt <mcpratt at pm.me>
AuthorDate: Sat May 29 09:03:11 2021 -0400

    base-files: upgrade: use procd to kill managed daemons
    
    These processes are managed by procd and set to start again when killed
    via the procd instance parameter "respawn" being set during init.
    
    Example:
    procd_set_param respawn 3600 1 0
    
    When they are killed manually during sysupgrade,
    they are started again in 5 seconds or less, depending on
    how the "respawn" parameter is set.
    
    Use procd through ubus to disable the instances that respawn them,
    however, allow dnsmasq, netifd, and logd to restart for remote logging.
    
    Properly closing all these processes increases free memory by about 3 MB,
    which should help low memory devices upgrade without crashing.
    
    For very low memory devices (set to 32 MB for now)
    also kill dnsmasq, netifd, and logd for an additional 3 MB of free memory.
    
    Also, bump sleep values to allow at least 10 seconds
    for network interfaces and daemons
    to come up after they are killed and restarted
    before caches are dropped.
    
    Signed-off-by: Michael Pratt <mcpratt at pm.me>
---
 package/base-files/files/lib/upgrade/stage2 | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/package/base-files/files/lib/upgrade/stage2 b/package/base-files/files/lib/upgrade/stage2
index e2259e3472..b00d0c079a 100755
--- a/package/base-files/files/lib/upgrade/stage2
+++ b/package/base-files/files/lib/upgrade/stage2
@@ -123,15 +123,31 @@ kill_remaining() { # [ <signal> [ <loop> ] ]
 
 indicate_upgrade
 
+while read -r a b c; do
+	case "$a" in
+		MemT*) mem="$b" ;; esac
+done < /proc/meminfo
+
+[ "$mem" -gt 32768 ] && \
+	skip_services="dnsmasq log network"
+for service in /etc/init.d/*; do
+	service=${service##*/}
+
+	case " $skip_services " in
+		*" $service "*) continue ;; esac
+
+	ubus call service delete '{ "name": "'"$service"'" }' 2>/dev/null
+done
+
 killall -9 telnetd
 killall -9 dropbear
 killall -9 ash
 
 kill_remaining TERM
-sleep 3
+sleep 4
 kill_remaining KILL 1
 
-sleep 1
+sleep 6
 
 echo 3 > /proc/sys/vm/drop_caches
 



More information about the lede-commits mailing list