Recovery: reindex interrupted sessions and fix packet counts; actionable AP activation error

This commit is contained in:
Andy Dixon
2026-10-09 18:22:56 +01:00
parent 43cbcc4076
commit d8bfcee2fc
4 changed files with 72 additions and 4 deletions
+1 -1
View File
@@ -309,7 +309,7 @@ func activate(ctx context.Context, n config.Network, files map[string][]byte, st
}
if n.AP.Enabled {
if _, err := run(ctx, 60*time.Second, "nmcli", "--wait", "45", "connection", "up", netgen.ConnName); err != nil {
return err
return fmt.Errorf("the access point did not start. Likely causes: the band/channel is not permitted for country %s or not supported by this radio, or the radio does not support %s in AP mode (%w)", n.AP.Country, strings.ToUpper(n.AP.Security), err)
}
step("access point %q activated", n.AP.SSID)
if _, err := run(ctx, 30*time.Second, "systemctl", "restart", "pilens-dnsmasq.service"); err != nil {
+14 -2
View File
@@ -130,7 +130,9 @@ func serve(args []string) error {
lim := capture.DefaultLimits()
db.GetJSON("capture_limits", &lim)
eng.SetLimits(lim)
recoverSessions(db, *caps)
for _, id := range recoverSessions(db, *caps) {
go eng.Reindex(id)
}
cert, fp, err := ensureCert(*data)
if err != nil {
@@ -178,7 +180,8 @@ func serve(args []string) error {
}
// recoverSessions finalises sessions left running by a crash or power loss.
func recoverSessions(db *store.Store, dir string) {
// It returns the IDs of the sessions it marked interrupted.
func recoverSessions(db *store.Store, dir string) (ids []string) {
rows, err := db.Query(`SELECT s.id, g.seq, g.file, g.format FROM segments g JOIN capture_sessions s ON s.id=g.session_id WHERE g.complete=0 AND g.deleted=0`)
if err == nil {
type seg struct {
@@ -216,7 +219,16 @@ func recoverSessions(db *store.Store, dir string) {
slog.Warn("recovered interrupted segment", "session", s.id, "segment", s.seq, "packets", n, "truncated_tail", scanErr != nil)
}
}
if r, err := db.Query(`SELECT id FROM capture_sessions WHERE state IN ('running','importing')`); err == nil {
for r.Next() {
var id string
r.Scan(&id)
ids = append(ids, id)
}
r.Close()
}
db.Exec(`UPDATE capture_sessions SET state='failed', error='interrupted: the service stopped unexpectedly (power loss or crash); segments were finalised on restart and summaries may be incomplete', ended_at=? WHERE state IN ('running','importing')`, time.Now().UnixMilli())
return ids
}
func sdNotify(state string) {