main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main import ( "log" "net/http" "os/exec" "j3s.sh/gore/internal/assets" ) func main() { 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) } 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 } // 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 }