install target, added environment file for systemd service

This commit is contained in:
swirl 2021-08-12 15:30:47 -04:00
parent 4e20f587fb
commit 3bc7271f44
10 changed files with 53 additions and 39 deletions

2
.gitignore vendored
View file

@ -1 +1 @@
out
linkserv

View file

@ -630,7 +630,7 @@ state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
A URL Shortener called Link.
Copyright (C) 2021 i@fsh.ee
Copyright (C) 2021 swurl@swurl.xyz
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by

6
doc/link.conf Normal file
View file

@ -0,0 +1,6 @@
BIN="BINDIR/BINNAME" # replace this with the path to link (usually /usr/local/bin/linkserv by default)
COPY="2021 you@your.doma.in"
DB="/srv/link/link.db"
PORT=8080
SEED="secret"
URL="https://your.doma.in"

View file

@ -3,7 +3,8 @@ Description=serve link instance
After=network.target
[Service]
ExecStart=/usr/local/bin/linkserv -url https://your.doma.in -db /srv/link/link.db -seed "secret"
EnvironmentFile=/etc/link.conf
ExecStart=/bin/sh -c '"${BIN}" -copy "${COPY}" -db "${DB}" -port ${PORT} -seed "${SEED}" -url "${URL}"'
[Install]
WantedBy=multi-user.target

3
go.mod
View file

@ -1,8 +1,9 @@
module git.fsh.ee/i/link
module git.swurl.xyz/swirl/link
go 1.16
require (
golang.org/dl v0.0.0-20210805175753-70f86bf65abd // indirect
gorm.io/driver/sqlite v1.1.4
gorm.io/gorm v1.21.9
)

2
go.sum
View file

@ -5,6 +5,8 @@ github.com/jinzhu/now v1.1.2 h1:eVKgfIdy9b6zbWBMgFpfDPoAMifwSZagU9HmEU6zgiI=
github.com/jinzhu/now v1.1.2/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/mattn/go-sqlite3 v1.14.5 h1:1IdxlwTNazvbKJQSxoJ5/9ECbEeaTTyeU7sEAZ5KKTQ=
github.com/mattn/go-sqlite3 v1.14.5/go.mod h1:WVKg1VTActs4Qso6iwGbiFih2UIHo0ENGwNd0Lj+XmI=
golang.org/dl v0.0.0-20210805175753-70f86bf65abd h1:zTi7rOU7NMmBInGr/IFQrDXBgYZ2VCO7BlylmxGpQTs=
golang.org/dl v0.0.0-20210805175753-70f86bf65abd/go.mod h1:IUMfjQLJQd4UTqG1Z90tenwKoCX93Gn3MAQJMOSBsDQ=
gorm.io/driver/sqlite v1.1.4 h1:PDzwYE+sI6De2+mxAneV9Xs11+ZyKV6oxD3wDGkaNvM=
gorm.io/driver/sqlite v1.1.4/go.mod h1:mJCeTFr7+crvS+TRnWc5Z3UvwxUN1BGBLMrf5LA9DYw=
gorm.io/gorm v1.20.7/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw=

View file

