Self-hosting Gotify

Push notifications are great. You know what else is great? Gotify, a self-hosted server for sending and receiving push notifications. Distributed as a single binary file, Gotify is easy to deploy and maintain, and the accompanying Android app completes the picture.

Assuming that you have a virtual private server instance running a web server complete with a Let's Encrypt certificate, deploying Gotify is a rather straightforward affair. Create directories for use with Gotify:

sudo mkdir -p /opt/gotify
sudo mkdir -p /var/log/gotify/
sudo mkdir -p /etc/gotify/

Grab the latest release of Gotify from the Releases page. Extract the downloaded archive, rename the binary file to gotify, and move it to the /opt/gotify directory.

Next, download an example configuration file, and move it to the /etc/gotify directory:

wget -O config.yml https://raw.githubusercontent.com/gotify/server/master/config.example.yml
sudo mv config.example.yml /etc/gotify/config.yml

Use the sudo nano /etc/gotify/config.yml command to open the config.yml configuration file for editing. The relevant settings you need to change are as follows:

server:
  port: 1111
  ssl:
    enabled: true
    redirecttohttps: true
    port: 3333
    certfile: /etc/letsencrypt/live/hello.xyz/cert.pem
    certkey: /etc/letsencrypt/live/hello.xyz/privkey.pem

defaultuser:
  name: username
  pass: password

You can specify any ports — as long as they are not 80 and 443, because these two are used by the web server running on the VPS. Since the assumption is that the server has a Let's Encrypt certificate, you need to specify the paths of the existing cert.pem and privkey.pem files as certfile and certkey values. Finally, specify the desired username and password for the default administrator account. Save the changes, and set the correct permissions for all relevant files and directories:

sudo chmod -R go-rw /opt/gotify /etc/gotify/config.yml /var/log/gotify

At this point, you can launch Gotify manually, but a better approach is to create a systemd service that starts Gotify automatically and reboots it when necessary. Use the sudo nano /etc/systemd/system/gotify.service to create the gotify.service systemd unit file and open it for editing, then add the following configuration:

[Unit]
Description=Gotify
Requires=network.target
After=network.target

[Service]
Type=simple
User=root
WorkingDirectory=/opt/gotify
ExecStart=/opt/gotify/gotify
StandardOutput=append:/var/log/gotify/gotify.log
StandardError=append:/var/log/gotify/gotify-error.log
Restart=always
RestartSec=3

[Install]
WantedBy=multi-user.target

Save the file, and use the commands below to enable and start the service:

sudo systemctl enable gotify.service
sudo systemctl start gotify

Point the browser to https://127.0.0.1:3333 (replace 127.0.0.1 with the actual IP address or domain name of the server running Gotify and 3333 with the SSL port you specified in the config.yml file), and log in using the specified username and password.