diff --git a/README.md b/README.md index 940bb23..b395106 100644 --- a/README.md +++ b/README.md @@ -8,3 +8,27 @@ It expects the following environment variables to be set: - `API_TOKEN` - Forgejo API authorization token - `REDIRECT_URL` - Redirect url when access fails or files do not exist (ex. `https://git.brut.systems`) - `PORT` - Port to listen on + +## Usage w/ systemd + +Create a file at `/etc/systemd/system/docs.brut.service` with the following: + +``` +[Unit] +Description=Serves files from Git repositories +After=network.target + +[Service] +Type=simple +ExecStart=/start.sh +ExecStop=/usr/bin/pkill docs.brut.systems +Restart=always +User= +Environment="API_URL=" +Environment="API_TOKEN=" +Environment="REDIRECT_URL=" +Environment="PORT=" + +[Install] +WantedBy=multi-user.target +``` diff --git a/docs.brut.systems b/docs.brut.systems new file mode 100755 index 0000000..55ff95d Binary files /dev/null and b/docs.brut.systems differ diff --git a/start.sh b/start.sh new file mode 100755 index 0000000..0fd3d5b --- /dev/null +++ b/start.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env sh + +EXECUTABLE="./docs.brut.systems" + +git pull + +if command -v go &> /dev/null; then + echo "Recompiling latest version..." + + go build -o "$EXECUTABLE" . + + if [ $? -ne 0 ]; then + echo "Compilation failed!" + exit 1 + fi + echo "Compilation successful." +fi + +if [ -x "$EXECUTABLE" ]; then + echo "Starting $EXECUTABLE..." + "$EXECUTABLE" "$@" +else + echo "Error: Executable not found and Go is not installed to compile it." + exit 1 +fi