30 lines
708 B
Bash
30 lines
708 B
Bash
#!/bin/bash
|
|
|
|
run(){
|
|
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
local docker_compose_file="$script_dir/../docker-compose.yml"
|
|
|
|
local running_count=$(docker-compose -f "$docker_compose_file" ps -q --filter "status=running" | wc -l)
|
|
|
|
if [ "$running_count" -gt 0 ]; then
|
|
read -p "容器已启动,是否重启容器?(y/n): " choice
|
|
case "$choice" in
|
|
Y|y)
|
|
echo "正在重启容器..."
|
|
docker-compose -f "$docker_compose_file" down
|
|
docker-compose -f "$docker_compose_file" up -d
|
|
return
|
|
;;
|
|
*)
|
|
echo "已取消操作"
|
|
exit 0
|
|
;;
|
|
esac
|
|
fi
|
|
|
|
docker-compose -f "$docker_compose_file" up -d
|
|
}
|
|
|
|
|
|
run
|