@ -87,32 +87,21 @@ to do (one of the design goals). Below are instructions detailing how.
| # emerge --ask dev-lang/go dev-vcs/git
| # apt install go git
|
| 2. Fetch and compile the source code
| # env GO111MODULE=off go get git.swurl.xyz/swirl/link
| 2. Clone the source code
| # git clone https://git.swurl.xyz/swirl/link
|
| 3. Copy the binary to your binary directory
| # cp $GOPATH/bin/link /usr/local/bin/linkserv
| # # Named linkserv to prevent conflicts with GNU link
| 3. Compile
| # cd link && make
|
| 4. Create a directory to store your database
| # mkdir -p /srv/link
| 4. Install
| # make install
|
| 5. (optional) Copy the example systemd service
| # cp doc/link.service /etc/systemd/system/
| * You can also create an equivalent for openrc, runit, etc.
| 5. Change the configuration to reflect your desired options
| # vim /etc/link.conf
|
| 6. Change the domain to reflect your setup
| # sed -i 's/your.doma.in/[DOMAIN HERE]/g' /etc/systemd/system/link.service
|
| 7. Change the seed to something secure
| # sed -i 's/secret/SecretPasswordHere/g' /etc/systemd/system/link.service
|
| 8. Enable and start the service
| 6. Enable and start the service
| # systemctl enable --now link
|
| 9. Or, run it manually
| # linkserv -url http://your.doma.in -db /srv/link/link.db -seed "secret"
|
| * The server is now running on localhost at port 8080.
| * If the SQLite database does not exist, it will be created.
| * All logging will be printed to standard error and standard output.
@ -129,8 +118,8 @@ to do (one of the design goals). Below are instructions detailing how.
| # emerge --ask www-servers/nginx app-crypt/certbot-nginx
| # apt install nginx python-certbot-nginx
|
| 2. Copy the example site file
| # cp doc/link.nginx.conf /etc/nginx/sites-available/link
| 2. Install if you haven't already
| # make install
|
| 3. Change the domain to reflect your setup
| # sed -i 's/your.doma.in/[DOMAIN HERE]/g' /etc/nginx/sites-available/link
@ -156,7 +145,7 @@ location /shortener {
<footer style='white-space: pre;'>Source code: <a href='https://short.swurl.xyz/src'>short.swurl.xyz/src</a></a>
License: AGPL v3{{if .Copy}}
Copy: {{.Copy}}{{end}}
Copy: {{.Copy}}{{end}}
Made with: Go, Neovim, and Gentoo/Arch Linux
</footer>
</html>

View file

@ -1,5 +1,5 @@
// A URL Shortener called Link.
// Copyright (C) 2021 i@fsh.ee
// Copyright (C) 2021 swurl@swurl.xyz
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View file

@ -1,12 +1,13 @@
BIN=out
CC=go1.17beta1
BIN=linkserv
CC=go
all: setup vendor gen build
prefix=/usr/local
confdir=/etc
systemd_dir=${DESTDIR}${confdir}/systemd/system
nginx_dir=${DESTDIR}${confdir}/nginx
bindir=${DESTDIR}${prefix}/bin
setup:
@env GOOD=off go get golang.org/dl/$(CC)
@env GOOD=off $(CC) download
#@env GO111MODULE=off $(CC) get github.com/golangci/golangci-lint/cmd/golangci-lint
all: vendor gen build
vendor: go.mod go.sum
@$(CC) mod tidy
@ -23,10 +24,22 @@ test:
run: lint build
@clear
@env $(ENV) ./$(BIN) -v -demo -copy "2021 i@fsh.ee" -url https://dev.fsh.ee -port 8080 -db /tmp/link_test_db_1.sql -seed secret
@env $(ENV) ./$(BIN) -v -demo -copy "2021 swurl@swurl.xyz" -url https://short.swurl.xyz -port 8080 -db /tmp/link.db -seed "secret"
dev:
@find . -type f | grep -E '(.*)\.(go|html)' | entr -cr make run
lint:
@golangci-lint run ./...
install-nginx:
@install -Dm644 doc/link.nginx.conf ${nginx_dir}/sites-available/link
install-systemd:
@install -Dm644 doc/link.service ${systemd_dir}/link.service
@install -Dm644 doc/link.conf ${DESTDIR}/${confdir}/link.conf
install-bin:
@install -Dm755 ${BIN} ${bindir}/${BIN}
install: build install-bin install-nginx install-systemd

2
vendor/modules.txt vendored
View file

@ -4,6 +4,8 @@ github.com/jinzhu/inflection
github.com/jinzhu/now
# github.com/mattn/go-sqlite3 v1.14.5
github.com/mattn/go-sqlite3
# golang.org/dl v0.0.0-20210805175753-70f86bf65abd
## explicit
# gorm.io/driver/sqlite v1.1.4
## explicit
gorm.io/driver/sqlite