添加一键安装脚本
This commit is contained in:
94
Install.sh
Normal file
94
Install.sh
Normal file
@@ -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 <<EOF > "$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}"
|
||||
Reference in New Issue
Block a user