From a686977da6f041df9fcb858c08d40fa33793402c Mon Sep 17 00:00:00 2001 From: CN-JS-HuiBai Date: Sat, 4 Apr 2026 18:53:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=80=E9=94=AE=E5=AE=89?= =?UTF-8?q?=E8=A3=85=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Install.sh | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 Install.sh diff --git a/Install.sh b/Install.sh new file mode 100644 index 0000000..ddd7746 --- /dev/null +++ b/Install.sh @@ -0,0 +1,94 @@ +#!/bin/bash + +# Data Visualization Display Wall - Systemd Installer +# Requirements: Node.js, NPM, Systemd (Linux) + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +echo -e "${BLUE}=== Data Visualization Display Wall Installer ===${NC}" + +# 1. Check permissions +if [ "$EUID" -ne 0 ]; then + echo -e "${RED}Please run as root (sudo ./Install.sh)${NC}" + exit 1 +fi + +# 2. Get current directory and user +PROJECT_DIR=$(pwd) +REAL_USER=${SUDO_USER:-$USER} +USER_HOME=$(getent passwd "$REAL_USER" | cut -d: -f6) + +echo -e "Project Directory: ${GREEN}$PROJECT_DIR${NC}" +echo -e "Running User: ${GREEN}$REAL_USER${NC}" + +# 3. Check for dependencies +if ! command -v node &> /dev/null; then + echo -e "${RED}Node.js is not installed. Please install Node.js first.${NC}" + exit 1 +fi + +if ! command -v npm &> /dev/null; then + echo -e "${RED}NPM is not installed. Please install NPM first.${NC}" + exit 1 +fi + +# 4. Install NPM dependencies +echo -e "${BLUE}Installing dependencies...${NC}" +# Run npm install as the real user to avoid permission issues in node_modules +sudo -u "$REAL_USER" npm install + +if [ $? -ne 0 ]; then + echo -e "${RED}NPM install failed.${NC}" + exit 1 +fi + +# 5. Create Systemd Service File +SERVICE_FILE="/etc/systemd/system/data-wall.service" +NODE_PATH=$(command -v node) + +echo -e "${BLUE}Creating systemd service at $SERVICE_FILE...${NC}" + +cat < "$SERVICE_FILE" +[Unit] +Description=Data Visualization Display Wall +After=network.target mysql.service + +[Service] +Type=simple +User=$REAL_USER +WorkingDirectory=$PROJECT_DIR +ExecStart=$NODE_PATH server/index.js +Restart=always +RestartSec=10 +StandardOutput=syslog +StandardError=syslog +SyslogIdentifier=data-wall +Environment=NODE_ENV=production +Environment=PORT=3000 +# If you have specific env vars in .env, they will be loaded by the app's dotenv.config() + +[Install] +WantedBy=multi-user.target +EOF + +# 6. Reload Systemd and Start +echo -e "${BLUE}Reloading systemd and starting service...${NC}" +systemctl daemon-reload +systemctl enable data-wall +systemctl stop data-wall # Stop if already running +systemctl start data-wall + +# 7. Check Status +if systemctl is-active --quiet data-wall; then + echo -e "${GREEN}SUCCESS: Service is now running.${NC}" + echo -e "You can access the dashboard at http://localhost:3000" + echo -e "View logs with: ${BLUE}journalctl -u data-wall -f${NC}" +else + echo -e "${RED}FAILED: Service failed to start. Check logs with 'journalctl -u data-wall -xe'${NC}" +fi + +echo -e "${BLUE}================================================${NC}"