-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathupgrade-node.sh
executable file
·64 lines (51 loc) · 1.42 KB
/
upgrade-node.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env bash
# Variables
USER_NAME=${SUDO_USER:-$(whoami)}
SERVICE_NAME="dig@$USER_NAME.service"
# Function to detect the Docker Compose command
detect_docker_compose_cmd() {
if command -v docker-compose >/dev/null 2>&1; then
echo "docker-compose"
elif docker compose version >/dev/null 2>&1; then
echo "docker compose"
else
echo ""
fi
}
# Detect Docker Compose command
DOCKER_COMPOSE_CMD=$(detect_docker_compose_cmd)
# Check if the script is being run as root
if [ "$EUID" -ne 0 ]; then
echo "Please run as root"
exit 1
fi
# Check if Docker Compose is installed
if [ -z "$DOCKER_COMPOSE_CMD" ]; then
echo "Docker Compose is not installed. Exiting..."
exit 1
fi
# Stop the service
echo "Stopping $SERVICE_NAME service..."
systemctl stop "$SERVICE_NAME"
if [ $? -ne 0 ]; then
echo "Failed to stop the service. Exiting..."
exit 1
fi
# Pull the latest Docker images using the detected Docker Compose command
echo "Pulling latest Docker images..."
$DOCKER_COMPOSE_CMD pull
if [ $? -ne 0 ]; then
echo "Failed to pull latest Docker images. Exiting..."
exit 1
fi
# Start the service
echo "Starting $SERVICE_NAME service..."
systemctl start "$SERVICE_NAME"
if [ $? -ne 0 ]; then
echo "Failed to start the service. Exiting..."
exit 1
fi
# Verify the service is running
echo "Checking status of $SERVICE_NAME service..."
systemctl status "$SERVICE_NAME"
echo "Node upgrade complete."