Fix PM2 start when running as root

This commit is contained in:
nmemmert committed 2025-12-04 12:34:27 -05:00
1 parent 36238311c2
commit a24d901620
1 file changed
+5 -4
+5 -4
View File
@@ -115,12 +115,13 @@ fi
# Start with PM2 # Start with PM2
echo "" echo ""
echo "Step 9: Starting application..." echo "Step 9: Starting application..."
cd "$INSTALL_DIR"
if [ "$EUID" -eq 0 ]; then if [ "$EUID" -eq 0 ]; then
su - $SERVICE_USER -c "cd $INSTALL_DIR && pm2 delete resource-monitor 2>/dev/null || true" sudo -u $SERVICE_USER pm2 delete resource-monitor 2>/dev/null || true
su - $SERVICE_USER -c "cd $INSTALL_DIR && pm2 start server/index.js --name resource-monitor" sudo -u $SERVICE_USER pm2 start server/index.js --name resource-monitor
su - $SERVICE_USER -c "pm2 save" sudo -u $SERVICE_USER pm2 save
env PATH=$PATH:/usr/bin pm2 startup systemd -u $SERVICE_USER --hp /home/$SERVICE_USER env PATH=$PATH:/usr/bin pm2 startup systemd -u $SERVICE_USER --hp /home/$SERVICE_USER
su - $SERVICE_USER -c "pm2 save" sudo -u $SERVICE_USER pm2 save
else else
pm2 delete resource-monitor 2>/dev/null || true pm2 delete resource-monitor 2>/dev/null || true
pm2 start server/index.js --name resource-monitor pm2 start server/index.js --name resource-monitor