]> littlesong.place Git - littlesongplace.git/commitdiff
Add systemd service files
authorChris Fulljames <christianfulljames@gmail.com>
Sun, 19 Jan 2025 15:47:40 +0000 (10:47 -0500)
committerChris Fulljames <christianfulljames@gmail.com>
Sun, 19 Jan 2025 15:47:40 +0000 (10:47 -0500)
main.py
requirements.txt
service/prod.service [new file with mode: 0644]
service/run.sh [new file with mode: 0644]
service/test.service [new file with mode: 0644]

diff --git a/main.py b/main.py
index 5bdf722343c2315ee46194266fd90d64f049989a..fca4eefc653bb6ac4c540d9c619c0b5982ec2f30 100644 (file)
--- a/main.py
+++ b/main.py
@@ -20,7 +20,7 @@ from flask import Flask, render_template, request, redirect, g, session, abort,
         send_from_directory, flash, get_flashed_messages
 from werkzeug.utils import secure_filename
 
-DATA_DIR = Path(".")
+DATA_DIR = Path(os.environ["DATA_DIR"]) if "DATA_DIR" in os.environ else Path(".")
 
 ################################################################################
 # Logging
@@ -38,7 +38,7 @@ root_logger.addHandler(handler)
 ################################################################################
 
 app = Flask(__name__)
-app.secret_key = "dev"
+app.secret_key = os.environ["SECRET_KEY"] if "SECRET_KEY" in os.environ else "dev"
 app.config["MAX_CONTENT_LENGTH"] = 50 * 1024 * 1024
 app.logger.addHandler(handler)
 
index d9c96abb20d3e95ec0609fe5e5a71881b53db6fd..6d89524c5bf95b25fafa060dfaba5f17280fc117 100644 (file)
@@ -1,4 +1,5 @@
 bcrypt
 bleach[css]
 flask
+gunicorn
 
diff --git a/service/prod.service b/service/prod.service
new file mode 100644 (file)
index 0000000..9fcc4cc
--- /dev/null
@@ -0,0 +1,12 @@
+[Unit]
+Description=Little Song Place Production Server
+After=multi-user.target
+
+[Service]
+WorkingDirectory=/var/www/littlesongplace
+ExecStart=/var/www/littlesongplace/service/run.sh 8080 /var/www/littlesongplace-data
+Restart=always
+
+[Install]
+WantedBy=multi-user.target
+
diff --git a/service/run.sh b/service/run.sh
new file mode 100644 (file)
index 0000000..c6a4a53
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/bash
+PORT=$1
+export DATA_DIR=$2
+export SECRET_KEY=$(< "$DATA_DIR/secret.key")
+. venv/bin/activate
+gunicorn -w 4 -b 127.0.0.1:$PORT 'main:app'
+
diff --git a/service/test.service b/service/test.service
new file mode 100644 (file)
index 0000000..ff2f783
--- /dev/null
@@ -0,0 +1,12 @@
+[Unit]
+Description=Little Song Place Test Server
+After=multi-user.target
+
+[Service]
+WorkingDirectory=/var/www/littlesongplace-test
+ExecStart=/var/www/littlesongplace-test/service/run.sh 8081 /var/www/littlesongplace-test-data
+Restart=always
+
+[Install]
+WantedBy=multi-user.target
+