Refactor install-systemd.sh and update yourchat2.service for improved installation and configuration. Added binary installation to /usr/local/bin, created work directory at /var/lib/yourchat2, and updated user/group settings. Enhanced README to reflect these changes.

This commit is contained in:
Torsten Schulz (local)
2026-03-04 17:23:29 +01:00
parent 5c4ac55f61
commit 91a58855eb
3 changed files with 23 additions and 11 deletions

View File

@@ -111,14 +111,16 @@ Es liegt eine Produktions-nahe Unit-Datei `yourchat2.service` im Projekt.
Zusaetzlich gibt es ein Installationsskript `install-systemd.sh`, das:
- Release-Binary baut
- Binary nach `/usr/local/bin/yourchat2` installiert
- Unit nach `/etc/systemd/system/yourchat2.service` installiert
- Arbeitsverzeichnis `/var/lib/yourchat2` erstellt
- Environment-Datei unter `/etc/yourchat2/yourchat2.env` anlegt (falls nicht vorhanden)
- Service aktiviert und startet
Installation:
```bash
cd ~/Programs/yourchat2
cd /home/tsschulz/Programs/yourchat2
sudo ./install-systemd.sh
```

View File

@@ -8,6 +8,9 @@ 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"
INSTALL_BIN="/usr/local/bin/yourchat2"
WORK_DIR="/var/lib/yourchat2"
BUILD_USER="tsschulz"
if [[ "${EUID}" -ne 0 ]]; then
echo "Dieses Skript muss als root ausgefuehrt werden (z. B. via sudo)." >&2
@@ -20,20 +23,27 @@ if [[ ! -f "${SERVICE_SRC}" ]]; then
fi
echo "[1/6] Build release binary ..."
sudo -u torsten cargo build --release --manifest-path "${PROJECT_DIR}/Cargo.toml"
sudo -u "${BUILD_USER}" 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 ..."
echo "[2/7] Install binary ..."
install -m 0755 "${BIN_PATH}" "${INSTALL_BIN}"
echo "[3/7] Install service file ..."
install -m 0644 "${SERVICE_SRC}" "${SERVICE_DST}"
echo "[3/6] Ensure environment directory ..."
echo "[4/7] Ensure environment directory ..."
install -d -m 0755 "${ENV_DIR}"
echo "[4/6] Ensure environment file ..."
echo "[5/7] Ensure work directory ..."
install -d -m 0750 "${WORK_DIR}"
chown "${BUILD_USER}:${BUILD_USER}" "${WORK_DIR}"
echo "[6/7] Ensure environment file ..."
if [[ ! -f "${ENV_FILE}" ]]; then
cat > "${ENV_FILE}" <<'EOF'
# yourchat2 environment
@@ -48,11 +58,11 @@ EOF
chown root:root "${ENV_FILE}"
fi
echo "[5/6] Reload and enable service ..."
echo "[7/7] Reload and enable service ..."
systemctl daemon-reload
systemctl enable --now "${SERVICE_NAME}.service"
echo "[6/6] Service status ..."
echo "[status] Service status ..."
systemctl --no-pager --full status "${SERVICE_NAME}.service" || true
echo

View File

@@ -5,15 +5,15 @@ Wants=network-online.target
[Service]
Type=simple
User=torsten
Group=torsten
WorkingDirectory=/home/torsten/Programs/yourchat2
User=tsschulz
Group=tsschulz
WorkingDirectory=/var/lib/yourchat2
EnvironmentFile=-/etc/yourchat2/yourchat2.env
Environment=CHAT_WS_ADDR=0.0.0.0:1235
Environment=CHAT_TCP_ADDR=127.0.0.1:1236
RuntimeDirectory=yourchat2
RuntimeDirectoryMode=0750
ExecStart=/home/torsten/Programs/yourchat2/target/release/yourchat2
ExecStart=/usr/local/bin/yourchat2
Restart=on-failure
RestartSec=2
TimeoutStopSec=15