small pixel drawing of a pufferfish gore

patch up logging, remove some legacy stuff
Jes Olson j3s@c3f.net
Tue, 17 Dec 2024 15:57:29 -0500
commit

588f100a96f99a57ef24a6ebfe8a7e3ff2715008

parent

88092f4b7e73c005b1c3d7eac3d6e3af0c5c43f9

3 files changed, 25 insertions(+), 23 deletions(-)

jump to
M .gitignore.gitignore

@@ -1,2 +1,3 @@

builddir pkg +vore*
M main.gomain.go

@@ -3,6 +3,7 @@

import ( "log" "net/http" + "os/exec" "j3s.sh/gore/internal/assets" )

@@ -12,6 +13,13 @@ http.HandleFunc("GET /", indexHandler)

http.Handle("GET /assets/", http.StripPrefix("/assets/", http.FileServer(http.FS(assets.Assets)))) http.HandleFunc("POST /add", addHandler) + var services []*service + var service1 = &service{ + cmd: exec.Command("/home/j3s/code/gore/builddir/git.j3s.sh/vore@v0.0.0-20240814184024-9d6fb2a0444f/vore"), + } + service1.state = NewProcessState() + services = append(services, service1) + if err := SuperviseServices(services); err != nil { log.Fatal(err) }

@@ -22,7 +30,7 @@

func SuperviseServices(services []*service) error { unwrapped := make([]*service, len(services)) for idx, svc := range services { - unwrapped[idx] = svc.s + unwrapped[idx] = svc } // Only supervise services after the SIGHUP handler is set up, otherwise a
M supervise.gosupervise.go

@@ -403,7 +403,6 @@ } else {

log.Printf("cannot read module info from %s: %v", s.Cmd().Path, err) } - l := log.New(s.Stderr, "", log.LstdFlags|log.Ldate|log.Ltime) attempt := 0 // Wait for clock to be updated via ntp for services

@@ -411,7 +410,7 @@ // that need correct time. This can be enabled

// by adding a settings file named waitforclock.txt under // waitforclock/<package> directory. if strings.HasPrefix(s.Cmd().Path, "/user/") && s.waitForClock { - l.Print("gore: waiting for clock to be synced") + log.Print("gore: waiting for clock to be synced") WaitForClock() }

@@ -452,21 +451,14 @@ // 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 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. - if _, err := os.Stat(oldDir); err == nil { - homeDir = oldDir - } + homeDir := "gore/" + base cmd.Env = append(cmd.Env, "HOME="+homeDir) + if err := os.MkdirAll(homeDir, 0700); err != nil { if errors.Is(err, syscall.EROFS) { - l.Printf("gore: cannot create $HOME directory without writeable /perm partition") + log.Printf("gore: cannot create $HOME directory without writeable gore/ dir") } else { - l.Printf("gore: creating $HOME: %v", err) + log.Fatalf("gore: creating $HOME: %s", err) } } else { // Process execution fails when cmd.Dir points to

@@ -474,17 +466,17 @@ // a non-existant directory.

cmd.Dir = homeDir } - l.Printf("gore: attempt %d, starting %q", attempt, cmd.Args) + log.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("gore: removing no longer existing diversion %q", d) + log.Printf("gore: removing no longer existing diversion %q", d) s.setDiversion("") } - l.Println("gore: " + err.Error()) + log.Println("gore: " + err.Error()) } else { pid = cmd.Process.Pid }

@@ -495,19 +487,19 @@

err := cmd.Wait() if err != nil { if isDontSupervise(err) { - l.Println("gore: process should not be supervised, stopping") + log.Println("gore: process should not be supervised, stopping") s.setStopped(true) } - l.Println("gore: " + err.Error()) + log.Println("gore: " + err.Error()) } else { - l.Printf("gore: exited successfully, stopping") + log.Printf("gore: exited successfully, stopping") s.setStopped(true) } if s.supervisionMode() == superviseOnce { s.setSupervisionMode(superviseDone) if !s.Stopped() { - l.Println("gore: running process only once, stopping") + log.Println("gore: running process only once, stopping") s.setStopped(true) } }

@@ -692,11 +684,12 @@ services.Lock()

services.S = svc defer services.Unlock() for _, s := range services.S { + fmt.Println(s) go supervise(s) } - http.HandleFunc("/stop", stopstartHandler) - http.HandleFunc("/restart", stopstartHandler) + http.HandleFunc("POST /stop", stopstartHandler) + http.HandleFunc("POST /restart", stopstartHandler) } func WaitForClock() {