git » gofer » commit caceac3

Add a `make install` target and update instructions

author Alberto Bertogli
2022-10-08 11:30:52 UTC
committer Alberto Bertogli
2022-10-13 22:26:18 UTC
parent 0cf6203973f88b27e8ef74676dc040c74ba93034

Add a `make install` target and update instructions

This patch adds a new `make install` target, that copies the binary and
some initial configuration files to /etc.

While this is not going to be absolutely universal, it should work well
enough on most popular Linux distributions, and serve as a starting
point for people doing it manually.

Makefile +9 -2
README.md +12 -3
etc/gofer.yaml +29 -0
etc/logrotate.d/gofer +2 -2
etc/systemd/{ => system}/gofer.service +0 -0

diff --git a/Makefile b/Makefile
index 11185cc..9de8e1c 100644
--- a/Makefile
+++ b/Makefile
@@ -16,7 +16,7 @@ gofer:
 		-X blitiri.com.ar/go/gofer/debug.SourceDateTs=${SOURCE_DATE_EPOCH} \
 		" ${GOFLAGS}
 
-vet: config/gofer.yaml test/01-be.yaml test/01-fe.yaml
+vet: config/gofer.yaml etc/gofer.yaml test/01-be.yaml test/01-fe.yaml
 	go vet ./...
 	cue vet config/gofer.schema.cue $^
 
@@ -34,4 +34,11 @@ cover:
 	COVER_DIR=$$PWD/.cover/ setsid -w ./test/test.sh
 	COVER_DIR=$$PWD/.cover/ setsid -w ./test/util/cover-report.sh
 
-.PHONY: gofer vet test cover
+install: gofer
+	install -D -b -p gofer /usr/local/bin
+	install -d /etc /etc/systemd/system/ /etc/logrotate.d/
+	cp -n etc/gofer.yaml /etc/
+	cp -n etc/systemd/system/gofer.service /etc/systemd/system/
+	cp -n etc/logrotate.d/gofer /etc/logrotate.d/
+
+.PHONY: gofer vet test cover install
diff --git a/README.md b/README.md
index e331c45..9fd86f8 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@
 # gofer
 
 [gofer](https://blitiri.com.ar/git/r/gofer) is a small web server and reverse
-proxy.
+proxy, written in Go.
 
 
 ## Status
@@ -16,15 +16,24 @@ It is fully functional and being used to serve some small websites.
 
 ## Install
 
-gofer is written in Go.
+To install from source, you'll need the [Go](https://golang.org/) compiler.
 
 ```sh
-go install blitiri.com.ar/go/gofer@latest
+# Clone the repository.
+git clone https://blitiri.com.ar/repos/gofer
+
+# Build the binary and install basic config files.
+cd gofer; sudo make install
+
+# Start the server.
+sudo systemctl start gofer
 ```
 
 
 ## Configure
 
+Configuration lives in `/etc/gofer.yaml` by default.
+
 See the [reference config](config/gofer.yaml) for details on how to configure
 gofer, and what features are available.
 
diff --git a/etc/gofer.yaml b/etc/gofer.yaml
new file mode 100644
index 0000000..abd0b5d
--- /dev/null
+++ b/etc/gofer.yaml
@@ -0,0 +1,29 @@
+# gofer configuration file
+
+control_addr: "127.0.0.1:8081"
+
+reqlog:
+  "requests.log":
+    file: "/var/log/gofer/requests.log"
+    bufsize: 16
+
+http:
+  ":80":
+    reqlog:
+      "/": "requests.log"
+    routes:
+      "/":
+        dir: "/srv/www/"
+
+
+# Uncomment this section to enable HTTPS.
+# Make sure to set the autocert hosts to the appropriate values.
+#https:
+#  ":443":
+#    autocerts:
+#      hosts: ["example.org", "www.example.org"]
+#    reqlog:
+#      "/": "requests.log"
+#    routes:
+#      "/":
+#        dir: "/srv/www/"
diff --git a/etc/logrotate.d/gofer b/etc/logrotate.d/gofer
index 3e72cc0..34ac35a 100644
--- a/etc/logrotate.d/gofer
+++ b/etc/logrotate.d/gofer
@@ -1,7 +1,7 @@
 /var/log/gofer/*.log {
-        weekly
+        size 50M
+        rotate 10
         missingok
-        rotate 12
         compress
         delaycompress
         notifempty
diff --git a/etc/systemd/gofer.service b/etc/systemd/system/gofer.service
similarity index 100%
rename from etc/systemd/gofer.service
rename to etc/systemd/system/gofer.service