mirror of
https://git.swurl.xyz/swirl/link.git
synced 2023-11-08 10:44:52 +02:00
install target, added environment file for systemd service
This commit is contained in:
parent
4e20f587fb
commit
3bc7271f44
10 changed files with 53 additions and 39 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1 +1 @@
|
||||||
out
|
linkserv
|
||||||
|
|
2
LICENSE
2
LICENSE
|
@ -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.
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
A URL Shortener called Link.
|
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
|
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
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
|
|
6
doc/link.conf
Normal file
6
doc/link.conf
Normal 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"
|
|
@ -3,7 +3,8 @@ Description=serve link instance
|
||||||
After=network.target
|
After=network.target
|
||||||
|
|
||||||
[Service]
|
[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]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
|
3
go.mod
3
go.mod
|
@ -1,8 +1,9 @@
|
||||||
module git.fsh.ee/i/link
|
module git.swurl.xyz/swirl/link
|
||||||
|
|
||||||
go 1.16
|
go 1.16
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
golang.org/dl v0.0.0-20210805175753-70f86bf65abd // indirect
|
||||||
gorm.io/driver/sqlite v1.1.4
|
gorm.io/driver/sqlite v1.1.4
|
||||||
gorm.io/gorm v1.21.9
|
gorm.io/gorm v1.21.9
|
||||||
)
|
)
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -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/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 h1:1IdxlwTNazvbKJQSxoJ5/9ECbEeaTTyeU7sEAZ5KKTQ=
|
||||||
github.com/mattn/go-sqlite3 v1.14.5/go.mod h1:WVKg1VTActs4Qso6iwGbiFih2UIHo0ENGwNd0Lj+XmI=
|
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 h1:PDzwYE+sI6De2+mxAneV9Xs11+ZyKV6oxD3wDGkaNvM=
|
||||||
gorm.io/driver/sqlite v1.1.4/go.mod h1:mJCeTFr7+crvS+TRnWc5Z3UvwxUN1BGBLMrf5LA9DYw=
|
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=
|
gorm.io/gorm v1.20.7/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw=
|
||||||
|
|
33
index.html
33
index.html
|
@ -87,32 +87,21 @@ to do (one of the design goals). Below are instructions detailing how.
|
||||||
| # emerge --ask dev-lang/go dev-vcs/git
|
| # emerge --ask dev-lang/go dev-vcs/git
|
||||||
| # apt install go git
|
| # apt install go git
|
||||||
|
|
|
|
||||||
| 2. Fetch and compile the source code
|
| 2. Clone the source code
|
||||||
| # env GO111MODULE=off go get git.swurl.xyz/swirl/link
|
| # git clone https://git.swurl.xyz/swirl/link
|
||||||
|
|
|
|
||||||
| 3. Copy the binary to your binary directory
|
| 3. Compile
|
||||||
| # cp $GOPATH/bin/link /usr/local/bin/linkserv
|
| # cd link && make
|
||||||
| # # Named linkserv to prevent conflicts with GNU link
|
|
||||||
|
|
|
|
||||||
| 4. Create a directory to store your database
|
| 4. Install
|
||||||
| # mkdir -p /srv/link
|
| # make install
|
||||||
|
|
|
|
||||||
| 5. (optional) Copy the example systemd service
|
| 5. Change the configuration to reflect your desired options
|
||||||
| # cp doc/link.service /etc/systemd/system/
|
| # vim /etc/link.conf
|
||||||
| * You can also create an equivalent for openrc, runit, etc.
|
|
||||||
|
|
|
|
||||||
| 6. Change the domain to reflect your setup
|
| 6. Enable and start the service
|
||||||
| # 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
|
|
||||||
| # systemctl enable --now link
|
| # 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.
|
| * The server is now running on localhost at port 8080.
|
||||||
| * If the SQLite database does not exist, it will be created.
|
| * If the SQLite database does not exist, it will be created.
|
||||||
| * All logging will be printed to standard error and standard output.
|
| * 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
|
| # emerge --ask www-servers/nginx app-crypt/certbot-nginx
|
||||||
| # apt install nginx python-certbot-nginx
|
| # apt install nginx python-certbot-nginx
|
||||||
|
|
|
|
||||||
| 2. Copy the example site file
|
| 2. Install if you haven't already
|
||||||
| # cp doc/link.nginx.conf /etc/nginx/sites-available/link
|
| # make install
|
||||||
|
|
|
|
||||||
| 3. Change the domain to reflect your setup
|
| 3. Change the domain to reflect your setup
|
||||||
| # sed -i 's/your.doma.in/[DOMAIN HERE]/g' /etc/nginx/sites-available/link
|
| # sed -i 's/your.doma.in/[DOMAIN HERE]/g' /etc/nginx/sites-available/link
|
||||||
|
|
2
main.go
2
main.go
|
@ -1,5 +1,5 @@
|
||||||
// A URL Shortener called Link.
|
// 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
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
|
29
makefile
29
makefile
|
@ -1,12 +1,13 @@
|
||||||
BIN=out
|
BIN=linkserv
|
||||||
CC=go1.17beta1
|
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:
|
all: vendor gen build
|
||||||
@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
|
|
||||||
|
|
||||||
vendor: go.mod go.sum
|
vendor: go.mod go.sum
|
||||||
@$(CC) mod tidy
|
@$(CC) mod tidy
|
||||||
|
@ -23,10 +24,22 @@ test:
|
||||||
|
|
||||||
run: lint build
|
run: lint build
|
||||||
@clear
|
@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:
|
dev:
|
||||||
@find . -type f | grep -E '(.*)\.(go|html)' | entr -cr make run
|
@find . -type f | grep -E '(.*)\.(go|html)' | entr -cr make run
|
||||||
|
|
||||||
lint:
|
lint:
|
||||||
@golangci-lint run ./...
|
@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
2
vendor/modules.txt
vendored
|
@ -4,6 +4,8 @@ github.com/jinzhu/inflection
|
||||||
github.com/jinzhu/now
|
github.com/jinzhu/now
|
||||||
# github.com/mattn/go-sqlite3 v1.14.5
|
# github.com/mattn/go-sqlite3 v1.14.5
|
||||||
github.com/mattn/go-sqlite3
|
github.com/mattn/go-sqlite3
|
||||||
|
# golang.org/dl v0.0.0-20210805175753-70f86bf65abd
|
||||||
|
## explicit
|
||||||
# gorm.io/driver/sqlite v1.1.4
|
# gorm.io/driver/sqlite v1.1.4
|
||||||
## explicit
|
## explicit
|
||||||
gorm.io/driver/sqlite
|
gorm.io/driver/sqlite
|
||||||
|
|
Loading…
Reference in a new issue