mirror of
https://github.com/OHV-IT/collabrix.git
synced 2025-12-15 16:48:36 +01:00
Add Systemd Service for Persistent Background Services
- teamchat.service: Systemd service configuration - install-service.sh: Automated service installer - SYSTEMD_INSTALL_README.md: Complete installation guide - Automatic start on boot with failure recovery - Proper logging to systemd journal - Root user configuration (can be customized) - Troubleshooting and management commands
This commit is contained in:
parent
9daab3cdf4
commit
b10078dc2e
126
SYSTEMD_INSTALL_README.md
Normal file
126
SYSTEMD_INSTALL_README.md
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
# Team Chat System - Systemd Service Installation
|
||||||
|
|
||||||
|
## 🚀 Schnellinstallation
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Als root ausführen
|
||||||
|
sudo ./install-service.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
## 📋 Was passiert bei der Installation?
|
||||||
|
|
||||||
|
1. **Service-Datei kopieren** → `/etc/systemd/system/teamchat.service`
|
||||||
|
2. **Systemd neu laden** → `systemctl daemon-reload`
|
||||||
|
3. **Service aktivieren** → Automatischer Start beim Boot
|
||||||
|
4. **Service starten** → Sofortiger Start
|
||||||
|
5. **Status prüfen** → Bestätigung der erfolgreichen Installation
|
||||||
|
|
||||||
|
## 🎯 Nach der Installation
|
||||||
|
|
||||||
|
### Service verwalten:
|
||||||
|
```bash
|
||||||
|
# Status prüfen
|
||||||
|
sudo systemctl status teamchat
|
||||||
|
|
||||||
|
# Service stoppen
|
||||||
|
sudo systemctl stop teamchat
|
||||||
|
|
||||||
|
# Service starten
|
||||||
|
sudo systemctl start teamchat
|
||||||
|
|
||||||
|
# Neustart
|
||||||
|
sudo systemctl restart teamchat
|
||||||
|
```
|
||||||
|
|
||||||
|
### Logs anzeigen:
|
||||||
|
```bash
|
||||||
|
# Live-Logs
|
||||||
|
sudo journalctl -u teamchat -f
|
||||||
|
|
||||||
|
# Letzte 50 Zeilen
|
||||||
|
sudo journalctl -u teamchat -n 50
|
||||||
|
```
|
||||||
|
|
||||||
|
### Service deaktivieren:
|
||||||
|
```bash
|
||||||
|
# Automatischen Start deaktivieren
|
||||||
|
sudo systemctl disable teamchat
|
||||||
|
|
||||||
|
# Service komplett entfernen
|
||||||
|
sudo systemctl stop teamchat
|
||||||
|
sudo rm /etc/systemd/system/teamchat.service
|
||||||
|
sudo systemctl daemon-reload
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🔧 Troubleshooting
|
||||||
|
|
||||||
|
### Service startet nicht:
|
||||||
|
```bash
|
||||||
|
# Detaillierte Fehler anzeigen
|
||||||
|
sudo systemctl status teamchat -l
|
||||||
|
|
||||||
|
# Systemd-Logs prüfen
|
||||||
|
sudo journalctl -u teamchat --no-pager
|
||||||
|
```
|
||||||
|
|
||||||
|
### Berechtigungsprobleme:
|
||||||
|
```bash
|
||||||
|
# Service-Datei prüfen
|
||||||
|
ls -la /etc/systemd/system/teamchat.service
|
||||||
|
|
||||||
|
# User in Service-Datei anpassen (falls nicht root)
|
||||||
|
sudo nano /etc/systemd/system/teamchat.service
|
||||||
|
# User=your_username ändern
|
||||||
|
sudo systemctl daemon-reload
|
||||||
|
sudo systemctl restart teamchat
|
||||||
|
```
|
||||||
|
|
||||||
|
### Port-Konflikte:
|
||||||
|
```bash
|
||||||
|
# Prüfe verwendete Ports
|
||||||
|
sudo netstat -tlnp | grep -E ':(8000|5173|80)'
|
||||||
|
|
||||||
|
# Ports in service-manager.sh anpassen falls nötig
|
||||||
|
sudo nano /home/OfficeDesk/service-manager.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
## 📊 Service-Details
|
||||||
|
|
||||||
|
- **Name:** `teamchat`
|
||||||
|
- **Beschreibung:** Team Chat System
|
||||||
|
- **User:** `root` (kann angepasst werden)
|
||||||
|
- **Working Directory:** `/home/OfficeDesk`
|
||||||
|
- **Auto-Start:** Beim System-Boot
|
||||||
|
- **Restart:** Bei Fehlern automatisch neu starten
|
||||||
|
- **Logs:** Systemd Journal (`journalctl`)
|
||||||
|
|
||||||
|
## 🔄 Alternative: Screen/Tmux
|
||||||
|
|
||||||
|
Falls Systemd nicht gewünscht ist:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Screen installieren
|
||||||
|
sudo apt install screen
|
||||||
|
|
||||||
|
# Session starten
|
||||||
|
screen -S teamchat
|
||||||
|
|
||||||
|
# Services starten
|
||||||
|
./service-manager.sh start
|
||||||
|
|
||||||
|
# Detach (Strg+A, D)
|
||||||
|
# Zurück: screen -r teamchat
|
||||||
|
```
|
||||||
|
|
||||||
|
## ✅ Erfolgreiche Installation prüfen
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Sollte "active (running)" zeigen
|
||||||
|
sudo systemctl status teamchat
|
||||||
|
|
||||||
|
# Sollte die Webseite laden
|
||||||
|
curl -I http://192.168.0.12
|
||||||
|
|
||||||
|
# Sollte JSON zurückgeben
|
||||||
|
curl http://localhost:8000/docs
|
||||||
|
```
|
||||||
91
install-service.sh
Executable file
91
install-service.sh
Executable file
@ -0,0 +1,91 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Team Chat System - Systemd Service Installer
|
||||||
|
# Installiert den Team Chat als Systemd-Service für automatischen Start
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
SERVICE_NAME="teamchat"
|
||||||
|
SERVICE_FILE="/home/OfficeDesk/teamchat.service"
|
||||||
|
SYSTEMD_PATH="/etc/systemd/system/${SERVICE_NAME}.service"
|
||||||
|
|
||||||
|
# Farben
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
BLUE='\033[0;34m'
|
||||||
|
NC='\033[0m'
|
||||||
|
|
||||||
|
log() {
|
||||||
|
echo -e "${GREEN}[$(date +'%Y-%m-%d %H:%M:%S')] $1${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
error() {
|
||||||
|
echo -e "${RED}[ERROR] $1${NC}" >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
warning() {
|
||||||
|
echo -e "${YELLOW}[WARNING] $1${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
info() {
|
||||||
|
echo -e "${BLUE}[INFO] $1${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Prüfe Root-Rechte
|
||||||
|
if [[ $EUID -ne 0 ]]; then
|
||||||
|
error "Dieses Script muss als root ausgeführt werden!"
|
||||||
|
echo "Verwendung: sudo $0"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
log "Installiere Team Chat System als Systemd-Service..."
|
||||||
|
|
||||||
|
# Kopiere Service-Datei
|
||||||
|
log "Kopiere Service-Datei nach $SYSTEMD_PATH"
|
||||||
|
cp "$SERVICE_FILE" "$SYSTEMD_PATH"
|
||||||
|
|
||||||
|
# Setze korrekte Berechtigungen
|
||||||
|
chmod 644 "$SYSTEMD_PATH"
|
||||||
|
|
||||||
|
# Systemd neu laden
|
||||||
|
log "Lade Systemd-Konfiguration neu..."
|
||||||
|
systemctl daemon-reload
|
||||||
|
|
||||||
|
# Service aktivieren
|
||||||
|
log "Aktiviere Service für automatischen Start beim Boot..."
|
||||||
|
systemctl enable "$SERVICE_NAME"
|
||||||
|
|
||||||
|
# Service starten
|
||||||
|
log "Starte Team Chat Service..."
|
||||||
|
systemctl start "$SERVICE_NAME"
|
||||||
|
|
||||||
|
# Warte kurz
|
||||||
|
sleep 3
|
||||||
|
|
||||||
|
# Status prüfen
|
||||||
|
log "Prüfe Service-Status..."
|
||||||
|
if systemctl is-active --quiet "$SERVICE_NAME"; then
|
||||||
|
log "✅ Service erfolgreich gestartet!"
|
||||||
|
echo ""
|
||||||
|
echo "=== Service Status ==="
|
||||||
|
systemctl status "$SERVICE_NAME" --no-pager -l
|
||||||
|
echo ""
|
||||||
|
echo "=== Nützliche Commands ==="
|
||||||
|
echo "Status prüfen: systemctl status $SERVICE_NAME"
|
||||||
|
echo "Service stoppen: systemctl stop $SERVICE_NAME"
|
||||||
|
echo "Service starten: systemctl start $SERVICE_NAME"
|
||||||
|
echo "Logs anzeigen: journalctl -u $SERVICE_NAME -f"
|
||||||
|
echo "Service deaktivieren: systemctl disable $SERVICE_NAME"
|
||||||
|
echo ""
|
||||||
|
info "Der Service startet jetzt automatisch beim System-Boot!"
|
||||||
|
else
|
||||||
|
error "Service konnte nicht gestartet werden!"
|
||||||
|
echo ""
|
||||||
|
echo "=== Debug Informationen ==="
|
||||||
|
systemctl status "$SERVICE_NAME" --no-pager -l
|
||||||
|
echo ""
|
||||||
|
echo "=== Logs ==="
|
||||||
|
journalctl -u "$SERVICE_NAME" --no-pager -n 20
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
22
teamchat.service
Normal file
22
teamchat.service
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Team Chat System
|
||||||
|
After=network.target postgresql.service
|
||||||
|
Requires=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
User=root
|
||||||
|
WorkingDirectory=/home/OfficeDesk
|
||||||
|
ExecStart=/home/OfficeDesk/service-manager.sh start
|
||||||
|
ExecStop=/home/OfficeDesk/service-manager.sh stop
|
||||||
|
Restart=always
|
||||||
|
RestartSec=5
|
||||||
|
StandardOutput=journal
|
||||||
|
StandardError=journal
|
||||||
|
SyslogIdentifier=teamchat
|
||||||
|
|
||||||
|
# Environment variables
|
||||||
|
Environment=NODE_ENV=production
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
Loading…
x
Reference in New Issue
Block a user