From 01277eec820e85d809a221f5abdbe8ee1996765b Mon Sep 17 00:00:00 2001 From: clxud Date: Thu, 2 Jul 2026 02:22:42 +0000 Subject: [PATCH] Fix .env loading for standalone repo structure --- backend/src/main.rs | 6 +----- scripts/install-systemd-services.sh | 19 +++++++++++++++++++ systemd/tssbot-backend.service | 19 +++++++++++++++++++ 3 files changed, 39 insertions(+), 5 deletions(-) create mode 100755 scripts/install-systemd-services.sh create mode 100644 systemd/tssbot-backend.service diff --git a/backend/src/main.rs b/backend/src/main.rs index ea346f1..d7dbcc7 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -2344,11 +2344,7 @@ fn load_root_env() { env::current_dir() .ok() .and_then(|path| path.parent().map(|parent| parent.join(".env"))), - Some( - PathBuf::from(env!("CARGO_MANIFEST_DIR")) - .join("..") - .join(".env"), - ), + Some(PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(".env")), ]; for candidate in candidates.into_iter().flatten() { diff --git a/scripts/install-systemd-services.sh b/scripts/install-systemd-services.sh new file mode 100755 index 0000000..b53114e --- /dev/null +++ b/scripts/install-systemd-services.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +# Installs/updates the tssbot-backend systemd --user unit and (re)starts it. +set -euo pipefail + +repo_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +unit_dir="${HOME}/.config/systemd/user" +mkdir -p "${unit_dir}" + +ln -sf "${repo_dir}/systemd/tssbot-backend.service" "${unit_dir}/tssbot-backend.service" + +systemctl --user daemon-reload +systemctl --user enable --now tssbot-backend.service + +if [ "$(loginctl show-user "$(whoami)" -p Linger --value 2>/dev/null)" != "yes" ]; then + echo "Linger is not enabled for $(whoami) — user services will stop when you log out." + echo "Enable it with: sudo loginctl enable-linger $(whoami)" +fi + +systemctl --user status --no-pager tssbot-backend.service diff --git a/systemd/tssbot-backend.service b/systemd/tssbot-backend.service new file mode 100644 index 0000000..66ebce1 --- /dev/null +++ b/systemd/tssbot-backend.service @@ -0,0 +1,19 @@ +[Unit] +Description=tssbot backend API service +After=network-online.target +Wants=network-online.target +StartLimitIntervalSec=100 +StartLimitBurst=10 + +[Service] +Type=simple +WorkingDirectory=%h/tssbot.web-backend +ExecStart=%h/tssbot.web-backend/backend/target/release/tssbot-backend +Restart=on-failure +RestartSec=200ms +RestartSteps=10 +RestartMaxDelaySec=10s +TimeoutStopSec=10 + +[Install] +WantedBy=default.target