start, console

This commit is contained in:
wandoubaba 2023-10-20 11:53:56 +08:00
parent 05e5fde379
commit 1b92be2fd1
2 changed files with 51 additions and 9 deletions

View File

@ -12,5 +12,8 @@ if docker ps -a --format '{{.Names}}' | grep -q "^$WORKERMAN_CONTAINER_NAME$"; t
docker rm -f $WORKERMAN_CONTAINER_NAME
fi
if [[ $1 == "build" ]]; then
docker compose run --rm $WORKERMAN_CONTAINER_NAME php webman build:bin $image_version && cp .env build/
else
docker compose run --rm $WORKERMAN_CONTAINER_NAME php webman "$@"
fi

51
start
View File

@ -7,16 +7,55 @@ source docker.conf
export WORKERMAN_CONTAINER_NAME=$container_name
export WORKERMAN_IMAGE_VERSION=$image_version
# 判断WORKERMAN_CONTAINER_NAME的docker容器是否存在如果存在删除它
if docker ps -a --format '{{.Names}}' | grep -q "^$WORKERMAN_CONTAINER_NAME$"; then
docker rm -f $WORKERMAN_CONTAINER_NAME
# 检查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
}
# 根据参数执行docker compose up命令
if [[ $1 == "-d" ]]; then
# 根据参数执行不同的命令
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
docker compose up
# 判断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