Skip to content

Instantly share code, notes, and snippets.

@hypervtechnics
Last active December 22, 2023 08:45
Show Gist options
  • Save hypervtechnics/9cb28e67aea93cb9b87af5141bc3aa25 to your computer and use it in GitHub Desktop.
Save hypervtechnics/9cb28e67aea93cb9b87af5141bc3aa25 to your computer and use it in GitHub Desktop.

Revisions

  1. hypervtechnics revised this gist Aug 22, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion TUTORIAL.md
    Original file line number Diff line number Diff line change
    @@ -165,7 +165,7 @@ systemctl status gotify.service
    If you want to enable the autostart after boot you can enable it like this:

    ```bash
    systemclt enable gotify.service
    systemctl enable gotify.service
    ```

    ## 5. Setup caddy
  2. hypervtechnics revised this gist Nov 19, 2019. 1 changed file with 79 additions and 35 deletions.
    114 changes: 79 additions & 35 deletions TUTORIAL.md
    Original file line number Diff line number Diff line change
    @@ -1,42 +1,67 @@
    # How to install Gotify with Caddy

    In this guide I am going to use SQLite as storage mechanism.
    In this guide I assume you want to use SQLite as storage mechanism. I used Ubuntu 18.04 but there should be no real differences between the different versions/distributions as long as it has systemd installed.

    ## Change to install location
    All commands are executed as `root`. If you do not want to do this, prefix them with `sudo [command]`.

    ```bash
    cd /opt
    mkdir -p gotify
    cd gotify
    You'll need the tool `unzip`. If you didn't install it yet or don't know if it is installed just execute `apt install -y unzip`.

    Parts of this guide are taken from [this](https://github.com/caddyserver/caddy/tree/master/dist/init/linux-systemd) guide and are modified for Gotify.

    ## 1. Decide for a install location

    I used the following paths:

    ```text
    App: /opt/gotify/
    Config: /opt/gotify/config.yml
    Data: /opt/gotify/data/
    ```

    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/`.
    You of course be more compliant with the linux directories and use this structure:

    ## Get Gotify
    ```text
    App: /usr/local/bin/gotify
    Config: /etc/gotify/config.yml
    Data: /var/lib/gotify/
    ```

    First you have to get the download link to the binary of your architecture. Find the newest release [here](https://github.com/gotify/server/releases/latest).
    Choose what you want and look for placeholders and replace the values appropiatly in the config files/commands we are using throughout this guide. Now for my approach we would create the directory like this, as I prefer to have all server applications in the `/opt` directory:

    ```bash
    # Needed to unzip the downloaded file
    apt install -y unzip
    mkdir -p /opt/gotify
    cd /opt/gotify
    ```

    # Download the new release to gotify-download.zip and unzip it
    ## 2. Download Gotify

    First you have to get the download link to the binary of your architecture. Find the newest release [here](https://github.com/gotify/server/releases/latest) and replace `<releaseurl>`.

    Download the release package to gotify-download.zip and unzip it.

    ```bash
    wget -O gotify-download.zip <releaseurl>
    unzip gotify-download.zip
    ```

    # Rename the executable file to a more intuitive name and set permissions
    Rename the executable file to a more intuitive name and set permissions.

    ```bash
    mv gotify-<os>-<arch> gotify
    sudo chown root:root gotify
    sudo chmod 755 gotify
    ```

    Create a group and user for running the app.

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

    ## Setup configuration
    ## 3. Setup gotify 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.
    Put your configuration into the configuration file `config.yml`. It does not exist yet so you need to create it. Here is the configuration I used. Remember to **change the password**! Also for Caddy the port needs to be somewhat other than 80 or 443. I chose 3000 as its free on my machine but you might change it if you want to or the port is already in use. You might also change the paths according to your desired directory structure.

    ```yaml
    server:
    @@ -60,28 +85,32 @@ uploadedimagesdir: data/images # the directory for storing uploaded images
    pluginsdir: data/plugins # the directory where plugin resides (leave empty to disable plugins)
    ```
    After that:
    Then assign the correct permissions to the configuration file.
    ```bash
    # Assign correct permissions to config file
    chown root:root config.yml
    chmod 644 config.yml
    ```

    Create the data directory with correct permissions.

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

    ## Test if that worked until now
    You can test if you set it up correctly until now by executing this command:

    ```bash
    sudo -u gotify ./gotify
    ```

    ## Setup systemd service
    If you see something like `server started` and no errors everything is fine and you can exit again using `Ctrl + C`.

    ## 4. 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.
    Save this systemd service to `/etc/systemd/system/gotify.service`. Remember to replace the paths according to your situation if you wanted to change them.

    ```text
    [Unit]
    @@ -99,36 +128,49 @@ Restart=on-abnormal
    User=gotify
    Group=gotify
    WorkingDirectory=<installlocation>
    ExecStart=<installlocation>/gotify
    WorkingDirectory=/opt/gotify
    ExecStart=/opt/gotify/gotify
    PrivateTmp=true
    ProtectSystem=full
    ReadWritePaths=<datalocation>
    ReadWriteDirectories=<datalocation>
    ReadWritePaths=/opt/gotify/data
    ReadWriteDirectories=/opt/gotify/data
    TimeoutStopSec=5s
    [Install]
    WantedBy=multi-user.target
    ```

    Set the appropiate permissions for the service file.

    ```bash
    # Set permissions
    chown root:root /etc/systemd/system/gotify.service
    chmod 644 /etc/systemd/system/gotify.service
    ```

    # Activate it
    Tell systemd to reload and run it.

    ```bash
    systemctl daemon-reload
    systemctl start gotify.service
    ```

    You can verify if it worked by executing the following command and seeing the same output like in the previous test.

    ```bash
    systemctl status gotify.service
    ```

    If you want to enable the autostart after boot you can enable it like this:

    # Enable at boot
    ```bash
    systemclt enable gotify.service
    ```

    ## Setup caddy
    ## 5. Setup caddy

    Add the following to your `Caddyfile`.
    Add the following to your `Caddyfile`. If you set another port than 3000 remember to change it here too.

    ```text
    <domain> {
    @@ -145,6 +187,8 @@ Restart caddy and everything should be done.
    systemctl restart caddy
    ```

    Test by going to `https://<domain>/`.

    ## 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.
    - 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.
  3. hypervtechnics created this gist Nov 18, 2019.
    150 changes: 150 additions & 0 deletions TUTORIAL.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,150 @@
    # How to install Gotify with Caddy

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

    ## Change to install location

    ```bash
    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](https://github.com/gotify/server/releases/latest).

    ```bash
    # 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.

    ```yaml
    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:
    ```bash
    # 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

    ```bash
    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.

    ```text
    [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
    ```

    ```bash
    # 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`.

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

    Restart caddy and everything should be done.

    ```bash
    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.