-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_service.sh
executable file
·47 lines (38 loc) · 1015 Bytes
/
setup_service.sh
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
#!/bin/bash
# Variables
SERVICE_NAME="ioniqsoc"
DESCRIPTION="Hyundai Ioniq state of charge service"
USER=$(whoami)
WORKING_DIR=$(pwd)
SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service"
# Check if script is run as root
if [[ "$EUID" -ne 0 ]]; then
echo "Please run as root"
exit 1
fi
# Create systemd service file
echo "Creating systemd service file at ${SERVICE_FILE}..."
cat <<EOT > $SERVICE_FILE
[Unit]
Description=$DESCRIPTION
After=network.target
[Service]
ExecStart=/usr/bin/npm run serve
WorkingDirectory=$WORKING_DIR
Restart=always
RestartSec=10
User=$USER
Environment=NODE_ENV=production
[Install]
WantedBy=multi-user.target
EOT
# Reload systemd to apply new service
echo "Reloading systemd..."
systemctl daemon-reload
# Enable and start the service
echo "Enabling and starting $SERVICE_NAME service..."
systemctl enable $SERVICE_NAME.service
systemctl start $SERVICE_NAME.service
# Check status
echo "Checking status of $SERVICE_NAME service..."
systemctl status $SERVICE_NAME.service