Skip to main content

Sample server

This document cover how to implement a production server for an application maked in Goffee.

Covers the implementation process on Debian Linux (version 12) providing detailed instructions tailored for this operating system. It guides you through the necessary steps for setting up the environment, installing dependencies, and configuring services to ensure a smooth deployment.

Server

Install the necesary packages as user root:

apt-get install redis certbot python3-certbot-nginx nginx sudo git libsqlite3-dev make gcc

Edit redis.conf and add a secure password directly in Redis’s configuration file

/etc/redis/redis.conf

# requirepass foobared

Uncomment it by removing the #, and change foobared to a secure password, then restart the service, run as root:

/etc/init.d/redis-server start

Enable redis service at boot

systemctl enable redis-server --now

User and files

Create a user for run the application. This user will be able to manage the servic, run as root:

adduser goffee

Enable sudo for the user

usermod -aG sudo goffee

Create the directory for the application, run as goffee user:

su -l goffee
mkdir ~/run

Copy the binary, .env file and storage folder inside run folder.

Inside run folder create one script to run called "run.sh" with the next content:

#!/bin/sh
SCRIPTPATH=$(cd "$(dirname "$0")"; pwd)
cd "$SCRIPTPATH"
"$SCRIPTPATH/appname" "prod"

Add execution persmisions, run as root:

chmod +x run.sh

The above directories and files should look like this::

/home/goffee/
/home/goffee/run
/home/goffee/run/.env
/home/goffee/run/run.sh
/home/goffee/run/goffee-appname
/home/goffee/run/storage/*

Service for the app

Create the next file to start the service managed by Debian, run as root:

/etc/systemd/system/goffee.service

The content of the file:

[Unit]
Description=Goffee app
After=network.target
StartLimitBurst=5
StartLimitIntervalSec=2
[Service]
Type=simple
Restart=always
RestartSec=1
User=goffee
ExecStart=/home/goffee/run/run.sh

[Install]
WantedBy=multi-user.target

Enable the service and start. Run as root:

systemctl enable goffee
systemctl start goffee

Enable user to user. Run as root:

visudo

Then, aggregate the user to enable the manage of the services without root permissions at the bottom of file:

goffee ALL = NOPASSWD:  /usr/sbin/service goffee restart
goffee ALL = NOPASSWD: /usr/sbin/service goffee stop
goffee ALL = NOPASSWD: /usr/sbin/service goffee start
goffee ALL = NOPASSWD: /usr/sbin/service goffee status

Proxy pass

This step can be optional. You can set up a web server to act as a proxy for your application. This can be useful if you have different applications on the same server and want to redirect them by domain (obviously, each Goffee application should have a different port and a different Redis database).

Install the Nginx web server as user root:

apt-get install nginx

Create new config file called "goffee" inside the folder "/etc/nginx/sites-enabled/":

/etc/nginx/sites-enabled/goffee.conf

The content of the file (assuming Goffee is running on port 8080):

    upstream ga { server 127.0.0.1:8080; }
server {
server_name yourdomain;
location / {
proxy_pass http://ga;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "upgrade";
}
}

Reload NGINX to apply the change.

systemctl reload nginx