use docker-compose

This commit is contained in:
zino
2023-11-23 14:17:59 +01:00
parent f158380306
commit ea4f4bf850

View File

@@ -1,33 +1,27 @@
#!/bin/bash
# Set the container name as a variable
CONTAINER_NAME="lgsm-cs"
# Set the container service name as defined in docker-compose.yml
SERVICE_NAME="lgsm-cs"
# Function to check if the container is running
is_container_running() {
docker inspect -f '{{.State.Running}}' "${CONTAINER_NAME}" 2>/dev/null
}
# Function to wait for the container to be fully up and running
wait_for_container() {
echo "Waiting for container ${CONTAINER_NAME} to be fully up and running..."
while [ "$(docker inspect -f '{{.State.Running}}' "${CONTAINER_NAME}")" != "true" ]; do
sleep 1
done
echo "Container ${CONTAINER_NAME} is now up."
[ "$(docker-compose ps -q ${SERVICE_NAME} | xargs docker inspect -f '{{.State.Running}}' 2>/dev/null)" = "true" ]
}
# Function to execute commands in the container
execute_in_container() {
docker exec -d "${CONTAINER_NAME}" sh -c "$1"
docker-compose exec -d "${SERVICE_NAME}" sh -c "$1"
}
# Check if container is running
if [ "$(is_container_running)" != "true" ]; then
echo "Container ${CONTAINER_NAME} is not running. Starting it..."
docker start "${CONTAINER_NAME}"
wait_for_container
fi
# Start the container using docker-compose
docker-compose up -d "${SERVICE_NAME}"
# Wait for container to be fully up and running
echo "Waiting for container ${SERVICE_NAME} to be fully up and running..."
while ! is_container_running; do
sleep 1
done
echo "Container ${SERVICE_NAME} is now up."
# Moving and copying libstdc++.so.6
execute_in_container "mv /data/serverfiles/libstdc++.so.6 /data/serverfiles/libstdc++.so.6.bak && cp /usr/lib/x86_64-linux-gnu/libstdc++.so.6 /data/serverfiles/"
@@ -37,5 +31,5 @@ execute_in_container "mv /data/.local/share/Steam/steamcmd/linux32/libstdc++.so.
execute_in_container "mv /data/serverfiles/libgcc_s.so.1 /data/serverfiles/libgcc_s.so.1.bak && cp /usr/lib/x86_64-linux-gnu/libgcc_s.so.1 /data/serverfiles/"
# Shutdown the container after the fixes
echo "Shutting down the container ${CONTAINER_NAME}..."
docker stop "${CONTAINER_NAME}"
echo "Shutting down the container ${SERVICE_NAME}..."
docker-compose stop "${SERVICE_NAME}"