diff --git a/backend/src/server.ts b/backend/src/server.ts index 6d900c1..d5d70bb 100644 --- a/backend/src/server.ts +++ b/backend/src/server.ts @@ -42,8 +42,8 @@ app.get("/:lang", (req, res) => { app.use("/css", express.static(appRoot.path + "/frontend/styles")); app.use("/js", express.static(appRoot.path + "/frontend/out")); -function addWebsocket(baseApp) { - const app = ws(baseApp).app; +function addWebsocket(baseApp: express.Express, httpsServer: https.Server) { + const app = ws(baseApp, httpsServer).app; app.ws("/api/v1/ws", (ws, req) => { const lang = getQueryParams(req).get("lang"); if (!lang) { @@ -70,19 +70,17 @@ function addWebsocket(baseApp) { } if (useTLS) { - addWebsocket( - https.createServer( - { - key: Buffer.from(process.env.TLS_PRIVATE_KEY, "base64").toString( - "ascii" - ), - cert: Buffer.from(process.env.TLS_CERTIFICATE, "base64").toString( - "ascii" - ), - }, - app - ) - ).listen(tlsPort, host, () => + const httpsServer = https.createServer( + { + key: Buffer.from(process.env.TLS_PRIVATE_KEY, "base64").toString("ascii"), + cert: Buffer.from(process.env.TLS_CERTIFICATE, "base64").toString( + "ascii" + ), + }, + app + ); + addWebsocket(app, httpsServer); + httpsServer.listen(tlsPort, host, () => console.log(`Listening on https://${host}:${tlsPort}`) ); http @@ -96,7 +94,8 @@ if (useTLS) { console.log(`Listening on http://${host}:${port}`) ); } else { - addWebsocket(app).listen(port, host, () => + addWebsocket(app, undefined); + app.listen(port, host, () => console.log(`Listening on http://${host}:${port}`) ); } diff --git a/scripts/install.py b/scripts/install.py index 389959f..4c0ec75 100755 --- a/scripts/install.py +++ b/scripts/install.py @@ -41,6 +41,11 @@ with tempfile.TemporaryDirectory() as tmpdir: subprocess.run(["make", "image-prod"], check=True) subprocess.run(["scripts/install-scripts.bash"], check=True) subprocess.run(["docker", "system", "prune", "-f"], check=True) + existing_containers = subprocess.run( + ["docker", "ps", "-q"], check=True, stdout=subprocess.PIPE + ).output.splitlines() + if existing_containers: + subprocess.run(["docker", "kill", *existing_containers], check=True) subprocess.run(["systemctl", "restart", "riju"], check=True) print("==> Successfully deployed Riju! <==", file=sys.stderr)