-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.sh
50 lines (41 loc) · 1.36 KB
/
start.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
#!/bin/bash
# Name of the container
CONTAINER_NAME="volara_miner"
# Function to check if the container exists
container_exists() {
docker ps -a --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$"
}
# Function to check if the container is running
is_container_running() {
docker ps --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$"
}
# Function to run the container if it doesn't exist
run_container() {
echo "Running ${CONTAINER_NAME} container interactively..."
docker run -it -e VANA_PRIVATE_KEY=${VANA_PRIVATE_KEY} --name ${CONTAINER_NAME} volara/miner
}
# Function to start the container if it exists but is not running
start_container() {
echo "Starting ${CONTAINER_NAME} container interactively..."
docker start -i ${CONTAINER_NAME}
}
# Function to attach to a running container
attach_container() {
echo "Attaching to ${CONTAINER_NAME} container..."
docker attach --sig-proxy=false ${CONTAINER_NAME}
}
# Main script
if ! container_exists; then
run_container
elif ! is_container_running; then
start_container
else
echo "${CONTAINER_NAME} container is already running."
attach_container
fi
# Trap to handle SIGINT (Ctrl+C) gracefully
trap 'echo "Detached from container. To stop it, use: docker stop ${CONTAINER_NAME}"; exit' SIGINT
# Keep the script running to maintain the container connection
while true; do
sleep 1
done