feat(server): use configurable startup settings

Load the listen address and port from settings, print connection guidance and explain startup failures.
This commit is contained in:
rekushi committed 2026-10-29 04:35:30 +00:00
1 parent ed8ac29cfa
commit d82cb81ca7
1 file changed
+33 -3
+33 -3
View File
@@ -4,8 +4,10 @@ from __future__ import annotations
import os
import sys
import time
import socket
from server_config import load_config
PORT = int(os.environ.get("REXIMEMO_PORT", "8080"))
DOCS_ARGUMENT = "docs:enabled"
@@ -68,13 +70,41 @@ def create_site(*, docs_enabled=False):
def main():
settings = load_config()
try:
port = int(os.environ.get("REXIMEMO_PORT", settings["port"]))
if not 1024 <= port <= 65535:
raise ValueError
except ValueError as exc:
raise SystemExit("Choose a port between 1024 and 65535 in server-settings.json or REXIMEMO_PORT.") from exc
host = os.environ.get("REXIMEMO_HOST", settings["host"])
docs_enabled = docs_enabled_from_args()
reactor, site, log = create_site(docs_enabled=docs_enabled)
log.write("RexiMemo OSE starting on port %d" % PORT)
log.write("%s starting on %s:%d" % (settings["site_name"], host, port))
log.write("Web client: http://127.0.0.1:%d/" % port)
try:
addresses = sorted({address[4][0] for address in socket.getaddrinfo(socket.gethostname(), None, socket.AF_INET)
if not address[4][0].startswith("127.")})
except OSError:
addresses = []
if host in {"0.0.0.0", "::"}:
for address in addresses:
log.write("DSi HTTP proxy: %s, port %d" % (address, port))
elif host not in {"127.0.0.1", "::1", "localhost"}:
log.write("DSi HTTP proxy: %s, port %d" % (host, port))
else:
log.write("Listening on this computer only. For a DSi on your network, choose listen address 0.0.0.0 during setup.")
if not settings["setup_complete"]:
log.write("First-run setup is available: python manage.py setup")
log.write("DSi mode uses the historical HTTP proxy path; NAS/DNS/auth services are not included.")
if docs_enabled:
log.write("Built-in documentation enabled at /docs")
reactor.listenTCP(PORT, site)
from twisted.internet.error import CannotListenError
try:
reactor.listenTCP(port, site, interface=host)
except CannotListenError as exc:
log.close()
raise SystemExit(f"Could not listen on {host}:{port}. Another server may already use that port. Stop it or choose another port with: python manage.py setup") from exc
try:
reactor.run()
finally: