diff --git a/packages/deferable-reboot/files/etc/config/deferable-reboot b/packages/deferable-reboot/files/etc/config/deferable-reboot deleted file mode 100644 index df44de6d2..000000000 --- a/packages/deferable-reboot/files/etc/config/deferable-reboot +++ /dev/null @@ -1,3 +0,0 @@ -config deferable-reboot 'options' - #option deferable_reboot_uptime '97200' - diff --git a/packages/deferable-reboot/files/usr/bin/deferable-reboot b/packages/deferable-reboot/files/usr/bin/deferable-reboot deleted file mode 100755 index 70e0b6a0c..000000000 --- a/packages/deferable-reboot/files/usr/bin/deferable-reboot +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/lua - -local defreboot = require 'deferable_reboot' - -defreboot.config() - -if defreboot.should_reboot() then - os.execute('logger -t deferable-reboot -p ALERT Rebooting in 30 seconds!') - defreboot.reboot() -end diff --git a/packages/deferable-reboot/Makefile b/packages/deferrable-reboot/Makefile similarity index 82% rename from packages/deferable-reboot/Makefile rename to packages/deferrable-reboot/Makefile index 94097d07b..45c02cde1 100644 --- a/packages/deferable-reboot/Makefile +++ b/packages/deferrable-reboot/Makefile @@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk GIT_COMMIT_DATE:=$(shell git log -n 1 --pretty=%ad --date=short . ) GIT_COMMIT_TSTAMP:=$(shell git log -n 1 --pretty=%at . ) -PKG_NAME:=deferable-reboot +PKG_NAME:=deferrable-reboot PKG_VERSION=$(GIT_COMMIT_DATE)-$(GIT_COMMIT_TSTAMP) include $(INCLUDE_DIR)/package.mk @@ -17,21 +17,21 @@ include $(INCLUDE_DIR)/package.mk define Package/$(PKG_NAME) SECTION:=utils CATEGORY:=Utilities - TITLE:=$(PKG_NAME) provides a deferable reboot. + TITLE:=$(PKG_NAME) provides a deferrable reboot. MAINTAINER:=Santiago Piccinini DEPENDS:=+lua +lime-system PKGARCH:=all endef define Package/$(PKG_NAME)/description - This $(PKG_NAME) provides a deferable reboot mechanism. The system + This $(PKG_NAME) provides a deferrable reboot mechanism. The system will be rebooted when the uptime of the system reach a specified amount - of seconds and if /tmp/deferable-reboot.defer file does not contain a + of seconds and if /tmp/deferrable-reboot.defer file does not contain a number that is greater than the current uptime. This way if anyone wants to postpone the reboot, the way is to store the next checkpoint in seconds. For example if the system must not reboot from now and up to 120 seconds in the future then something like this can be donde - awk '{print $1 + 120}' /proc/uptime > /tmp/deferable-reboot.defer + awk '{print $1 + 120}' /proc/uptime > /tmp/deferrable-reboot.defer endef define Build/Configure diff --git a/packages/deferrable-reboot/files/etc/config/deferrable-reboot b/packages/deferrable-reboot/files/etc/config/deferrable-reboot new file mode 100644 index 000000000..4bff11507 --- /dev/null +++ b/packages/deferrable-reboot/files/etc/config/deferrable-reboot @@ -0,0 +1,3 @@ +config deferrable-reboot 'options' + #option deferrable_reboot_uptime '97200' + diff --git a/packages/deferrable-reboot/files/etc/uci-defaults/90-cron-defer-reboot b/packages/deferrable-reboot/files/etc/uci-defaults/90-cron-defer-reboot new file mode 100644 index 000000000..9523dedc1 --- /dev/null +++ b/packages/deferrable-reboot/files/etc/uci-defaults/90-cron-defer-reboot @@ -0,0 +1,10 @@ +#!/bin/sh + +unique_append() +{ + grep -qF "$1" "$2" || echo "$1" >> "$2" +} + +unique_append \ + "*/3 * * * * ((sleep $((RANDOM % 120)); /usr/bin/deferable-reboot-check )&)" /etc/crontabs/root + diff --git a/packages/deferable-reboot/files/etc/uci-defaults/deferable-reboot-cron b/packages/deferrable-reboot/files/etc/uci-defaults/deferrable-reboot-cron similarity index 67% rename from packages/deferable-reboot/files/etc/uci-defaults/deferable-reboot-cron rename to packages/deferrable-reboot/files/etc/uci-defaults/deferrable-reboot-cron index 53faaf926..a164d6b97 100755 --- a/packages/deferable-reboot/files/etc/uci-defaults/deferable-reboot-cron +++ b/packages/deferrable-reboot/files/etc/uci-defaults/deferrable-reboot-cron @@ -6,5 +6,5 @@ unique_append() } unique_append \ - '*/1 * * * * ((deferable-reboot &> /dev/null)&)'\ + '*/1 * * * * ((deferrable-reboot &> /dev/null)&)'\ /etc/crontabs/root diff --git a/packages/deferrable-reboot/files/usr/bin/deferrable-reboot b/packages/deferrable-reboot/files/usr/bin/deferrable-reboot new file mode 100755 index 000000000..5e73ddeab --- /dev/null +++ b/packages/deferrable-reboot/files/usr/bin/deferrable-reboot @@ -0,0 +1,10 @@ +#!/usr/bin/lua + +local defreboot = require 'deferrable_reboot' + +defreboot.config() + +if defreboot.should_reboot() then + os.execute('logger -t deferrable-reboot -p ALERT Rebooting in 30 seconds!') + defreboot.reboot() +end diff --git a/packages/deferrable-reboot/files/usr/bin/deferrable-reboot-check b/packages/deferrable-reboot/files/usr/bin/deferrable-reboot-check new file mode 100755 index 000000000..7f273c6ff --- /dev/null +++ b/packages/deferrable-reboot/files/usr/bin/deferrable-reboot-check @@ -0,0 +1,17 @@ +#!/bin/sh + +uci_config_path="lime-autogen.system.deferrable_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 "deferrable-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/deferrable-reboot.defer +fi diff --git a/packages/deferable-reboot/files/usr/lib/lua/deferable_reboot.lua b/packages/deferrable-reboot/files/usr/lib/lua/deferrable_reboot.lua similarity index 84% rename from packages/deferable-reboot/files/usr/lib/lua/deferable_reboot.lua rename to packages/deferrable-reboot/files/usr/lib/lua/deferrable_reboot.lua index 1fc1fa39b..b5296b8bc 100644 --- a/packages/deferable-reboot/files/usr/lib/lua/deferable_reboot.lua +++ b/packages/deferrable-reboot/files/usr/lib/lua/deferrable_reboot.lua @@ -6,13 +6,13 @@ local defreboot = {} defreboot.DEFAULT_REBOOT_UPTIME = 60*60*27 defreboot.SLEEP_BEFORE_REBOOT_S = 30 -defreboot.POSTPONE_FILE_PATH = '/tmp/deferable-reboot.defer' +defreboot.POSTPONE_FILE_PATH = '/tmp/deferrable-reboot.defer' function defreboot.config(min_uptime) if min_uptime == nil then local uci = config.get_uci_cursor() - local lime_min_uptime = config.get("system", "deferable_reboot_uptime_s", false) - local general_min_uptime = uci:get("deferable-reboot", "options", "deferable_reboot_uptime_s") + local lime_min_uptime = config.get("system", "deferrable_reboot_uptime_s", false) + local general_min_uptime = uci:get("deferrable-reboot", "options", "deferrable_reboot_uptime_s") min_uptime = tonumber(lime_min_uptime or general_min_uptime or defreboot.DEFAULT_REBOOT_UPTIME) end assert(type(min_uptime) == "number", "min_uptime must be a number") @@ -39,7 +39,7 @@ end --! use this function to postpone the reboot, also the following command can be used ---! replacing SECONDS: # awk '{print $1 + SECONDS}' /proc/uptime > /tmp/deferable-reboot.defer +--! replacing SECONDS: # awk '{print $1 + SECONDS}' /proc/uptime > /tmp/deferrable-reboot.defer function defreboot.read_postpone_file() local f = io.open(defreboot.POSTPONE_FILE_PATH) if f ~= nil then diff --git a/packages/deferable-reboot/tests/test_deferable_reboot.lua b/packages/deferrable-reboot/tests/test_deferrable_reboot.lua similarity index 74% rename from packages/deferable-reboot/tests/test_deferable_reboot.lua rename to packages/deferrable-reboot/tests/test_deferrable_reboot.lua index eae4a1032..87568e7a5 100644 --- a/packages/deferable-reboot/tests/test_deferable_reboot.lua +++ b/packages/deferrable-reboot/tests/test_deferrable_reboot.lua @@ -1,10 +1,10 @@ local config = require "lime.config" local test_utils = require 'tests.utils' -local defreboot = require 'deferable_reboot' +local defreboot = require 'deferrable_reboot' local uci = nil -describe('Deferable Reboot tests #defreboot', function() +describe('Deferrable Reboot tests #defreboot', function() it('test load config from lime.config default value', function() defreboot.config() @@ -13,25 +13,25 @@ describe('Deferable Reboot tests #defreboot', function() it('test load config from lime.config', function() config.set('system', 'lime') - config.set('system', 'deferable_reboot_uptime_s', '120') + config.set('system', 'deferrable_reboot_uptime_s', '120') defreboot.config() assert.is.equal(120, defreboot.min_uptime) end) - it('test load config from config/deferable-reboot', function() - uci:set('deferable-reboot', 'options', 'deferable-reboot') - uci:set('deferable-reboot', 'options', 'deferable_reboot_uptime_s', '99') - uci:commit('deferable-reboot') + it('test load config from config/deferrable-reboot', function() + uci:set('deferrable-reboot', 'options', 'deferrable-reboot') + uci:set('deferrable-reboot', 'options', 'deferrable_reboot_uptime_s', '99') + uci:commit('deferrable-reboot') defreboot.config() assert.is.equal(99, defreboot.min_uptime) end) - it('test lime.config has precedence over config/deferable-reboot ', function() + it('test lime.config has precedence over config/deferrable-reboot ', function() config.set('system', 'lime') - config.set('system', 'deferable_reboot_uptime_s', '120') - uci:set('deferable-reboot', 'options', 'deferable-reboot') - uci:set('deferable-reboot', 'options', 'deferable_reboot_uptime_s', '99') - uci:commit('deferable-reboot') + config.set('system', 'deferrable_reboot_uptime_s', '120') + uci:set('deferrable-reboot', 'options', 'deferrable-reboot') + uci:set('deferrable-reboot', 'options', 'deferrable_reboot_uptime_s', '99') + uci:commit('deferrable-reboot') defreboot.config() assert.is.equal(120, defreboot.min_uptime) end) diff --git a/packages/lime-docs/files/www/docs/lime-example.txt b/packages/lime-docs/files/www/docs/lime-example.txt index 15659d107..e57047353 100644 --- a/packages/lime-docs/files/www/docs/lime-example.txt +++ b/packages/lime-docs/files/www/docs/lime-example.txt @@ -21,7 +21,8 @@ config lime system option keep_on_upgrade 'libremesh dropbear minimum-essential /etc/sysupgrade.conf' # Files defining the list of files and directories to backup when upgrade. Relative to /lib/upgrade/keep.d if no '/' defined. option root_password_policy 'DO_NOTHING' # When configured to SET_SECRET, the root password secret will be configured as specified in root_password_secret. When set to RANDOM a strong random password will be set if root has no password, use this if your firmware is built with the ssh keys inside. DO_NOTHING does nothing, leaving the root password empty (you will have to set it manually or through FirstBootWizard). option root_password_secret '' # This is the password hash as stored in /etc/shadow, it is only used when root_password_policy=SET_SECRET. You can generate the secret with 'openssl passwd -1' to be compatible with most openwrt firmwares, use a strong password with at least 10 numbers and letters, the longer the better!. For improved security use "openssl passwd -6" for SHA512 (or -5 for SHA256) but be aware that not all firmwares support this. - option deferable_reboot_uptime_s '97200' + option deferrable_reboot_uptime_s '97200' + option deferrable_reboot_ping_target '4.2.2.2' # b.resolvers.Level3.net # the reboot scheduled by deferrable_reboot, if installed, will be deferred if the ping to this IP is succesful option firstbootwizard_configured false option firstbootwizard_dismissed false # When true fbw banner will be hidden. diff --git a/packages/lime-system/files/etc/config/lime-defaults b/packages/lime-system/files/etc/config/lime-defaults index 5f5c4a31f..922b8db3a 100644 --- a/packages/lime-system/files/etc/config/lime-defaults +++ b/packages/lime-system/files/etc/config/lime-defaults @@ -11,7 +11,8 @@ config lime system option keep_on_upgrade 'libremesh dropbear minimum-essential /etc/sysupgrade.conf' option root_password_policy 'DO_NOTHING' option root_password_secret '' - option deferable_reboot_uptime_s '97200' + option deferrable_reboot_uptime_s '97200' + option deferrable_reboot_ping_target '4.2.2.2' option firstbootwizard_configured false option firstbootwizard_dismissed false diff --git a/packages/safe-upgrade/files/usr/sbin/safe-upgrade b/packages/safe-upgrade/files/usr/sbin/safe-upgrade index 34a07fd66..1be358b39 100755 --- a/packages/safe-upgrade/files/usr/sbin/safe-upgrade +++ b/packages/safe-upgrade/files/usr/sbin/safe-upgrade @@ -327,7 +327,7 @@ local function upgrade(args) su.preserve_files_to_new_partition(args) -- postpone 10m defarable-reboot - os.execute("awk '{print $1 + 600}' /proc/uptime > /tmp/deferable-reboot.defer") + os.execute("awk '{print $1 + 600}' /proc/uptime > /tmp/deferrable-reboot.defer") print(string.format("erasing partition %d", partitions.other)) os.execute(string.format("mtd erase fw%d", partitions.other)) diff --git a/tests/utils.lua b/tests/utils.lua index ed64806fa..ae1a81a9e 100644 --- a/tests/utils.lua +++ b/tests/utils.lua @@ -11,7 +11,7 @@ UCI_CONFIG_FILES = { "6relayd", "babeld", "batman-adv", "check-date", "dhcp", "dropbear", "fstab", "firewall", "libremap", "lime", "lime-app", "location", "luci", "network", "pirania", "rpcd", "shared-state", "system", "ucitrack", - "uhttpd", "wireless", "deferable-reboot", config.UCI_AUTOGEN_NAME, config.UCI_NODE_NAME, + "uhttpd", "wireless", "deferrable-reboot", config.UCI_AUTOGEN_NAME, config.UCI_NODE_NAME, config.UCI_COMMUNITY_NAME, config.UCI_DEFAULTS_NAME }