diff --git a/README-DEPLOYMENT.md b/README-DEPLOYMENT.md new file mode 100644 index 0000000..9afa7f9 --- /dev/null +++ b/README-DEPLOYMENT.md @@ -0,0 +1,89 @@ +# Deployment-Anleitung für ypchat.net + +## Voraussetzungen + +- Die Anwendung muss nach `/opt/ypchat` kopiert werden +- Node.js muss installiert sein +- Apache muss konfiguriert sein + +## Schritte + +### 1. Anwendung nach /opt/ypchat kopieren + +```bash +# Als root oder mit sudo +sudo mkdir -p /opt/ypchat +sudo cp -r /home/torsten/Programs/SingleChat/* /opt/ypchat/ +sudo chown -R www-data:www-data /opt/ypchat +``` + +### 2. Installation durchführen + +```bash +cd /opt/ypchat +sudo -u www-data ./install.sh +``` + +### 3. Service installieren + +```bash +cd /opt/ypchat +sudo ./install-service-ypchat.sh +``` + +### 4. Alten Service stoppen + +```bash +sudo systemctl stop ypchat +sudo systemctl disable ypchat # Optional: Alten Service deaktivieren +``` + +### 5. Neuen Service starten + +```bash +sudo systemctl start ypchat +sudo systemctl status ypchat +``` + +### 6. Logs prüfen + +```bash +sudo journalctl -u ypchat -f +``` + +## Troubleshooting + +### Service startet nicht + +```bash +# Prüfe Logs +sudo journalctl -u ypchat -n 50 + +# Prüfe ob Node.js verfügbar ist +which node +/usr/bin/node --version + +# Prüfe ob .env existiert +ls -la /opt/ypchat/.env +cat /opt/ypchat/.env +``` + +### Alte Seite wird noch angezeigt + +1. Prüfe ob der neue Service läuft: `sudo systemctl status ypchat` +2. Prüfe ob Port 4000 belegt ist: `sudo lsof -i :4000` +3. Prüfe Apache-Logs: `sudo tail -f /var/log/apache2/error.log` +4. Apache neu laden: `sudo systemctl reload apache2` + +### Gebaute Dateien fehlen + +```bash +# Prüfe ob dist existiert +ls -la /opt/ypchat/docroot/dist + +# Falls nicht, baue neu: +cd /opt/ypchat +sudo -u www-data npm run build +sudo -u www-data cp -r client/dist docroot/ +``` + diff --git a/install-service-ypchat.sh b/install-service-ypchat.sh new file mode 100755 index 0000000..74d82c8 --- /dev/null +++ b/install-service-ypchat.sh @@ -0,0 +1,106 @@ +#!/bin/bash + +# SingleChat Systemd Service Installation für ypchat.net +# Erstellt einen systemd Service für SingleChat + +set -e + +SERVICE_NAME="ypchat" +SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service" +APP_DIR="/opt/ypchat" +USER="www-data" +GROUP="www-data" + +echo "==========================================" +echo "SingleChat Systemd Service Installation" +echo "==========================================" + +# Prüfe ob als root ausgeführt +if [ "$EUID" -ne 0 ]; then + echo "FEHLER: Dieses Skript muss als root ausgeführt werden!" + echo "Bitte führe aus: sudo ./install-service-ypchat.sh" + exit 1 +fi + +# Prüfe ob App-Verzeichnis existiert +if [ ! -d "$APP_DIR" ]; then + echo "FEHLER: App-Verzeichnis $APP_DIR existiert nicht!" + echo "Bitte kopiere die Anwendung nach $APP_DIR oder passe APP_DIR an." + exit 1 +fi + +# Prüfe ob .env Datei existiert +if [ ! -f "$APP_DIR/.env" ]; then + echo "WARNUNG: .env Datei nicht gefunden in $APP_DIR" + echo "Erstelle .env Datei..." + cat > "$APP_DIR/.env" << EOF +NODE_ENV=production +PORT=4000 +SESSION_SECRET=$(openssl rand -hex 32) +EOF + chown $USER:$GROUP "$APP_DIR/.env" + echo "✓ .env Datei erstellt" +fi + +# Erstelle Service-Datei +echo "Erstelle Service-Datei..." +cat > "$SERVICE_FILE" << EOF +[Unit] +Description=SingleChat Node.js Application +After=network.target + +[Service] +Type=simple +User=$USER +Group=$GROUP +WorkingDirectory=$APP_DIR +Environment="NODE_ENV=production" +Environment="PORT=4000" +EnvironmentFile=$APP_DIR/.env +ExecStart=/usr/bin/node server/index.js +Restart=always +RestartSec=10 +StandardOutput=journal +StandardError=journal +SyslogIdentifier=ypchat + +[Install] +WantedBy=multi-user.target +EOF + +echo "✓ Service-Datei erstellt: $SERVICE_FILE" + +# Lade systemd neu +echo "Lade systemd neu..." +systemctl daemon-reload + +echo "✓ systemd neu geladen" + +# Stoppe alten Service falls vorhanden +if systemctl is-active --quiet ypchat 2>/dev/null; then + echo "Stoppe alten Service..." + systemctl stop ypchat + echo "✓ Alter Service gestoppt" +fi + +# Aktiviere Service +echo "Aktiviere Service..." +systemctl enable $SERVICE_NAME + +echo "✓ Service aktiviert" + +echo "" +echo "==========================================" +echo "Service-Installation abgeschlossen!" +echo "==========================================" +echo "" +echo "Verfügbare Befehle:" +echo " Start: sudo systemctl start $SERVICE_NAME" +echo " Stop: sudo systemctl stop $SERVICE_NAME" +echo " Status: sudo systemctl status $SERVICE_NAME" +echo " Logs: sudo journalctl -u $SERVICE_NAME -f" +echo "" +echo "WICHTIG: Starte den Service mit:" +echo " sudo systemctl start $SERVICE_NAME" +echo "" +