-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-service.sh
More file actions
executable file
·79 lines (60 loc) · 1.63 KB
/
install-service.sh
File metadata and controls
executable file
·79 lines (60 loc) · 1.63 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
79
#!/bin/bash
# Exit on any error
set -e
# Check if running as root
if [ "$EUID" -ne 0 ]; then
echo "Please run as root (use sudo)"
exit 1
fi
# Configuration
PROJECT_DIR=$(pwd)
SERVICE_NAME="cicd-cli-controller"
SERVICE_USER="cicd-service"
NODE_VERSION="19.x"
echo "Installing CICD CLI Controller Service..."
# Install Node.js if not present
if ! command -v node &> /dev/null; then
echo "Installing Node.js ${NODE_VERSION}..."
curl -fsSL https://deb.nodesource.com/setup_${NODE_VERSION} | bash -
apt-get install -y nodejs
fi
# Install dependencies
npm install --production
# Create systemd service file
cat > /etc/systemd/system/${SERVICE_NAME}.service << EOL
[Unit]
Description=CICD CLI Controller Service
After=network.target
[Service]
Type=simple
WorkingDirectory=${PROJECT_DIR}
ExecStart=/usr/bin/node src/server.js
Restart=always
RestartSec=10
StandardOutput=journal
StandardError=journal
SyslogIdentifier=${SERVICE_NAME}
Environment=NODE_ENV=production
EnvironmentFile=${PROJECT_DIR}/.env
[Install]
WantedBy=multi-user.target
EOL
# Reload systemd and enable service
systemctl daemon-reload
systemctl enable ${SERVICE_NAME}
systemctl start ${SERVICE_NAME}
echo "Service installation completed!"
echo "Service status:"
systemctl status ${SERVICE_NAME}
echo "
Installation complete! The service is now:
- Installed in ${PROJECT_DIR}
- Running as system service (${SERVICE_NAME})
- Configured to start automatically on boot
- Running as dedicated user ${SERVICE_USER}
You can manage the service with:
systemctl start ${SERVICE_NAME}
systemctl stop ${SERVICE_NAME}
systemctl restart ${SERVICE_NAME}
systemctl status ${SERVICE_NAME}
"