feat(agent): add crash logs and watchdog startup

- Recover panics to disk for diagnostics
- Add 5-minute watchdog task with startup
- Add -ensure flag to start detached agent
- Add script to pull remote folder via API
This commit is contained in:
2026-09-01 20:04:20 +03:00
parent 2ce438852a
commit 36cb847f9e
11 changed files with 458 additions and 8 deletions
+20 -4
View File
@@ -13,33 +13,49 @@ import (
"flag"
"tea.chunkbyte.com/kato/go-worm/lib/agent"
"tea.chunkbyte.com/kato/go-worm/lib/crashlog"
"tea.chunkbyte.com/kato/go-worm/lib/helpers"
"tea.chunkbyte.com/kato/go-worm/lib/install"
"tea.chunkbyte.com/kato/go-worm/lib/instance"
)
func main() {
defer crashlog.Recover()
background := flag.Bool("background", false, "run without a console window")
ensure := flag.Bool("ensure", false, "start the agent if it is not already running")
flag.Parse()
if err := install.Ensure(); err != nil {
helpers.Log.Fatalf("install: %v", err)
die(err)
}
if *ensure {
if err := instance.EnsureRunning(); err != nil {
die(err)
}
return
}
if *background {
if err := instance.Detach(); err != nil {
helpers.Log.Fatalf("%v", err)
die(err)
}
return
}
a, err := agent.New()
if err != nil {
helpers.Log.Fatalf("%v", err)
die(err)
}
defer a.Close()
if err := a.Serve(); err != nil {
helpers.Log.Fatalf("%v", err)
die(err)
}
}
func die(err error) {
crashlog.RecordError(err)
helpers.Log.Fatal(err)
}