Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/modules/proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
| 导入 | 分享链接(ss / vless / vmess / trojan / hysteria2 / hy2 / tuic / anytls / socks / http(s))和 base64 订阅,先预览再添加 |
| DNS | fake-ip:代理域名只由代理服务器端解析,本地和运营商 DNS 看不到 |
| 透明代理 | nftables `tproxy`(TCP + UDP,IPv4 + IPv6),只接管目标在代理集合里的连接 |
| 常驻内存 | sing-box:只用 SS 时 arm64 精简构建实测 RSS 约 43 MB;CI 里 amd64 官方完整构建(含 tailscale / cloudflared 等无关代码)只用 SS 约 67 MB,每种协议都跑过流量后约 77 MB(`GOMEMLIMIT=48MiB` 软上限,`GOGC=50`)。第二个 dnsmasq 约 5 MB(cache 8000) |
| 常驻内存 | sing-box:只用 SS 时 arm64 精简构建实测 RSS 约 43 MB;CI 里 amd64 官方完整构建(含 tailscale / cloudflared 等无关代码)只用 SS 约 67 MB,每种协议都跑过流量后约 77 MB(`GOMEMLIMIT=96MiB` 软上限,高于有流量时的用量——上限低于实际堆大小时 GC 会不停运行,白白耗 CPU;`GOGC=50`)。第二个 dnsmasq 约 5 MB(cache 8000) |
| 闪存 | sing-box 二进制由固件(platform)决定;`mr` 本轮再增加约 192 KB(arm64 5.31 → 5.51 MB) |
| 关闭时 | `proxy.enabled: false`:没有 nft 链、没有服务、没有 DNS 改动 |

