From bd233d5d239c5c7e690111982770d610565de4e7 Mon Sep 17 00:00:00 2001 From: Ilario Gelmetti Date: Tue, 31 Dec 2024 09:53:25 +0100 Subject: [PATCH] deferable-reboot move cron command to file --- .../files/etc/uci-defaults/90-cron-defer-reboot | 3 +-- .../files/usr/bin/deferable-reboot-check | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100755 packages/deferable-reboot/files/usr/bin/deferable-reboot-check diff --git a/packages/deferable-reboot/files/etc/uci-defaults/90-cron-defer-reboot b/packages/deferable-reboot/files/etc/uci-defaults/90-cron-defer-reboot index bb14c3cb5..9523dedc1 100644 --- a/packages/deferable-reboot/files/etc/uci-defaults/90-cron-defer-reboot +++ b/packages/deferable-reboot/files/etc/uci-defaults/90-cron-defer-reboot @@ -6,6 +6,5 @@ unique_append() } unique_append \ - "*/3 * * * * ((sleep $((RANDOM % 120)); if ping -c 10 -W 10 \$(uci -q get lime-autogen.system.deferable_reboot_ping_target) &> /dev/null; then awk '{print \$1 + 1800}' /proc/uptime > /tmp/deferable-reboot.defer ; fi )&) "\ - /etc/crontabs/root + "*/3 * * * * ((sleep $((RANDOM % 120)); /usr/bin/deferable-reboot-check )&)" /etc/crontabs/root diff --git a/packages/deferable-reboot/files/usr/bin/deferable-reboot-check b/packages/deferable-reboot/files/usr/bin/deferable-reboot-check new file mode 100755 index 000000000..85b5187a0 --- /dev/null +++ b/packages/deferable-reboot/files/usr/bin/deferable-reboot-check @@ -0,0 +1,17 @@ +#!/bin/sh + +uci_config_path="lime-autogen.system.deferable_reboot_ping_target" +target=$(uci -q get $uci_config_path &> /dev/null) + +if [ -n "$target" ]; then + if ping -c 10 -W 10 $target; then + action=defer + fi +else + echo "deferable-reboot: Could not get the ping target from UCI $uci_config_path, deferring anyway" + action=defer +fi + +if [ "$action" == "defer" ]; then + awk '{print $1 + 1800}' /proc/uptime > /tmp/deferable-reboot.defer +fi