Skip to content

Commit b4894e1

Browse files
committed
smart-reboot: add network-idle aware scheduled reboot utility
Add smart-reboot, a lightweight OpenWrt utility that performs scheduled reboot during a dawn time window when network traffic is idle. - UCI-based configuration (/etc/config/smart-reboot) - Procd-managed uloop background daemon - Dawn time window with periodic retry on active traffic - Atomic /proc/net/dev telemetry and dynamic ubus L3 device resolution - Failsafe guards (NTP sync, system uptime, and single daily reboot) Signed-off-by: Min Choi <3387910@naver.com>
1 parent f901d88 commit b4894e1

4 files changed

Lines changed: 401 additions & 0 deletions

File tree

‎utils/smart-reboot/Makefile‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
include $(TOPDIR)/rules.mk
2+
3+
PKG_NAME:=smart-reboot
4+
PKG_VERSION:=1
5+
PKG_RELEASE:=1
6+
7+
PKG_MAINTAINER:=Min Choi <3387910@naver.com>
8+
PKG_LICENSE:=GPL-2.0-only
9+
PKG_LICENSE_FILES:=LICENSE
10+
11+
include $(INCLUDE_DIR)/package.mk
12+
13+
define Package/smart-reboot
14+
SECTION:=utils
15+
CATEGORY:=Utilities
16+
TITLE:=Smart reboot based on network idle state
17+
DEPENDS:=+ucode +ucode-mod-uci +ucode-mod-log +ucode-mod-fs +ucode-mod-ubus +ucode-mod-uloop
18+
PKGARCH:=all
19+
endef
20+
21+
define Package/smart-reboot/description
22+
Reboot router at configured dawn time window only when monitored interfaces are idle.
23+
endef
24+
25+
define Package/smart-reboot/conffiles
26+
/etc/config/smart-reboot
27+
endef
28+
29+
define Build/Compile
30+
endef
31+
32+
define Package/smart-reboot/install
33+
$(INSTALL_DIR) $(1)/etc/config
34+
$(INSTALL_CONF) ./files/smart-reboot.config $(1)/etc/config/smart-reboot
35+
36+
$(INSTALL_DIR) $(1)/etc/init.d
37+
$(INSTALL_BIN) ./files/smart-reboot.init $(1)/etc/init.d/smart-reboot
38+
39+
$(INSTALL_DIR) $(1)/usr/sbin
40+
$(INSTALL_BIN) ./files/smart-reboot.uc $(1)/usr/sbin/smart-reboot
41+
endef
42+
43+
$(eval $(call BuildPackage,smart-reboot))
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
config settings 'settings'
2+
option enabled '0'
3+
option window_start '03:00'
4+
option window_end '06:00'
5+
option check_interval '300'
6+
option sample_seconds '60'
7+
option threshold_kb '256'
8+
option last_auto_reboot ''
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/sh /etc/rc.common
2+
3+
START=95
4+
STOP=10
5+
USE_PROCD=1
6+
7+
PROG="/usr/sbin/smart-reboot"
8+
9+
start_service() {
10+
config_load smart-reboot
11+
local enabled
12+
config_get enabled settings enabled '0'
13+
[ "$enabled" = "1" ] || return 0
14+
15+
procd_open_instance "smart-reboot"
16+
procd_set_param command "$PROG"
17+
procd_set_param respawn 3600 5 0
18+
procd_set_param stdout 1
19+
procd_set_param stderr 1
20+
procd_set_param pidfile /var/run/smart-reboot.pid
21+
procd_close_instance
22+
}
23+
24+
service_triggers() {
25+
procd_add_reload_trigger "smart-reboot"
26+
}

0 commit comments

Comments
 (0)