Expand Down
2 changes: 1 addition & 1 deletion docs/modules/sys.md
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ boot) are the ones a RAM log loses. Types and where they come from:
| `apply` / `rollback` | `history.go` `setResult`: a change applied / confirmed, rolled back (and why) | info / warn |
| `login_lock` | the login throttle (`api_login.go`, web UI passwords and API tokens) locked a source | warn |
| `new_device` | `mr event tick`: a DHCPv4 client whose MAC was never seen (`dhcp.hosts` count as known). The list of seen MACs is on flash (`devices.seen`, newest 2048, appended; a reboot reports nothing); the first day after it is created only learns (the lease file is in RAM, the house's devices come back one by one). At most 5 per scan one by one, the rest in one line. Host names come from the network: cleaned, capped | info |
| `boot` / `upgrade` | `mr event boot` (mr-bootlog, the last boot service): clean restart (a mark written by `mr event shutdown` when OpenRC stops the system — reboot and power-off both run the shutdown runlevel; a restart of the service writes none, and a mark of the running boot is dropped; the reason from the change log, e.g. `schedule: reboot`; the downtime once NTP agrees), kernel crash (a new ramoops record in `/sys/fs/pstore`), new firmware (the kexec upgrade leaves no mark), otherwise unexpected restart (power cut, hang, hardware watchdog). A mark left by an older boot is ignored | info / warn |
| `boot` / `upgrade` | `mr event boot` (mr-bootlog, the last boot service): clean restart (a mark written by `mr event shutdown` when OpenRC stops the system — reboot and power-off both run the shutdown runlevel; a restart of the service writes none, and a mark of the running boot is dropped; the reason from the change log, e.g. `schedule: reboot`; the downtime once NTP agrees), kernel crash (a new ramoops record in `/sys/fs/pstore`), sysupgrade (it marks its stop before the kexec, which skips OpenRC, and ends the PPPoE sessions first: `clean restart (sysupgrade)` plus an `upgrade` event when the version changed), otherwise unexpected restart (power cut, hang, hardware watchdog). A mark left by an older boot is ignored | info / warn |
| `doctor` | the background `mr doctor` run: a finding that is new or worse since the last run, and "fine again". Standing choices and moments of an apply (`ssh` password logins, `offload: off`, `config.unapplied`, a change waiting for confirmation) are left out; the state is in `/run` (a reboot reports what is still wrong once more) | warn / risk / info |
| `ddns` | `mr ddns sync` (see "DDNS"): records written with a new address, a record failing 3 times in a row or refused, and working again | info / warn |
| `wifi` | the wifi module's self-heal (`wifi.self_heal`, `mr wifi tick`, see `docs/modules/wifi.md`): a radio's TX stalled with stations associated — firmware recovery triggered, hostapd restarted, gave up (no automatic reboot) — and TX moving again | warn / risk / info |
Expand Down
13 changes: 9 additions & 4 deletions mr/mod_sys_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -727,12 +727,17 @@ func eventBoot(c *Config) error {
return nil
}

// eventShutdown marks a clean stop (mr-bootlog's stop while OpenRC goes down), with the reason the
// change log gives for a reboot of the last 15 minutes (schedule, web UI).
// eventShutdown marks a clean stop (mr-bootlog's stop while OpenRC goes down, and sysupgrade before its
// kexec), with the reason the change log gives for a reboot or sysupgrade of the last 15 minutes.
func eventShutdown() error {
m := shutdownMark{Time: eventNow().Unix(), BootID: eventBootID()}
if r := changeLogRecent(15 * time.Minute); len(r) > 0 && strings.Contains(r[0], "reboot") {
m.Why = eventClean(r[0], 80)
if r := changeLogRecent(15 * time.Minute); len(r) > 0 {
switch {
case strings.Contains(r[0], "sysupgrade"): // the kexec skips OpenRC: sysupgrade marks its stop itself
m.Why = "sysupgrade"
case strings.Contains(r[0], "reboot"):
m.Why = eventClean(r[0], 80)
}
}
b, _ := json.Marshal(m)
return writeAtomic(eventShutdownFile, b, 0600)
Expand Down
24 changes: 24 additions & 0 deletions mr/mod_sys_event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,3 +526,27 @@ func TestFmtSecs(t *testing.T) {
}
}
}

// sysupgrade kexecs without OpenRC: it marks its stop, so the next boot is a planned restart (also with
// the same version: a rebuilt release), not an unexpected one (#105).
func TestEventBootAfterSysupgrade(t *testing.T) {
_, now, _, _ := eventEnv(t)
c := testConfig(t)
version = "v1"
boot := func(id string) event {
t.Helper()
eventBootID = func() string { return id }
if err := eventBoot(c); err != nil {
t.Fatal(err)
}
ev := eventsRead(0, 0)
return ev[len(ev)-1]
}
boot("b1")
appendChangeLogAt(*now, "sysupgrade: installing mini-router v1 (kexec)")
eventShutdown()
*now = now.Add(2 * time.Minute)
if e := boot("b2"); e.Sev != "info" || !strings.HasPrefix(e.Msg, "booted after a clean restart (sysupgrade)") {
t.Errorf("same-version sysupgrade: %+v", e)
}
}
4 changes: 3 additions & 1 deletion rootfs/etc/init.d/dstatus-agent
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ description="DStatus probe agent"
supervisor=supervise-daemon
command=/usr/bin/dstatus-agent
command_args="-c /etc/dstatus-agent/config.yaml"
supervise_daemon_args="--env GOGC=50 --env GOMEMLIMIT=8MiB"
# GOMEMLIMIT is a soft heap limit: below the live heap (~10 MB) the GC runs nonstop — 8MiB cost 81% of a
# core on the AX6000, 32MiB 7% at the same RSS
supervise_daemon_args="--env GOGC=50 --env GOMEMLIMIT=32MiB"
respawn_delay=10
# a crash loop stops after 10 respawns in 10 minutes: mr doctor reports it, mr doctor --heal restarts it
respawn_max=10
Expand Down
4 changes: 3 additions & 1 deletion rootfs/etc/init.d/mr-proxy
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ supervisor=supervise-daemon
command=/usr/bin/sing-box
# --disable-color: sing-box colours its log even when stdout is not a terminal (escape codes in syslog)
command_args="run --disable-color -c /run/mr-proxy/config.json -c /run/mr-proxy/api.json -D /run/mr-proxy"
supervise_daemon_args="--env GOGC=50 --env GOMEMLIMIT=48MiB"
# soft heap limit above the working set under load (~77 MB RSS with traffic on every protocol): at or below it
# the GC runs nonstop and costs CPU instead of saving memory
supervise_daemon_args="--env GOGC=50 --env GOMEMLIMIT=96MiB"
output_logger="logger -t sing-box -p daemon.info"
error_logger="logger -t sing-box -p daemon.notice"
respawn_delay=2
Expand Down
2 changes: 1 addition & 1 deletion rootfs/etc/init.d/tailscale
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ command=/usr/sbin/tailscaled
# TS_PORT: services.tailscale.port, from /etc/conf.d/tailscale (rendered by mr; the firewall opens
# the same UDP port on the WANs)
command_args="--port ${TS_PORT:-41641} --state /etc/tailscale/tailscaled.state"
supervise_daemon_args="--env TS_DEBUG_FIREWALL_MODE=nftables --env GOGC=50 --env GOMEMLIMIT=24MiB"
supervise_daemon_args="--env TS_DEBUG_FIREWALL_MODE=nftables --env GOGC=50 --env GOMEMLIMIT=48MiB"
respawn_delay=5
# a crash loop stops after 10 respawns in 10 minutes: mr doctor reports it, mr doctor --heal restarts it
respawn_max=10
Expand Down
6 changes: 6 additions & 0 deletions rootfs/usr/libexec/mr/sysupgrade
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,12 @@ kexec_installer() {
rm -f "$WORK/Image" "$WORK/initrd.cpio"
logger -t sysupgrade "installing mini-router $version via kexec" 2>/dev/null
echo "$(date '+%Y-%m-%d %H:%M:%S') sysupgrade: installing mini-router $version (kexec)" >> /etc/router-changes.log
# no OpenRC shutdown: end the PPPoE sessions (LCP terminate + PADT — else the ISP takes the new
# system's first session for a duplicate and hangs it up) and mark a planned stop for the boot event
for s in /etc/init.d/mr-pppoe.*; do
[ -e "$s" ] && rc-service --ifstarted "${s##*/}" stop > /dev/null 2>&1
done
/usr/sbin/mr event shutdown > /dev/null 2>&1
# mt76 keeps DMA-writing RX buffers after kexec into memory the new kernel (installer) reuses:
# stop WiFi and unload the driver first (the installer never loads it; the reboot brings it back)
rc-service --ifstarted mr-hostapd stop > /dev/null 2>&1
Expand Down
Loading