docker-webman-jsonrpc/start
2023-10-20 11:53:56 +08:00

62 lines
1.8 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 读取docker.conf文件
source docker.conf
# 设置系统环境变量
export WORKERMAN_CONTAINER_NAME=$container_name
export WORKERMAN_IMAGE_VERSION=$image_version
# 检查docker-compose.yml文件是否存在
if [ ! -f "docker-compose.yml" ]; then
echo "Error: docker-compose.yml file not found"
exit 1
fi
# 定义帮助函数
show_help() {
echo "Usage: ./start [COMMAND]"
echo ""
echo "Commands:"
echo " run once"
echo " start run once"
echo " -d run in daemon mode"
echo " status service status(daemon mode only)"
echo " reload reload files(daemon mode only)"
echo " restart restart service(daemon mode only)"
echo " stop stop service and container"
echo " help show this help message"
}
# 定义安装依赖的函数
install_dependencies() {
# 执行一次composer install
docker compose run --rm $WORKERMAN_CONTAINER_NAME composer install
}
# 根据参数执行不同的命令
if [[ $# -eq 0 || $1 == "start" ]]; then
install_dependencies
docker compose run --rm $WORKERMAN_CONTAINER_NAME php start.php start
elif [[ $1 == "-d" ]]; then
install_dependencies
docker compose up -d
elif [[ $1 == "help" ]]; then
show_help
else
# 判断WORKERMAN_CONTAINER_NAME的docker容器是否存在如果不存在直接退出
if ! docker ps -a --format '{{.Names}}' | grep -q "^$WORKERMAN_CONTAINER_NAME$"; then
echo "container not exist."
exit 1
fi
if ! docker ps --format '{{.Names}}' | grep -q "^$WORKERMAN_CONTAINER_NAME$"; then
echo "container is not running."
exit 1
fi
# 执行php start命令
docker exec -it $WORKERMAN_CONTAINER_NAME php start.php "$@"
if [[ $1 == "stop" ]]; then
docker stop $WORKERMAN_CONTAINER_NAME
fi
fi