smart-reboot: add network-idle aware scheduled reboot utility#28586
smart-reboot: add network-idle aware scheduled reboot utility#28586minicom365 wants to merge 6 commits intoopenwrt:masterfrom
Conversation
55b9b80 to
31b0d1e
Compare
Add smart-reboot package for scheduled reboot when monitored interfaces are idle. - Introduce UCI config and init integration - Run check at configured HH:MM via cron - Reboot only if sampled traffic delta is below threshold - Auto-enable and restart service after install Signed-off-by: Minicom Developer <3387910@naver.com>
31b0d1e to
a8cda07
Compare
Rewrite /usr/sbin/smart-reboot-check from shell to ucode as suggested in review. - Keep existing behavior and configuration semantics - Preserve locking, idle traffic sampling and reboot decision logic - Keep last_auto_reboot update before reboot - Add runtime dependency on ucode - Bump PKG_RELEASE to 4 Signed-off-by: minicom365 <3387910@naver.com>
|
Thanks for the suggestion. I rewrote Changes included:
Please take another look when you have time. 감사합니다. |
| let sample_seconds = int(cfg_get("sample_seconds", "120")); | ||
| let byte_threshold = int(cfg_get("byte_threshold", "262144")); | ||
| let all_ifaces = cfg_get("all_ifaces", "0"); | ||
| let ifaces = parse_ifaces(cmd_out(`uci -q get ${CFG}.${SECTION}.ifaces`)); |
| function cfg_get(key, def) { | ||
| let val = cmd_out(`uci -q get ${CFG}.${SECTION}.${key}`); | ||
| return length(val) ? val : def; | ||
| } |
| ifaces = list_all_ifaces(); | ||
| } | ||
| else if (!length(ifaces)) { | ||
| let wan_dev = cmd_out("uci -q get network.wan.device"); |
| let delta = end_bytes - start_bytes; | ||
|
|
||
| if (delta <= byte_threshold) { | ||
| logger(`Network idle detected (delta=${delta} bytes, threshold=${byte_threshold}), rebooting now`); |
| system("/sbin/reboot"); | ||
| } | ||
| else { | ||
| logger(`Skip reboot, network is active (delta=${delta} bytes, threshold=${byte_threshold})`); |
| SECTION:=utils | ||
| CATEGORY:=Utilities | ||
| TITLE:=Smart reboot based on network idle state | ||
| DEPENDS:=+busybox +uci +ucode |
There was a problem hiding this comment.
Formatting is off here
| /etc/config/smart-reboot | ||
| endef | ||
|
|
||
| define Build/Compile |
There was a problem hiding this comment.
I think add a true here can prevent warning
|
Applied follow-up review updates and force-pushed. Latest commit:
Thanks again for the detailed feedback. |
| let wan_dev = cursor.get("network", "wan", "device"); | ||
| if (length(wan_dev)) | ||
| ifaces = [ wan_dev ]; | ||
| } |
There was a problem hiding this comment.
does it have to be the wan device?
Some users have multiple wan, so making this configurable is a good idea.
Address review comments by using ucode modules directly. - Use uci module instead of shelling out to uci commands - Use log module instead of logger command - Keep behavior unchanged (lock, sampling, threshold, reboot) - Add required ucode module dependencies - Make Build/Compile explicitly no-op with true - Fix Makefile formatting Signed-off-by: minicom365 <3387910@naver.com>
b9d909e to
8d31c86
Compare
Do not implicitly fallback to network.wan.device when no monitored interfaces are configured. - Require explicit interface selection through settings.ifaces - Keep all_ifaces mode as before - Exit safely with a log message when no interfaces are configured Signed-off-by: minicom365 <3387910@naver.com>
|
Good point, thanks. I removed the hardcoded Latest commit: New behavior when
This should better support multi-WAN/custom setups. |
| start_service() { | ||
| [ -f "$CRON_FILE" ] || touch "$CRON_FILE" | ||
| gen_schedule | ||
| /etc/init.d/cron restart >/dev/null 2>&1 |
There was a problem hiding this comment.
is a restart necessary or does a reload work just as well?
There was a problem hiding this comment.
cron restart is not strictly necessary; reload is sufficient and less disruptive when supported. Updated to prefer reload and fall back to restart if reload is unavailable/fails.
Use cron reload when available after updating /etc/crontabs/root. Fallback to a full cron restart if reload is not supported or fails. Signed-off-by: 최민 <3387910@naver.com>
| function main() { | ||
| log.openlog("smart-reboot", log.LOG_PID); | ||
|
|
||
| if (system(`lock -n ${LOCK_FILE} >/dev/null 2>&1`) != 0) |
There was a problem hiding this comment.
ucode has a lock function:
|
|
||
| let enabled = cfg_get("enabled", "0"); | ||
| if (enabled != "1") { | ||
| system(`lock -u ${LOCK_FILE}`); |
There was a problem hiding this comment.
|
|
||
| let now = localtime(time()); | ||
| if (now.hour != hour || now.min != minute) { | ||
| system(`lock -u ${LOCK_FILE}`); |
There was a problem hiding this comment.
| logger(`Skip reboot, network is active (delta=${delta} bytes, threshold=${byte_threshold})`); | ||
| } | ||
|
|
||
| system(`lock -u ${LOCK_FILE}`); |
There was a problem hiding this comment.
| } | ||
|
|
||
| let start_bytes = sum_iface_bytes(ifaces); | ||
| system(`sleep ${sample_seconds}`); |
There was a problem hiding this comment.
| } | ||
| else if (!length(ifaces)) { | ||
| logger("No monitored interfaces configured. Set smart-reboot.settings.ifaces or enable all_ifaces."); | ||
| system(`lock -u ${LOCK_FILE}`); |
There was a problem hiding this comment.
Apply review suggestions to avoid external sleep and lock commands. Signed-off-by: 최민 <3387910@naver.com>
This adds
smart-reboot, a lightweight OpenWrt utility that performs scheduled reboot only when monitored interfaces are considered idle.Features
/etc/config/smart-reboot)HH:MMTesting
ipq806x/genericarm_cortex-a15_neon-vfpv4Notes
Signed-off-by: minicom365 3387910@naver.com