small pixel drawing of a pufferfish gore

main.go

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
}