-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_web_server.sh
More file actions
78 lines (64 loc) · 1.58 KB
/
install_web_server.sh
File metadata and controls
78 lines (64 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
set -e # Break execution on errors
# Configuration
APP_NAME="lineage2js-web-server"
APP_DIR="/opt/$APP_NAME"
REPO_URL="https://github.com/Lineage2JS/web-server.git"
echo "=== Deploying Lineage2 Web Server ==="
# Checking rights
if [[ $EUID -ne 0 ]]; then
echo "Error: Run script with sudo"
exit 1
fi
# Checking Node.js
if ! command -v node &> /dev/null; then
echo "Error: Node.js is not installed"
exit 1
fi
# Checking npm
if ! command -v npm &> /dev/null; then
echo "Error: npm is not installed"
exit 1
fi
# Creating a directory
echo "Creating a directory..."
mkdir -p $APP_DIR
# Cloning/updating a repository
echo "Cloning a repository..."
cd $APP_DIR
if [ -d ".git" ]; then
echo "Updating an existing repository..."
git pull
else
echo "Cloning a new repository..."
git clone $REPO_URL .
fi
# Installing dependencies
echo "Installing dependencies..."
npm ci --only=production
# Creating a service
echo "Creating a systemd service..."
cat > /etc/systemd/system/$APP_NAME.service << EOF
[Unit]
Description=Lineage2JS Web Server
After=network.target
[Service]
Type=simple
WorkingDirectory=$APP_DIR
Environment=NODE_ENV=production
Environment=STATIC_FILES_PATH=/var/www/html/lineage2js-web-ui/
ExecStart=/usr/bin/node server.js
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
EOF
# Starting the service
echo "Starting the service..."
systemctl daemon-reload
systemctl enable $APP_NAME
systemctl restart $APP_NAME
echo "=== Done! ==="
echo "App: $APP_DIR"
echo "Control: systemctl status $APP_NAME"
echo "Logs: journalctl -u $APP_NAME -f"