Skip to content

Instantly share code, notes, and snippets.

@hypervtechnics
Last active December 22, 2023 08:45
Show Gist options
  • Select an option

  • Save hypervtechnics/9cb28e67aea93cb9b87af5141bc3aa25 to your computer and use it in GitHub Desktop.

Select an option

Save hypervtechnics/9cb28e67aea93cb9b87af5141bc3aa25 to your computer and use it in GitHub Desktop.
Gotify and Caddy with Systemd

How to install Gotify with Caddy

In this guide I am going to use SQLite as storage mechanism.

Change to install location

cd /opt
mkdir -p gotify
cd gotify

The install location will be substituted with <installlocation> in this guide in the further steps. I prefer /opt/<app>. But of course you might also use something like /usr/local/bin/ and store the configuration in /etc/gotify/.

Get Gotify

First you have to get the download link to the binary of your architecture. Find the newest release here.

# Needed to unzip the downloaded file
apt install -y unzip

# Download the new release to gotify-download.zip and unzip it
wget -O gotify-download.zip <releaseurl>
unzip gotify-download.zip

# Rename the executable file to a more intuitive name and set permissions
mv gotify-<os>-<arch> gotify
sudo chown root:root gotify
sudo chmod 755 gotify

# Create a group and user for running the app
groupadd -r gotify
useradd -M -d /opt/gotify -s /sbin/nologin -r -g gotify gotify

Setup configuration

Put your configuration into config.yml in a directory of your choice. E.g. <installlocation>/config.yml or /etc/gotify/config.yml. Here is the configuration used by me. Remember to change the password.

server:
  listenaddr: "127.0.0.1" # the address to bind on, leave empty to bind on all addresses
  port: 3000 # the port for the http server
  ssl:
    enabled: false # if https should be enabledeave empty to bind on all addresses
    letsencrypt:
      enabled: false # if the certificate should be requested from letsencrypt
  responseheaders: # response headers are added to every response (default: none)
    Access-Control-Allow-Origin: "*"
    Access-Control-Allow-Methods: "GET,POST"
database: # see below
  dialect: sqlite3
  connection: data/gotify.db
defaultuser: # on database creation, gotify creates an admin user (these values will only be used for the first start, if you want to edit the user after the first start use the WebUI)
  name: admin # the username of the default user
  pass: somesupersecurepassword123!!! # the password of the default user
passstrength: 10 # the bcrypt password strength (higher = better but also slower)
uploadedimagesdir: data/images # the directory for storing uploaded images
pluginsdir: data/plugins # the directory where plugin resides (leave empty to disable plugins)

After that:

# Assign correct permissions to config file
chown root:root config.yml
chmod 644 config.yml

# Create the directory with correct permissions
mkdir data
chown -R gotify:gotify data
chmod -R 755 data

Test if that worked until now

sudo -u gotify ./gotify

Setup systemd service

Save the systemd service to /etc/systemd/system/gotify.service. The template for the service file. Replace the tokens in the file depending on what you want.

[Unit]
Description=Gotify Push Notification Server
Documentation=https://gotify.net/docs
After=network-online.target
Wants=network-online.target systemd-networkd-wait-online.service

StartLimitIntervalSec=14400
StartLimitBurst=10

[Service]
Restart=on-abnormal

User=gotify
Group=gotify

WorkingDirectory=<installlocation>
ExecStart=<installlocation>/gotify

PrivateTmp=true
ProtectSystem=full
ReadWritePaths=<datalocation>
ReadWriteDirectories=<datalocation>

TimeoutStopSec=5s

[Install]
WantedBy=multi-user.target
# Set permissions
chown root:root /etc/systemd/system/gotify.service
chmod 644 /etc/systemd/system/gotify.service

# Activate it
systemctl daemon-reload
systemctl start gotify.service

# Enable at boot
systemclt enable gotify.service

Setup caddy

Add the following to your Caddyfile.

<domain> {
    proxy / localhost:3000 {
        transparent
        websocket
    }
}

Restart caddy and everything should be done.

systemctl restart caddy

Notes

  • Consider removing the admin password from the config.yml or change to another to prevent forgetting to change and other people getting access to the admin panel.
@brvier
Copy link

brvier commented Apr 24, 2023

systemclt enable gotify.service
should be
systemctl enable gotify.service

@hypervtechnics
Copy link
Author

systemclt enable gotify.service should be systemctl enable gotify.service

yes, updated. although currently I'd recommend a docker container setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment