-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdocker_compose_bounce.sh
76 lines (67 loc) · 3.26 KB
/
docker_compose_bounce.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
# external variable sources
source /opt/docker/scripts/.color_codes.conf
source /opt/docker/scripts/.vars_docker.env
# source /opt/docker/compose/stackslist-compose.conf
# script variable definitions
unset bounce_list IFS
# function definitions
fnc_help_compose_bounce(){
echo -e "${blu:?}[-> This script bounces (removes then re-deploys) a single or pre-defined list of Docker Swarm stack <-]${def:?}"
echo -e " -"
echo -e " - SYNTAX: # dsb ${cyn:?}stack_name${def:?}"
echo -e " - SYNTAX: # dsb ${cyn:?}-option${def:?}"
echo -e " - VALID OPTIONS:"
echo -e " - ${cyn:?}-a | --all ${def:?}│ Bounces all containers with a corresponding folder inside the '${ylw:?}${docker_compose}/${def:?}' path."
echo -e " - ${cyn:?}-p | --preset ${def:?}│ Bounces the 'preset' array of containers defined in '${ylw:?}${docker_vars}/${cyn:?}compose_stacks.env${def:?}'"
echo -e " - ${cyn:?}-d | --default ${def:?}│ Bounces the 'default' array of containers defined in '${ylw:?}${docker_vars}/${cyn:?}compose_stacks.env${def:?}'"
echo -e " - ${cyn:?}-h │ --help ${def:?}│ Displays this help message."
echo
exit 1 # Exit script after printing help
}
case "$1" in ("-h"|*"help"*) fnc_help_compose_bounce ;; esac
fnc_intro_compose_bounce(){ echo -e "${blu:?}[-> STOPS THEN RESTARTS LISTED CONTAINERS <-]${def:?}"; echo -e "${cyn:?} -> ${bounce_list[*]} ${def:?}"; echo; }
fnc_outro_compose_bounce(){ echo -e "[-- ${grn:?}BOUNCE (REMOVE & REDEPLOY) STACK SCRIPT COMPLETE${def:?} --]"; echo; }
fnc_nothing_to_do(){ echo -e "${ylw:?} -> no containers exist to bounce${def:?}"; }
fnc_invalid_syntax(){ echo -e "${ylw:?} >> INVALID OPTION SYNTAX, USE THE -${cyn:?}help${ylw:?} OPTION TO DISPLAY PROPER SYNTAX <<${def:?}"; exit 1; }
fnc_list_all(){ IFS=$'\n'; bounce_list=( "$(docker container list --format "{{.Names}}")" ); }
fnc_list_default(){ IFS=$'\n'; bounce_list=( "${stacks_default[@]}" ); }
fnc_list_preset(){ IFS=$'\n'; bounce_list=( "${stacks_preset[@]}" ); }
fnc_docker_compose_stop(){ bash "${docker_scripts}/docker_compose_stop.sh" "${bounce_list[@]}"; }
fnc_docker_compose_start(){ bash "${docker_scripts}/docker_compose_start.sh" "${bounce_list[@]}"; }
# determine script output according to option entered
case "${1}" in
(-*)
case "${1}" in
("-a"|"--all") fnc_list_all ;;
("-d"|"--default") fnc_list_default ;;
("-p"|"--preset") fnc_list_preset ;;
(*) fnc_invalid_syntax ;;
esac
;;
(*)
# container_list=("$(docker container list --format {{.Names}})")
# for name in ${!container_list}; do
# # case "${bounce_list[@]}" in
# # (*${name}*)
# # echo "present"
# # ;;
# # (*)
# # echo "not present"
# # ;;
# # esac
# if [[ " ${bounce_list[*]} " == *"${name}"* ]]; then
# break
# fi
# done
IFS=' '; bounce_list=("$@")
;;
esac
# # display script intro
# fnc_intro_compose_bounce
# remove all stacks in list defined above
fnc_docker_compose_stop "${bounce_list[@]}"
# (re)deploy all stacks in list defined above
fnc_docker_compose_start "${bounce_list[@]}"
# # display script outro
# fnc_outro_compose_bounce