<commit_before>local utils = require "lime.utils"
local config = require "lime.config"

local defreboot = {}

defreboot.DEFAULT_REBOOT_UPTIME = 60*60*7
defreboot.SLEEP_BEFORE_REBOOT_S = 30

defreboot.POSTPONE_FILE_PATH = '/tmp/deferable-reboot.defer'

function defreboot.config(min_uptime)
	if min_uptime == nil then
		min_uptime = tonumber(config.get("system", "deferable_reboot_uptime",
										 defreboot.DEFAULT_REBOOT_UPTIME))
	end
	assert(type(min_uptime) == "number", "min_uptime must be a number")
	defreboot.min_uptime = min_uptime
end

function defreboot.should_reboot()
	local uptime_s = utils.uptime_s()
	local postpone_until_s = defreboot.read_postpone_file()
	local min_uptime = defreboot.min_uptime

	if (postpone_until_s ~= nil) and (postpone_until_s > min_uptime) then
		min_uptime = postpone_until_s
	end
	return uptime_s > min_uptime
end

function defreboot.postpone_util_s(uptime)
	assert(type(uptime) == "number", "uptime must be a number")
	local f = io.open(defreboot.POSTPONE_FILE_PATH, 'w')
	f:write(tostring(uptime))
	f:close()
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
function defreboot.read_postpone_file()
	local f = io.open(defreboot.POSTPONE_FILE_PATH)
	if f ~= nil then
		return tonumber(f:read("*l"))
	end
	return nil
end

function defreboot.reboot()
	--! give time to sysupgrade to kill us
	nixio.nanosleep(defreboot.SLEEP_BEFORE_REBOOT_S)
	os.execute("reboot")
end

return defreboot
<commit_msg>deferable-reboot: change minimum uptime to 27hs<commit_after>local utils = require "lime.utils"
local config = require "lime.config"

local defreboot = {}

defreboot.DEFAULT_REBOOT_UPTIME = 60*60*27
defreboot.SLEEP_BEFORE_REBOOT_S = 30

defreboot.POSTPONE_FILE_PATH = '/tmp/deferable-reboot.defer'

function defreboot.config(min_uptime)
	if min_uptime == nil then
		min_uptime = tonumber(config.get("system", "deferable_reboot_uptime",
										 defreboot.DEFAULT_REBOOT_UPTIME))
	end
	assert(type(min_uptime) == "number", "min_uptime must be a number")
	defreboot.min_uptime = min_uptime
end

function defreboot.should_reboot()
	local uptime_s = utils.uptime_s()
	local postpone_until_s = defreboot.read_postpone_file()
	local min_uptime = defreboot.min_uptime

	if (postpone_until_s ~= nil) and (postpone_until_s > min_uptime) then
		min_uptime = postpone_until_s
	end
	return uptime_s > min_uptime
end

function defreboot.postpone_util_s(uptime)
	assert(type(uptime) == "number", "uptime must be a number")
	local f = io.open(defreboot.POSTPONE_FILE_PATH, 'w')
	f:write(tostring(uptime))
	f:close()
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
function defreboot.read_postpone_file()
	local f = io.open(defreboot.POSTPONE_FILE_PATH)
	if f ~= nil then
		return tonumber(f:read("*l"))
	end
	return nil
end

function defreboot.reboot()
	--! give time to sysupgrade to kill us
	nixio.nanosleep(defreboot.SLEEP_BEFORE_REBOOT_S)
	os.execute("reboot")
end

return defreboot

{'fraction_non_alphanumeric': 0.10473502665412356, 'fraction_numerical': 0.005957980558168705, 'mean_word_length': 5.41851106639839, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7589412', 'n_tokens_mistral': 1281, 'n_tokens_neox': 1224, 'n_words': 263}