Skip to content
James Culbertson edited this page Sep 19, 2023 · 9 revisions

Deployment

The site can be deployed for availability on the Internet for viewing the website and reports remotely. It is also optimized for viewing in a mobile phone which is a nice option for keeping track of your website availability on the go. There are a number of options for deploying it and one of these will be reviewed here.

Hosting

There are many hosting options but if you don't already have one available it is recommended to use a VPS or cloud VM if you don't already have one available. I've successfully deployed the application on a DigitalOcean 512MB 1 Core Droplet ($4 per month).

Web Server

Apache and NGINX are good options for serving the website and the app can also serve itself by configuring the port that is used (config.toml). Since the application involves login it is recommended to set up a certificate for serving over https. The Caddy web server can take care of this concern by automatically setting up a free https certificate. Following is an example caddyfile configuration for GoPingsites:

gopingsites.yourwebsite.com {
    proxy / localhost:8000
}

The proxy directive above redirects requests to the subdomain gopingsites to the GoPingSites application running on port 8000.

Running as a Service

It is recommended to run the GoPingSites application and Caddy web server (if applicable) as a service so that it will restart when the machine reboots. In the DigitalOcean and Caddy scenario described above I was able to use the systemd service on an Ubuntu server as described in this article: Keep Caddy Running. In the examples below the services are set up to run as less-privileged users (caddy and gopingsites) rather than the root user for improved security.

Below are the contents of the systemd configuration file /etc/systemd/system/go-ping-sites.service for running as a local user named gopingsites:

# go-ping-sites.service

[Unit]
Description=go-ping-sites

[Service]
User=gopingsites
WorkingDirectory=/home/gopingsites/gopingsites
ExecStart=/home/gopingsites/gopingsites/go-ping-sites
Restart=always

[Install]
WantedBy=multi-user.target

Below are the contents of the systemd configuration file /etc/systemd/system/caddy.service for running as a local user named caddy:

# caddy.service

[Unit]
Description=Caddy
Documentation=https://caddyserver.com/docs/
After=network.target

[Service]
User=caddy
ExecStart=/usr/local/bin/caddy run --environ --config /etc/caddy/Caddyfile
ExecReload=/usr/local/bin/caddy reload --config /etc/caddy/Caddyfile
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512
PrivateTmp=true
ProtectSystem=full
AmbientCapabilities=CAP_NET_BIND_SERVICE

[Install]
WantedBy=multi-user.target

After those have been setup, the services can be started with:

sudo systemctl start go-ping-sites
sudo systemctl start caddy

Use the restart command if they ever have to be restarted.

To make sure the lesser user can bind to port 80 to renew, etc:

setcap 'cap_net_bind_service=+ep' /usr/local/bin/caddy