-
Notifications
You must be signed in to change notification settings - Fork 2
/
stop.sh
executable file
·54 lines (48 loc) · 1.69 KB
/
stop.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
#!/usr/bin/env bash
QUIET="$#"
BASE_PATH="$(dirname "$0")"
cd $BASE_PATH;
source $BASE_PATH/inc/init
# checking if docker VM is running ($DEVDOCKER_VM)
if [ -x "$DOCKERMACHINE_PATH" ]; then
if [ "$("$DOCKERMACHINE" status $DEVDOCKER_VM 2>&1)" != "Running" ]; then
echo -ne "\033$TERM_COLOR_YELLOW"
echo "# Already stopped"
echo -ne "\033$TERM_COLOR_NORMAL"
exit
fi
# setting environment variables
source $BASE_PATH/inc/vm-eval
eval "$DOCKER_ENV_VARS"
fi
DEVDOCKER_IDS="$(docker ps | (grep "\<$DEVDOCKER_IMAGE\>" || true) | awk '{print $1}')"
if [ "$DEVDOCKER_IDS" == "" ]; then
echo -ne "\033$TERM_COLOR_YELLOW"
echo "# All devdocker containers are already stopped"
echo -ne "\033$TERM_COLOR_NORMAL"
else
echo -ne "\033$TERM_COLOR_GREEN"
echo "# Stopping devdocker containers:"
echo -ne "\033$TERM_COLOR_NORMAL"
docker stop "$DEVDOCKER_IDS"
sleep 1
fi
# cleanup exited devdocker containers
docker ps -a -q --filter "ancestor=$DEVDOCKER_IMAGE" | xargs -n 1 -I {} docker rm {} > /dev/null
if [ -x "$DOCKERMACHINE_PATH" ]; then
# remove non stopped forwarding ports ssh processes if any
PORT_FW_PID="$(ps auwx | (grep "$(echo $SSH_PORT_FW_CMD)" | grep -v 'grep' | grep -v 'sudo' || true) | awk '{print $2}')";
if [ "$PORT_FW_PID" != "" ]; then
if [[ "$QUIET" == "0" ]]; then
echo -ne "\033$TERM_COLOR_GREEN"
echo "# Remove ports forwarding"
echo -ne "\033$TERM_COLOR_NORMAL"
fi
sudo kill -KILL $PORT_FW_PID
fi
echo
echo -ne "\033$TERM_COLOR_GREEN"
echo "# You can stop Docker VM if necessary:"
echo -ne "\033$TERM_COLOR_NORMAL"
echo "./vm-stop.sh"
fi