优化install.sh
This commit is contained in:
68
Install.sh
68
Install.sh
@@ -6,6 +6,7 @@
|
|||||||
# Colors for output
|
# Colors for output
|
||||||
RED='\033[0;31m'
|
RED='\033[0;31m'
|
||||||
GREEN='\033[0;32m'
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
BLUE='\033[0;34m'
|
BLUE='\033[0;34m'
|
||||||
NC='\033[0m' # No Color
|
NC='\033[0m' # No Color
|
||||||
|
|
||||||
@@ -23,20 +24,39 @@ REAL_USER=${SUDO_USER:-$USER}
|
|||||||
USER_HOME=$(getent passwd "$REAL_USER" | cut -d: -f6)
|
USER_HOME=$(getent passwd "$REAL_USER" | cut -d: -f6)
|
||||||
|
|
||||||
echo -e "Project Directory: ${GREEN}$PROJECT_DIR${NC}"
|
echo -e "Project Directory: ${GREEN}$PROJECT_DIR${NC}"
|
||||||
echo -e "Running User: ${GREEN}$REAL_USER${NC}"
|
echo -e "Running User: ${GREEN}$REAL_USER${NC}"
|
||||||
|
|
||||||
# 3. Check for dependencies
|
# 3. Check for mandatory files
|
||||||
if ! command -v node &> /dev/null; then
|
if [ ! -f "server/index.js" ]; then
|
||||||
echo -e "${RED}Node.js is not installed. Please install Node.js first.${NC}"
|
echo -e "${RED}Error: server/index.js not found. Please run this script from the project root.${NC}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! command -v npm &> /dev/null; then
|
# 4. Check for dependencies
|
||||||
echo -e "${RED}NPM is not installed. Please install NPM first.${NC}"
|
echo -e "${BLUE}Checking dependencies...${NC}"
|
||||||
exit 1
|
check_dep() {
|
||||||
|
if ! command -v "$1" &> /dev/null; then
|
||||||
|
echo -e "${RED}$1 is not installed. Please install $1 first.${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
check_dep node
|
||||||
|
check_dep npm
|
||||||
|
|
||||||
|
# 5. Check for .env file
|
||||||
|
if [ ! -f ".env" ]; then
|
||||||
|
echo -e "${YELLOW}Warning: .env file not found.${NC}"
|
||||||
|
if [ -f ".env.example" ]; then
|
||||||
|
echo -e "Creating .env from .env.example..."
|
||||||
|
cp .env.example .env
|
||||||
|
chown "$REAL_USER":"$REAL_USER" .env
|
||||||
|
echo -e "${GREEN}Created .env file. Please ensure values are correct.${NC}"
|
||||||
|
else
|
||||||
|
echo -e "${RED}Error: .env.example not found. Configuration missing.${NC}"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 4. Install NPM dependencies
|
# 6. Install NPM dependencies
|
||||||
echo -e "${BLUE}Installing dependencies...${NC}"
|
echo -e "${BLUE}Installing dependencies...${NC}"
|
||||||
# Run npm install as the real user to avoid permission issues in node_modules
|
# Run npm install as the real user to avoid permission issues in node_modules
|
||||||
sudo -u "$REAL_USER" npm install
|
sudo -u "$REAL_USER" npm install
|
||||||
@@ -46,7 +66,7 @@ if [ $? -ne 0 ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 5. Create Systemd Service File
|
# 7. Create Systemd Service File
|
||||||
SERVICE_FILE="/etc/systemd/system/data-wall.service"
|
SERVICE_FILE="/etc/systemd/system/data-wall.service"
|
||||||
NODE_PATH=$(command -v node)
|
NODE_PATH=$(command -v node)
|
||||||
|
|
||||||
@@ -55,7 +75,8 @@ echo -e "${BLUE}Creating systemd service at $SERVICE_FILE...${NC}"
|
|||||||
cat <<EOF > "$SERVICE_FILE"
|
cat <<EOF > "$SERVICE_FILE"
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Data Visualization Display Wall
|
Description=Data Visualization Display Wall
|
||||||
After=network.target mysql.service
|
After=network.target mysql.service redis-server.service valkey-server.service
|
||||||
|
Wants=mysql.service
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
@@ -67,28 +88,37 @@ RestartSec=10
|
|||||||
StandardOutput=syslog
|
StandardOutput=syslog
|
||||||
StandardError=syslog
|
StandardError=syslog
|
||||||
SyslogIdentifier=data-wall
|
SyslogIdentifier=data-wall
|
||||||
# Pass environment via .env file injection for flexibility
|
# Pass environment via .env file injection
|
||||||
EnvironmentFile=-$PROJECT_DIR/.env
|
EnvironmentFile=-$PROJECT_DIR/.env
|
||||||
Environment=NODE_ENV=production
|
Environment=NODE_ENV=production
|
||||||
|
|
||||||
|
# Security Hardening
|
||||||
|
CapabilityBoundingSet=
|
||||||
|
NoNewPrivileges=true
|
||||||
|
LimitNOFILE=65535
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# 6. Reload Systemd and Start
|
# 8. Reload Systemd and Start
|
||||||
echo -e "${BLUE}Reloading systemd and starting service...${NC}"
|
echo -e "${BLUE}Reloading systemd and restarting service...${NC}"
|
||||||
systemctl daemon-reload
|
systemctl daemon-reload
|
||||||
systemctl enable data-wall
|
systemctl enable data-wall
|
||||||
systemctl stop data-wall # Stop if already running
|
systemctl restart data-wall
|
||||||
systemctl start data-wall
|
|
||||||
|
|
||||||
# 7. Check Status
|
# 9. Check Status
|
||||||
|
echo -e "${BLUE}Checking service status...${NC}"
|
||||||
|
sleep 2
|
||||||
if systemctl is-active --quiet data-wall; then
|
if systemctl is-active --quiet data-wall; then
|
||||||
echo -e "${GREEN}SUCCESS: Service is now running.${NC}"
|
echo -e "${GREEN}SUCCESS: Service is now running.${NC}"
|
||||||
echo -e "You can access the dashboard at http://localhost:3000"
|
PORT=$(grep "^PORT=" .env | cut -d'=' -f2)
|
||||||
echo -e "View logs with: ${BLUE}journalctl -u data-wall -f${NC}"
|
PORT=${PORT:-3000}
|
||||||
|
echo -e "Dashboard URL: ${YELLOW}http://localhost:${PORT}${NC}"
|
||||||
|
echo -e "View logs: ${BLUE}journalctl -u data-wall -f${NC}"
|
||||||
else
|
else
|
||||||
echo -e "${RED}FAILED: Service failed to start. Check logs with 'journalctl -u data-wall -xe'${NC}"
|
echo -e "${RED}FAILED: Service failed to start.${NC}"
|
||||||
|
echo -e "Check logs with: ${BLUE}journalctl -u data-wall -xe${NC}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -e "${BLUE}================================================${NC}"
|
echo -e "${BLUE}================================================${NC}"
|
||||||
|
|||||||
Reference in New Issue
Block a user