From 5115473d246782a40f1896eb89a43a43e4a8384c Mon Sep 17 00:00:00 2001 From: pedro Date: Mon, 25 Jul 2022 15:13:23 +0200 Subject: [PATCH] rc: do not (re)start services during upgrade/reboot --- release/src-rt-6.x.4708/router/others/btcheck | 2 +- release/src-rt-6.x.4708/router/others/mycheck | 2 +- release/src-rt-6.x.4708/router/rc/init.c | 12 +++++++++-- release/src-rt-6.x.4708/router/rc/openvpn.c | 2 +- release/src-rt-6.x.4708/router/rc/services.c | 21 +++++++++++-------- release/src-rt-6.x.4708/router/rc/tinc.c | 2 +- 6 files changed, 26 insertions(+), 15 deletions(-) diff --git a/release/src-rt-6.x.4708/router/others/btcheck b/release/src-rt-6.x.4708/router/others/btcheck index 0776feb7fb..c616b6359e 100755 --- a/release/src-rt-6.x.4708/router/others/btcheck +++ b/release/src-rt-6.x.4708/router/others/btcheck @@ -26,7 +26,7 @@ case "$1" in } ;; check) - [ "$BTON" -eq 1 -a "$BTCH" -eq 1 ] && { + [ "$BTON" -eq 1 -a "$BTCH" -eq 1 -a "$(nvram get g_upgrade)" != "1" -a "$(nvram get g_reboot)" != "1" ] && { pidof transmission-daemon >/dev/null || { logger -t btcheck "Transmission stopped? Starting..." service bittorrent restart diff --git a/release/src-rt-6.x.4708/router/others/mycheck b/release/src-rt-6.x.4708/router/others/mycheck index ae72d6d40b..b1c34c55d9 100755 --- a/release/src-rt-6.x.4708/router/others/mycheck +++ b/release/src-rt-6.x.4708/router/others/mycheck @@ -26,7 +26,7 @@ case "$1" in } ;; check) - [ "$MYON" -eq 1 -a "$MYCH" -eq 1 ] && { + [ "$MYON" -eq 1 -a "$MYCH" -eq 1 -a "$(nvram get g_upgrade)" != "1" -a "$(nvram get g_reboot)" != "1" ] && { pidof mysqld >/dev/null || { logger -t mycheck "MySQL stopped? Starting..." service mysql restart diff --git a/release/src-rt-6.x.4708/router/rc/init.c b/release/src-rt-6.x.4708/router/rc/init.c index 7af9ac4e0c..761ccffc52 100644 --- a/release/src-rt-6.x.4708/router/rc/init.c +++ b/release/src-rt-6.x.4708/router/rc/init.c @@ -9850,9 +9850,8 @@ int init_main(int argc, char *argv[]) unlink("/var/notice/sysup"); nvram_set("g_reboot", "1"); - if (nvram_match("webmon_bkp", "1")) { + if (nvram_get_int("webmon_bkp")) xstart("/usr/sbin/webmon_bkp", "hourly"); /* make a copy before halt/reboot router */ - } run_nvscript("script_shut", NULL, 10); @@ -9865,8 +9864,17 @@ int init_main(int argc, char *argv[]) if ((state == SIGTERM /* REBOOT */) || (state == SIGQUIT /* HALT */)) { stop_syslog(); + killall("buttons", SIGTERM); + killall("udhcpc", SIGTERM); +#ifdef TCONFIG_USB remove_storage_main(1); stop_usb(); +#ifndef TCONFIG_USBAP + remove_usb_module(); +#endif +#endif /* TCONFIG_USB */ + remove_conntrack(); + stop_jffs2(); shutdn(state == SIGTERM /* REBOOT */); sync(); sync(); sync(); diff --git a/release/src-rt-6.x.4708/router/rc/openvpn.c b/release/src-rt-6.x.4708/router/rc/openvpn.c index 7ee2b6911e..3e4d515fc1 100644 --- a/release/src-rt-6.x.4708/router/rc/openvpn.c +++ b/release/src-rt-6.x.4708/router/rc/openvpn.c @@ -208,7 +208,7 @@ static void ovpn_setup_watchdog(ovpn_type_t type, const int unit) if ((fp = fopen(buffer, "w"))) { fprintf(fp, "#!/bin/sh\n" - "[ -z \"$(pidof vpn%s%d)\" ] && {\n" + "[ -z \"$(pidof vpn%s%d)\" -a \"$(nvram get g_upgrade)\" != \"1\" -a \"$(nvram get g_reboot)\" != \"1\" ] && {\n" " service vpn%s%d restart\n" "}\n", instanceType, unit, diff --git a/release/src-rt-6.x.4708/router/rc/services.c b/release/src-rt-6.x.4708/router/rc/services.c index 564cbfcf91..47d252df8e 100644 --- a/release/src-rt-6.x.4708/router/rc/services.c +++ b/release/src-rt-6.x.4708/router/rc/services.c @@ -972,7 +972,7 @@ void generate_mdns_config(void) void start_mdns(void) { - if (nvram_get_int("g_upgrade")) + if (nvram_get_int("g_upgrade") || nvram_get_int("g_reboot")) return; if (!nvram_get_int("mdns_enable")) @@ -2754,7 +2754,7 @@ static void stop_media_server(void) #ifdef TCONFIG_USB static void start_nas_services(void) { - if (nvram_get_int("g_upgrade")) + if (nvram_get_int("g_upgrade") || nvram_get_int("g_reboot")) return; if (getpid() != 1) { @@ -2797,7 +2797,7 @@ void restart_nas_services(int stop, int start) /* restart all NAS applications */ if (stop) stop_nas_services(); - if (start && !nvram_get_int("g_upgrade")) + if (start) start_nas_services(); file_unlock(fd); @@ -2831,8 +2831,8 @@ void check_services(void) /* periodically reap any zombies */ setitimer(ITIMER_REAL, &zombie_tv, NULL); - /* do not restart if upgrading */ - if (!nvram_get_int("g_upgrade")) { + /* do not restart if upgrading/rebooting */ + if (!nvram_get_int("g_upgrade") && !nvram_get_int("g_reboot")) { _check(pid_hotplug2, "hotplug2", start_hotplug2); _check(pid_dnsmasq, "dnsmasq", start_dnsmasq); _check(pid_crond, "crond", start_cron); @@ -2919,6 +2919,7 @@ void start_services(void) #ifdef TCONFIG_IRQBALANCE start_irqbalance(); #endif + start_upnp(); } void stop_services(void) @@ -2980,6 +2981,7 @@ void stop_services(void) #ifdef TCONFIG_IRQBALANCE stop_irqbalance(); #endif + stop_upnp(); } /* nvram "action_service" is: "service-action[-modifier]" @@ -3284,11 +3286,14 @@ TOP: if (strcmp(service, "upgrade") == 0) { if (act_start) { + if (nvram_get_int("webmon_bkp")) + xstart("/usr/sbin/webmon_bkp", "hourly"); /* make a copy before upgrade */ + nvram_set("g_upgrade", "1"); stop_sched(); stop_cron(); #ifdef TCONFIG_USB - stop_nas_services(); /* Samba, FTP and Media Server */ + restart_nas_services(1, 0); /* Samba, FTP and Media Server */ #endif #ifdef TCONFIG_ZEBRA stop_zebra(); @@ -3317,10 +3322,8 @@ TOP: killall("udhcpc", SIGTERM); stop_wan(); } - else { + else stop_ntpd(); - stop_upnp(); - } #ifdef TCONFIG_MDNS stop_mdns(); #endif diff --git a/release/src-rt-6.x.4708/router/rc/tinc.c b/release/src-rt-6.x.4708/router/rc/tinc.c index 3c4b7d827f..4a2c8a046a 100644 --- a/release/src-rt-6.x.4708/router/rc/tinc.c +++ b/release/src-rt-6.x.4708/router/rc/tinc.c @@ -36,7 +36,7 @@ static void tinc_setup_watchdog(void) if ((fp = fopen(buffer, "w"))) { fprintf(fp, "#!/bin/sh\n" - "[ -z $(pidof tincd) ] && {\n" + "[ -z \"$(pidof tincd)\" -a \"$(nvram get g_upgrade)\" != \"1\" -a \"$(nvram get g_reboot)\" != \"1\" ] && {\n" " service tinc restart\n" "}\n"); fclose(fp);