From 1b92be2fd10bf98392e7ca92c77428ee1be9979a Mon Sep 17 00:00:00 2001 From: wandoubaba Date: Fri, 20 Oct 2023 11:53:56 +0800 Subject: [PATCH] start, console --- build.sh => console | 7 ++++-- start | 53 +++++++++++++++++++++++++++++++++++++++------ 2 files changed, 51 insertions(+), 9 deletions(-) rename build.sh => console (65%) diff --git a/build.sh b/console similarity index 65% rename from build.sh rename to console index 5fe3c92..0964451 100755 --- a/build.sh +++ b/console @@ -12,5 +12,8 @@ if docker ps -a --format '{{.Names}}' | grep -q "^$WORKERMAN_CONTAINER_NAME$"; t docker rm -f $WORKERMAN_CONTAINER_NAME fi - -docker compose run --rm $WORKERMAN_CONTAINER_NAME php webman build:bin $image_version && cp .env build/ \ No newline at end of file +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 \ No newline at end of file diff --git a/start b/start index a3f9183..621445a 100755 --- a/start +++ b/start @@ -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 -docker compose run --rm $WORKERMAN_CONTAINER_NAME composer install +# 定义帮助函数 +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" +} -# 根据参数执行docker compose up命令 -if [[ $1 == "-d" ]]; then +# 定义安装依赖的函数 +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 - 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