-
Notifications
You must be signed in to change notification settings - Fork 1
/
stop.sh
executable file
·29 lines (24 loc) · 1.15 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
#!/bin/bash
# Exit 1 if any script fails.
set -e
# The docker container name has a default value.
DOCKER_CONTAINER_NAME="logstash-indexer";
# Get docker container states.
DOCKER_CONTAINER_RUNS=`docker ps | grep -q ${DOCKER_CONTAINER_NAME} && echo true || echo false`
DOCKER_CONTAINER_EXISTS=`docker ps -a | grep -q ${DOCKER_CONTAINER_NAME} && echo true || echo false`
# Stop container if running.
if $DOCKER_CONTAINER_RUNS; then {
printf "\n%s\n\n" "=== Stop running docker container [${DOCKER_CONTAINER_NAME}] ==="; \
docker stop ${DOCKER_CONTAINER_NAME}; ! docker ps | grep -q ${DOCKER_CONTAINER_NAME};
} else {
printf "\n%s\n" "=== No need to stop not running docker container [${DOCKER_CONTAINER_NAME}] ===";
} fi
# Remove container if exists and if no circleci environment.
if test -z "${CIRCLECI}"; then {
if $DOCKER_CONTAINER_EXISTS; then {
printf "\n%s\n\n" "=== Remove existing docker container [${DOCKER_CONTAINER_NAME}] ===";
docker rm -f ${DOCKER_CONTAINER_NAME}; ! docker ps -a | grep -q ${DOCKER_CONTAINER_NAME};
} else {
printf "\n%s\n" "=== No need to remove not existing docker container [${DOCKER_CONTAINER_NAME}] ===";
} fi
} fi