112 lines
3.3 KiB
Bash
112 lines
3.3 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
source ./lib.sh
|
|
|
|
log "systemd Units (Reverb / Scheduler / Queue / Mail) …"
|
|
|
|
cat > /etc/systemd/system/${APP_USER}-ws.service <<EOF
|
|
[Unit]
|
|
Description=${APP_NAME} WebSocket Backend
|
|
After=network-online.target
|
|
Wants=network-online.target
|
|
[Service]
|
|
Type=simple
|
|
Environment=NODE_ENV=production WS_PORT=8080
|
|
User=${APP_USER}
|
|
Group=${APP_GROUP}
|
|
WorkingDirectory=${APP_DIR}
|
|
ExecStartPre=/usr/bin/bash -lc 'test -f .env'
|
|
ExecStartPre=/usr/bin/bash -lc 'test -d vendor'
|
|
ExecStart=/usr/bin/php artisan reverb:start --host=127.0.0.1 --port=8080 --no-interaction
|
|
Restart=always
|
|
RestartSec=2
|
|
StandardOutput=append:/var/log/${APP_USER}-ws.log
|
|
StandardError=append:/var/log/${APP_USER}-ws.log
|
|
KillSignal=SIGINT
|
|
TimeoutStopSec=15
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOF
|
|
|
|
cat > /etc/systemd/system/${APP_USER}-schedule.service <<EOF
|
|
[Unit]
|
|
Description=${APP_NAME} Laravel Scheduler
|
|
After=network-online.target
|
|
Wants=network-online.target
|
|
[Service]
|
|
Type=simple
|
|
User=${APP_USER}
|
|
Group=${APP_GROUP}
|
|
WorkingDirectory=${APP_DIR}
|
|
ExecStartPre=/usr/bin/bash -lc 'test -f .env'
|
|
ExecStartPre=/usr/bin/bash -lc 'test -d vendor'
|
|
ExecStart=/usr/bin/php artisan schedule:work
|
|
Restart=always
|
|
RestartSec=2
|
|
StandardOutput=append:/var/log/${APP_USER}-schedule.log
|
|
StandardError=append:/var/log/${APP_USER}-schedule.log
|
|
KillSignal=SIGINT
|
|
TimeoutStopSec=15
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOF
|
|
|
|
cat > /etc/systemd/system/${APP_USER}-queue.service <<EOF
|
|
[Unit]
|
|
Description=${APP_NAME} Queue Worker
|
|
After=network-online.target
|
|
Wants=network-online.target
|
|
[Service]
|
|
Type=simple
|
|
User=${APP_USER}
|
|
Group=${APP_GROUP}
|
|
WorkingDirectory=${APP_DIR}
|
|
ExecStartPre=/usr/bin/bash -lc 'test -f .env'
|
|
ExecStartPre=/usr/bin/bash -lc 'test -d vendor'
|
|
ExecStart=/usr/bin/php artisan queue:work --queue=default,notify --tries=1
|
|
Restart=always
|
|
RestartSec=2
|
|
StandardOutput=append:/var/log/${APP_USER}-queue.log
|
|
StandardError=append:/var/log/${APP_USER}-queue.log
|
|
KillSignal=SIGINT
|
|
TimeoutStopSec=15
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOF
|
|
|
|
chown root:root /etc/systemd/system/${APP_USER}-*.service
|
|
chmod 644 /etc/systemd/system/${APP_USER}-*.service
|
|
touch /var/log/${APP_USER}-ws.log /var/log/${APP_USER}-schedule.log /var/log/${APP_USER}-queue.log
|
|
chown ${APP_USER}:${APP_GROUP} /var/log/${APP_USER}-*.log
|
|
chmod 664 /var/log/${APP_USER}-*.log
|
|
|
|
systemctl daemon-reload
|
|
|
|
# App-Dienste
|
|
if sudo -u "$APP_USER" -H bash -lc "cd ${APP_DIR} && php artisan list --no-ansi | grep -qE '(^| )reverb:start( |$)'"; then
|
|
systemctl enable --now ${APP_USER}-ws
|
|
else
|
|
systemctl disable --now ${APP_USER}-ws >/dev/null 2>&1 || true
|
|
fi
|
|
systemctl enable --now ${APP_USER}-schedule
|
|
systemctl enable --now ${APP_USER}-queue
|
|
|
|
# Webstack
|
|
systemctl reload nginx || true
|
|
systemctl restart php*-fpm || true
|
|
|
|
# Mail-Dienste JETZT starten (damit 25/465/587 offen sind)
|
|
systemctl enable --now rspamd opendkim || true
|
|
systemctl enable --now postfix
|
|
systemctl enable --now dovecot
|
|
|
|
# Falls DB-Migration schon durch: einmal reload
|
|
db_ready(){ mysql -u"${DB_USER}" -p"${DB_PASS}" -h 127.0.0.1 -D "${DB_NAME}" -e "SHOW TABLES LIKE 'migrations'\G" >/dev/null 2>&1; }
|
|
if db_ready; then
|
|
systemctl reload postfix || true
|
|
systemctl reload dovecot || true
|
|
fi
|
|
|
|
# Mini-Portcheck (hilft beim Installer-Output)
|
|
echo "Listening (25/465/587):"
|
|
ss -ltnp | awk '$4 ~ /:(25|465|587)$/ {print " " $0}' |