diff options
Diffstat (limited to 'public/docs/production.html')
-rw-r--r-- | public/docs/production.html | 143 |
1 files changed, 143 insertions, 0 deletions
diff --git a/public/docs/production.html b/public/docs/production.html new file mode 100644 index 0000000..abb0b7c --- /dev/null +++ b/public/docs/production.html @@ -0,0 +1,143 @@ +<!doctype html> +<title>Public Server</title> +<link rel="stylesheet" href="style.css"> +<body> +<article> + +<h1> +Running a public server +</h1> + +<p> +To let other people connect to your server and play games, there are a few other things you will need to set up. + +<h2> +Recovering from a crash +</h2> + +<p> +Use <tt>nodemon</tt> to restart the server if it crashes. +This also restarts the server if the software is updated. + +<pre> +nodemon server.js +</pre> + +<h2> +Database & Backups +</h2> + +<p> +For best performance, you should turn on WAL mode on the database. + +<pre> +sqlite3 db "pragma journal_mode = wal" +</pre> + +<p> +You will want to backup your database periodically. This is easy to do with a single sqlite command. +Schedule the following command using cron or something similar, and make sure to copy the resulting +backup database to another machine! + +<pre> +sqlite3 db "vacuum into strftime('backup-%Y%m%d-%H%M.db')" +</pre> + +<h2> +Customize settings +</h2> + +<p> +The server reads its settings from the .env file. + +<pre> +NODE_ENV=production + +SITE_NAME=Example +SITE_URL=https://example.com +SITE_IMPRINT="This website is operated by ..." + +HTTP_HOST=localhost +HTTP_PORT=8080 + +# Enable mail notifications +MAIL_FROM=Example Notifications <notifications@example.com> +MAIL_HOST=localhost +MAIL_PORT=25 + +# Enable webhooks +WEBHOOKS=1 + +# Enable forum +FORUM=1 +</pre> + +<h2> +Expose the server to the internet +</h2> + +<p> +For simplicity, the server only talks plain HTTP on localhost. +To expose the server to your LAN and/or WAN, either listen to 0.0.0.0 or use a reverse proxy server such as Nginx. +To use SSL (HTTPS) you need a reverse proxy server. + +<p> +Here is an example Nginx configuration: + +<pre> +server { + listen 80; + server_name example.com www.example.com; + return 301 https://$host$request_uri; +} + +server { + listen 443 ssl; + server_name example.com www.example.com; + ssl_certificate /path/to/ssl/certificate/fullchain.cer; + ssl_certificate_key /path/to/ssl/certificate/example.com.key; + root /path/to/server/public; + location / { + try_files $uri @rally; + } + location @rally { + proxy_pass http://127.0.0.1:8080; + proxy_http_version 1.1; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_read_timeout 86400s; + proxy_send_timeout 86400s; + } +} +</pre> + +<h2> +Archive +</h2> + +<p> +Storing all the games ever played requires a lot of space. To keep the size of +the main database down, you can delete and/or archive finished games periodically. + +<p> +You can copy the game state and replay data for finished games to a separate archive database. +Below are the tools to archive (and restore) the game state data. +Run the archive and purge scripts as part of the backup cron job. + +<dl> +<dt> +<code>sqlite3 tools/archive.sql</code> +<dd> +Copy game state data of finished games into archive database. +<dt> +<code>sqlite3 tools/purge.sql</code> +<dd> +Delete game state data of finished games over a certain age. +<dt> +<code>bash tools/unarchive.sh <i>game_id</i></code> +<dd> +Restore archived game state. +</dl> + |