try to rename as gowebd
put the HTML assets raw in the binary also I'm how old and still committed a binary. squashed Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
c6be85e92f
commit
d827c398f0
|
@ -3,4 +3,5 @@ go.mod
|
|||
go.sum
|
||||
|
||||
go.wit.com
|
||||
gowebd
|
||||
files/
|
||||
|
|
15
Makefile
15
Makefile
|
@ -1,3 +1,5 @@
|
|||
VERSION = $(shell git describe --tags)
|
||||
|
||||
all:
|
||||
@echo "make run # will build and run the daemon here"
|
||||
@echo "make debian # will build a debian package"
|
||||
|
@ -19,9 +21,9 @@ restart:
|
|||
run:
|
||||
git pull
|
||||
echo "build it!"
|
||||
GO111MODULE=off go build -v -x
|
||||
./go.wit.com
|
||||
# setcap 'cap_net_bind_service=+ep' go.wit.com # allow the binary to open ports below 1024
|
||||
GO111MODULE=off go build -v -x -ldflags "-X main.Version=${VERSION} -X gui.GUIVERSION=${VERSION}"
|
||||
./gowebd --port 2233
|
||||
# setcap 'cap_net_bind_service=+ep' gowebd # allow the binary to open ports below 1024
|
||||
|
||||
goimports:
|
||||
goimports -w *.go
|
||||
|
@ -31,6 +33,11 @@ redomod:
|
|||
GO111MODULE= go mod init
|
||||
GO111MODULE= go mod tidy
|
||||
|
||||
clean:
|
||||
rm -f go.*
|
||||
rm -f go.wit.com
|
||||
rm -f gowebd
|
||||
|
||||
# makes a .deb package
|
||||
debian:
|
||||
go-deb --no-gui --repo go.wit.com/apps/go.wit.com
|
||||
go-deb --no-gui --repo go.wit.com/apps/gowebd
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
makes the website go.wit.com
|
||||
|
||||
TODO: make it generic so it can use different DNS names
|
12
args.go
12
args.go
|
@ -10,11 +10,17 @@ import (
|
|||
"go.wit.com/dev/alexflint/arg"
|
||||
)
|
||||
|
||||
var args struct {
|
||||
var argv args
|
||||
|
||||
type args struct {
|
||||
ListRepos bool `arg:"--list-repos" help:"list all repositories"`
|
||||
Port int `arg:"--port" help:"port to run on (default is 2520)"`
|
||||
Port int `arg:"--port" default:"2520" help:"port to run on"`
|
||||
}
|
||||
|
||||
func (args) Version() string {
|
||||
return "virtigo " + Version
|
||||
}
|
||||
|
||||
func init() {
|
||||
arg.MustParse(&args)
|
||||
arg.MustParse(&argv)
|
||||
}
|
||||
|
|
5
build
5
build
|
@ -7,9 +7,10 @@ cp gowebd.service files/lib/systemd/system/
|
|||
# caddy file. propose this as the dir structure caddy should use
|
||||
mkdir -p files/etc/gowebd/
|
||||
cp Caddyfile.go.wit.com files/etc/gowebd/
|
||||
cp resources/repomap files/etc/gowebd/
|
||||
cp resources/Makefile files/etc/gowebd/
|
||||
|
||||
# share dir
|
||||
mkdir -p files/usr/share/gowebd/
|
||||
cp Makefile files/usr/share/gowebd/
|
||||
cp resources/repomap files/usr/share/gowebd/go.wit.com
|
||||
cp -a resources/repomap files/usr/share/gowebd/go.wit.com
|
||||
cp -a resources files/usr/share/gowebd/
|
||||
|
|
4
control
4
control
|
@ -1,6 +1,6 @@
|
|||
Source: go.wit.com
|
||||
Source: gowebd
|
||||
Build-Depends: golang
|
||||
Package: go.wit.com
|
||||
Package: gowebd
|
||||
Maintainer: Jeff Carr <jcarr@wit.com>
|
||||
Architecture: amd64
|
||||
Depends: caddy
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
[Unit]
|
||||
Description=go.wit.com
|
||||
Description=gowebd
|
||||
|
||||
[Service]
|
||||
User=root
|
||||
Type=simple
|
||||
ExecStart=/usr/bin/go.wit.com
|
||||
ExecStop=killall go.wit.com
|
||||
ExecStart=/usr/bin/gowebd
|
||||
ExecStop=killall gowebd
|
||||
Restart=on-failure
|
||||
RestartSec=30
|
||||
RestartSec=5
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
|
17
main.go
17
main.go
|
@ -11,6 +11,8 @@ import (
|
|||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
var Version string
|
||||
|
||||
//go:embed resources/*
|
||||
var resources embed.FS
|
||||
|
||||
|
@ -21,6 +23,8 @@ var versionMap map[string]string
|
|||
var configfile []string
|
||||
var keysSorted []string
|
||||
|
||||
var HOSTNAME string = "go.wit.com"
|
||||
|
||||
// remove '?' part and trailing '/'
|
||||
func cleanURL(url string) string {
|
||||
url = "/" + strings.Trim(url, "/")
|
||||
|
@ -38,7 +42,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
|||
requrl := parts[0]
|
||||
|
||||
url, repourl := findkey(requrl)
|
||||
log.Warn("go.wit.com URL =", url, "REPO URL =", repourl, "REQUEST URL =", requrl)
|
||||
log.Warn("gowebd URL =", url, "REPO URL =", repourl, "REQUEST URL =", requrl)
|
||||
if repourl != "" {
|
||||
repoHTML(w, url, repourl)
|
||||
return
|
||||
|
@ -96,6 +100,10 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
|||
writeFile(w, "skeleton.v2.css")
|
||||
return
|
||||
}
|
||||
if tmp == "/favicon.ico" {
|
||||
writeFile(w, "ipv6.png")
|
||||
return
|
||||
}
|
||||
// used for uptime monitor checking
|
||||
if tmp == "/uptime" {
|
||||
writeFile(w, "uptime.html")
|
||||
|
@ -150,7 +158,10 @@ func main() {
|
|||
log.Println("found log =", versionMap["go.wit.com/log"])
|
||||
http.HandleFunc("/", okHandler)
|
||||
// go https()
|
||||
err := http.ListenAndServe(":2520", nil)
|
||||
p := fmt.Sprintf(":%d", argv.Port)
|
||||
log.Println("HOSTNAME set to:", HOSTNAME)
|
||||
log.Println("Running on port", p)
|
||||
err := http.ListenAndServe(p, nil)
|
||||
if err != nil {
|
||||
log.Println("Error starting server:", err)
|
||||
}
|
||||
|
@ -160,7 +171,7 @@ func badurl(w http.ResponseWriter, badurl string) {
|
|||
fmt.Fprintln(w, "<!DOCTYPE html>")
|
||||
fmt.Fprintln(w, "<html>")
|
||||
fmt.Fprintln(w, " <head>")
|
||||
fmt.Fprintln(w, " <meta http-equiv=\"refresh\" content=\"3; url=https://go.wit.com/\">")
|
||||
fmt.Fprintln(w, " <meta http-equiv=\"refresh\" content=\"3; url=https://" + HOSTNAME + "/\">")
|
||||
fmt.Fprintln(w, " </head>")
|
||||
fmt.Fprintln(w, " <body>")
|
||||
fmt.Fprintln(w, " IPv4 IS NOT SUPPORTED<br>")
|
||||
|
|
2
postinst
2
postinst
|
@ -5,4 +5,4 @@ cd /etc/gowebd/
|
|||
ln -s /usr/share/gowebd/go.wit.com .
|
||||
|
||||
# allow the binary to open ports below 1024
|
||||
setcap 'cap_net_bind_service=+ep' /usr/bin/go.wit.com
|
||||
setcap 'cap_net_bind_service=+ep' /usr/bin/gowebd
|
||||
|
|
10
repoHTML.go
10
repoHTML.go
|
@ -64,12 +64,20 @@ func findkey(url string) (string, string) {
|
|||
}
|
||||
|
||||
func readconfigfile() {
|
||||
var pfile []byte
|
||||
var err error
|
||||
repoMap = make(map[string]string)
|
||||
pfile, err := resources.ReadFile("resources/repomap")
|
||||
|
||||
pfile, err = os.ReadFile("/etc/gowebd/repomap")
|
||||
if err != nil {
|
||||
log.Error(err, "no repository map file found in /etc/gowebd/")
|
||||
log.Error(err, "falling back to the repository map file built into the gowebd binary")
|
||||
pfile, err = resources.ReadFile("resources/repomap")
|
||||
if err != nil {
|
||||
log.Error(err, "missing repomap in the binary")
|
||||
return
|
||||
}
|
||||
}
|
||||
configfile = strings.Split(string(pfile), "\n")
|
||||
for _, line := range configfile {
|
||||
fields := strings.Fields(line)
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
all:
|
||||
gowebd --version
|
||||
@echo "make log # watch gowebd log"
|
||||
@echo "make restart # restart gowebd"
|
||||
@echo "make enable # enable gowebd on boot"
|
||||
@echo "make status # show the systemd status of gowebd"
|
||||
|
||||
log:
|
||||
@journalctl -f -xeu gowebd.service
|
||||
|
||||
status:
|
||||
systemctl status gowebd.service
|
||||
|
||||
enable:
|
||||
systemctl enable gowebd.service
|
||||
|
||||
restart:
|
||||
systemctl stop gowebd.service
|
||||
systemctl start gowebd.service
|
|
@ -1,4 +0,0 @@
|
|||
#!/bin/bash -x
|
||||
#
|
||||
|
||||
echo "TODO: make this work"
|
Binary file not shown.
After Width: | Height: | Size: 3.6 KiB |
Loading…
Reference in New Issue