*
Jes Olson j3s@c3f.net
Mon, 09 Dec 2024 14:51:10 -0500
3 files changed,
30 insertions(+),
23 deletions(-)
M
main.go
→
main.go
@@ -7,11 +7,6 @@
"j3s.sh/gore/internal/assets" ) -var ( - buildTimestamp = "uninitialized" - hostname string -) - func main() { http.HandleFunc("GET /", indexHandler) http.Handle("GET /assets/", http.StripPrefix("/assets/", http.FileServer(http.FS(assets.Assets))))@@ -23,3 +18,18 @@ }
log.Println("Starting Gore server on :6043...") log.Fatal(http.ListenAndServe(":6043", nil)) } + +func SuperviseServices(services []*service) error { + unwrapped := make([]*service, len(services)) + for idx, svc := range services { + unwrapped[idx] = svc.s + } + + // Only supervise services after the SIGHUP handler is set up, otherwise a + // particularly fast dhcp client (e.g. when running in qemu) might send + // SIGHUP before the signal handler is set up, thereby killing init and + // panic the system! + superviseServices(unwrapped) + + return nil +}
M
status.go
→
status.go
@@ -238,12 +238,10 @@ Model string
XsrfToken int32 Kernel string }{ - Service: svc, - BuildTimestamp: buildTimestamp, - Hostname: hostname, - Model: model, - XsrfToken: token, - Kernel: kernel, + Service: svc, + Model: model, + XsrfToken: token, + Kernel: kernel, }); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return@@ -321,7 +319,6 @@ Hostname string
}{ Services: services.S, Meminfo: parseMeminfo(), - Hostname: hostname, } if jsonRequested(r) {
M
supervise.go
→
supervise.go
@@ -447,14 +447,14 @@ if attempt == 0 {
cmd.Env = append(cmd.Env, "GOKRAZY_FIRST_START=1") } // Designate a subdirectory under /perm/home as $HOME. - // This mirrors what gokrazy system daemons and + // This mirrors what gore system daemons and // ported daemons would do, so setting $HOME // increases the chance that third-party daemons // just work. base := filepath.Base(s.Cmd().Path) oldDir := "/perm/" + base homeDir := "/perm/home/" + base - // Older gokrazy installations used /perm/<base>, + // Older gore installations used /perm/<base>, // but since we started creating one directory for each // supervised process, it is better to use /perm/home/<base> // to avoid cluttering the /perm partition.@@ -464,9 +464,9 @@ }
cmd.Env = append(cmd.Env, "HOME="+homeDir) if err := os.MkdirAll(homeDir, 0700); err != nil { if errors.Is(err, syscall.EROFS) { - l.Printf("gokrazy: cannot create $HOME directory without writeable /perm partition") + l.Printf("gore: cannot create $HOME directory without writeable /perm partition") } else { - l.Printf("gokrazy: creating $HOME: %v", err) + l.Printf("gore: creating $HOME: %v", err) } } else { // Process execution fails when cmd.Dir points to@@ -474,17 +474,17 @@ // a non-existant directory.
cmd.Dir = homeDir } - l.Printf("gokrazy: attempt %d, starting %q", attempt, cmd.Args) + l.Printf("gore: attempt %d, starting %q", attempt, cmd.Args) s.setStarted(time.Now()) attempt++ pid := -1 if err := cmd.Start(); err != nil { if d := s.Diverted(); os.IsNotExist(err) && d != "" { - l.Printf("gokrazy: removing no longer existing diversion %q", d) + l.Printf("gore: removing no longer existing diversion %q", d) s.setDiversion("") } - l.Println("gokrazy: " + err.Error()) + l.Println("gore: " + err.Error()) } else { pid = cmd.Process.Pid }@@ -495,19 +495,19 @@
err := cmd.Wait() if err != nil { if isDontSupervise(err) { - l.Println("gokrazy: process should not be supervised, stopping") + l.Println("gore: process should not be supervised, stopping") s.setStopped(true) } - l.Println("gokrazy: " + err.Error()) + l.Println("gore: " + err.Error()) } else { - l.Printf("gokrazy: exited successfully, stopping") + l.Printf("gore: exited successfully, stopping") s.setStopped(true) } if s.supervisionMode() == superviseOnce { s.setSupervisionMode(superviseDone) if !s.Stopped() { - l.Println("gokrazy: running process only once, stopping") + l.Println("gore: running process only once, stopping") s.setStopped(true) } }