|
1 | 1 | #!/usr/bin/env bash |
2 | 2 | # ------------------------------------------------------------------------------ |
3 | | -# Installer for PVESciptslocal |
| 3 | +# Installer for PVESciptslocal with systemd integration |
4 | 4 | # ------------------------------------------------------------------------------ |
5 | 5 |
|
6 | 6 | set -euo pipefail |
@@ -79,11 +79,46 @@ msg_info "Building application..." |
79 | 79 | npm run build |
80 | 80 | msg_ok "Build completed." |
81 | 81 |
|
82 | | -# --- Start the application --- |
83 | | -read -rp "Do you want to start the application now? (y/N): " START_APP |
84 | | -if [[ "$START_APP" =~ ^[Yy]$ ]]; then |
85 | | - msg_info "Starting application..." |
86 | | - npm start |
| 82 | +# --- Create systemd service --- |
| 83 | +SERVICE_NAME="pvescriptslocal" |
| 84 | +SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service" |
| 85 | + |
| 86 | +msg_info "Creating systemd service at $SERVICE_FILE..." |
| 87 | +cat > "$SERVICE_FILE" <<EOF |
| 88 | +[Unit] |
| 89 | +Description=PVEScriptslocal Service |
| 90 | +After=network.target |
| 91 | +
|
| 92 | +[Service] |
| 93 | +WorkingDirectory=${INSTALL_DIR} |
| 94 | +ExecStart=/usr/bin/npm start |
| 95 | +Restart=always |
| 96 | +RestartSec=10 |
| 97 | +Environment=NODE_ENV=production |
| 98 | +User=root |
| 99 | +
|
| 100 | +[Install] |
| 101 | +WantedBy=multi-user.target |
| 102 | +EOF |
| 103 | + |
| 104 | +systemctl daemon-reexec |
| 105 | +msg_ok "Systemd service created and started." |
| 106 | + |
| 107 | +# --- Enable/Start Service --- |
| 108 | +read -rp "Enable and start the service now? (y/N): " START_SERVICE |
| 109 | +if [[ "$START_SERVICE" =~ ^[Yy]$ ]]; then |
| 110 | + systemctl enable --now pvescriptslocal.service |
| 111 | + msg_ok "Service enabled and started. Check status with: systemctl status pvescriptslocal" |
87 | 112 | else |
88 | | - msg_info "You can start the app anytime by running: cd $INSTALL_DIR && npm start" |
| 113 | + msg_info "You can start it manually with: systemctl start pvescriptslocal" |
89 | 114 | fi |
| 115 | + |
| 116 | +echo |
| 117 | +echo "---------------------------------------------" |
| 118 | +echo " Service installed: $SERVICE_NAME" |
| 119 | +echo " Manage it with:" |
| 120 | +echo " systemctl start $SERVICE_NAME" |
| 121 | +echo " systemctl stop $SERVICE_NAME" |
| 122 | +echo " systemctl status $SERVICE_NAME" |
| 123 | +echo " App will be available at: http://<IP>:3000" |
| 124 | +echo "---------------------------------------------" |
0 commit comments