diff options
-rwxr-xr-x | INSTALL.sh | 2 | ||||
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | bin-src/httpd.go | 35 | ||||
-rw-r--r-- | systemd/dashboard-httpd.service | 6 | ||||
-rw-r--r-- | systemd/dashboard-httpd.socket | 8 |
5 files changed, 51 insertions, 2 deletions
@@ -10,4 +10,4 @@ sudo pacman -S --needed -- \ mkdir -p -- ~/.config/systemd/user/ ln -srf -- ~/dashboard/systemd/* ~/.config/systemd/user/ -systemctl --user enable --now dashboard-daily.timer +systemctl --user enable --now dashboard-daily.timer dashboard-httpd.socket @@ -5,7 +5,7 @@ outs = $(patsubst public-src/%,public/%,\ $(srcs)))) all: $(outs) all: public/3rd-party -all: bin/cron-daily +all: bin/cron-daily bin/httpd .PHONY: all NET-%: diff --git a/bin-src/httpd.go b/bin-src/httpd.go new file mode 100644 index 0000000..6b653bd --- /dev/null +++ b/bin-src/httpd.go @@ -0,0 +1,35 @@ +package main + +import ( + "errors" + "fmt" + "net" + "net/http" + "os" + "path/filepath" +) + +func mainWithError() error { + listenerFile := os.NewFile(uintptr(3), "listener") + if listenerFile == nil { + return errors.New("FD3 is not open") + } + + listener, err := net.FileListener(listenerFile) + if err != nil { + return err + } + + if err := os.Chdir(filepath.Dir(filepath.Dir(os.Args[0]))); err != nil { + return err + } + + return http.Serve(listener, http.FileServer(http.Dir("public"))) +} + +func main() { + if err := mainWithError(); err != nil { + fmt.Fprintf(os.Stderr, "%s: error: %v\n", os.Args[0], err) + os.Exit(1) + } +} diff --git a/systemd/dashboard-httpd.service b/systemd/dashboard-httpd.service new file mode 100644 index 0000000..17d45fa --- /dev/null +++ b/systemd/dashboard-httpd.service @@ -0,0 +1,6 @@ +[Unit] +Description=Dashboard HTTP server +Requires=dashboard-httpd.socket + +[Service] +ExecStart=/bin/sh -c '~/dashboard/bin/httpd' diff --git a/systemd/dashboard-httpd.socket b/systemd/dashboard-httpd.socket new file mode 100644 index 0000000..e49aac4 --- /dev/null +++ b/systemd/dashboard-httpd.socket @@ -0,0 +1,8 @@ +[Unit] +Description=Dashboard HTTP server + +[Socket] +ListenStream=41198 + +[Install] +WantedBy=sockets.target |