Update README and systemd service configuration for yourchat2. Added installation script install-systemd.sh for easier setup and modified yourchat2.service to improve service management, including environment file support and enhanced restart policies.

This commit is contained in:
Torsten Schulz (local)
2026-03-04 17:21:03 +01:00
parent 0b91b94ae1
commit 5c4ac55f61
4 changed files with 291 additions and 9 deletions

60
install-systemd.sh Executable file
View File

@@ -0,0 +1,60 @@
#!/usr/bin/env bash
set -euo pipefail
SERVICE_NAME="yourchat2"
PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SERVICE_SRC="${PROJECT_DIR}/yourchat2.service"
SERVICE_DST="/etc/systemd/system/${SERVICE_NAME}.service"
ENV_DIR="/etc/yourchat2"
ENV_FILE="${ENV_DIR}/yourchat2.env"
BIN_PATH="${PROJECT_DIR}/target/release/yourchat2"
if [[ "${EUID}" -ne 0 ]]; then
echo "Dieses Skript muss als root ausgefuehrt werden (z. B. via sudo)." >&2
exit 1
fi
if [[ ! -f "${SERVICE_SRC}" ]]; then
echo "Service-Datei nicht gefunden: ${SERVICE_SRC}" >&2
exit 1
fi
echo "[1/6] Build release binary ..."
sudo -u torsten cargo build --release --manifest-path "${PROJECT_DIR}/Cargo.toml"
if [[ ! -x "${BIN_PATH}" ]]; then
echo "Binary wurde nicht erzeugt: ${BIN_PATH}" >&2
exit 1
fi
echo "[2/6] Install service file ..."
install -m 0644 "${SERVICE_SRC}" "${SERVICE_DST}"
echo "[3/6] Ensure environment directory ..."
install -d -m 0755 "${ENV_DIR}"
echo "[4/6] Ensure environment file ..."
if [[ ! -f "${ENV_FILE}" ]]; then
cat > "${ENV_FILE}" <<'EOF'
# yourchat2 environment
# CHAT_WS_ADDR=0.0.0.0:1235
# CHAT_TCP_ADDR=127.0.0.1:1236
# CHAT_UNIX_SOCKET=/run/yourchat2/yourchat2.sock
# CHAT_ALLOWED_USERS=alice,bob
# CHAT_DB_URL=postgres://user:pass@host:5432/dbname
# SECRET_KEY=replace-with-real-secret
EOF
chmod 0640 "${ENV_FILE}"
chown root:root "${ENV_FILE}"
fi
echo "[5/6] Reload and enable service ..."
systemctl daemon-reload
systemctl enable --now "${SERVICE_NAME}.service"
echo "[6/6] Service status ..."
systemctl --no-pager --full status "${SERVICE_NAME}.service" || true
echo
echo "Fertig. Konfiguration bei Bedarf in ${ENV_FILE} anpassen."
echo "Danach neu laden mit: systemctl restart ${SERVICE_NAME}.service"