-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathctl.sh
executable file
·37 lines (32 loc) · 888 Bytes
/
ctl.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
#!/usr/bin/env bash
CONTAINER_NAME='client'
FORMAT_OUTPUT='table'
SHELL=/bin/bash
logger(){
echo -e "[`date "+%Y.%m.%d-%H:%M:%S %Z"`] - ${1} - ${2}"
}
yes_or_no() {
while true; do
read -p "[data] input 'yes' o 'no': " input
case "$input" in
[Yy]|[Yy][Ee][Ss]) return 0 ;;
[Nn]|[Nn][Oo]) return 1 ;;
*) echo "[data] please, input 'yes' o 'no'" ;;
esac
done
}
if [[ ! $(which docker) ]]; then
logger ERROR "docker is not installed"
exit 1
fi
if [[ $(docker ps -a --format '{{.Names}}' | grep -E "${CONTAINER_NAME}") ]]; then
eval "docker exec -it ${CONTAINER_NAME} etcdctl $@" < /dev/tty
else
logger WARN 'not found container client'
logger INFO 'probe `docker-compose up -d`'
logger "launch docker-compose ? (yes/no)"
if yes_or_no; then
docker-compose up -d
logger INFO 'relaunch the command'
fi
fi