-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstop.sh
More file actions
executable file
·58 lines (46 loc) · 1.37 KB
/
stop.sh
File metadata and controls
executable file
·58 lines (46 loc) · 1.37 KB
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
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(CDPATH= cd -- "$(dirname "$0")" && pwd)"
SERVICE_NAME="php-app"
SCRIPT_PATH="/var/www/html/scripts/runtime-control.php"
cd "$ROOT_DIR"
stop_host_managed_app_containers() {
local -a ids=()
local id
while IFS= read -r id; do
[ -n "$id" ] && ids+=("$id")
done < <(docker ps -q --filter label=doki.app)
while IFS= read -r id; do
[ -n "$id" ] && ids+=("$id")
done < <(docker ps -q --filter label=doki.job.id)
if [ ${#ids[@]} -eq 0 ]; then
return 0
fi
mapfile -t ids < <(printf '%s\n' "${ids[@]}" | awk 'NF && !seen[$0]++')
if [ ${#ids[@]} -eq 0 ]; then
return 0
fi
echo "Stopping remaining Doki app containers from the host..."
docker stop "${ids[@]}"
}
app_exit=0
if [ -n "$(docker compose ps -q "$SERVICE_NAME" 2>/dev/null)" ]; then
echo "Stopping Doki app runtimes inside '$SERVICE_NAME'..."
set +e
docker compose exec -T "$SERVICE_NAME" php "$SCRIPT_PATH" stop --skip-core "$@"
app_exit=$?
set -e
else
echo "Skipping in-container app shutdown because '$SERVICE_NAME' is not running."
fi
host_app_exit=0
set +e
stop_host_managed_app_containers
host_app_exit=$?
set -e
if [ "$app_exit" -eq 0 ] && [ "$host_app_exit" -ne 0 ]; then
app_exit=$host_app_exit
fi
echo "Stopping Doki core containers..."
docker compose stop
exit "$app_exit"