diff --git a/History.txt b/History.txt index 36cddf7..391a324 100644 --- a/History.txt +++ b/History.txt @@ -1,4 +1,7 @@ 1.00: 支持RUN、URL、SLEEP三种配置文件项。 1.01: - 添加ECHO、RUNWAIT配置文件项。 \ No newline at end of file + 添加ECHO、RUNWAIT配置文件项。 +1.02: + 添加PORT、ZOOKEEPER配置文件项。 + \ No newline at end of file diff --git a/SequentialStartup.CMD b/SequentialStartup.CMD index 3552324..444fdec 100644 --- a/SequentialStartup.CMD +++ b/SequentialStartup.CMD @@ -1,103 +1,102 @@ -::˳ű -::@author FB -::@version 1.01 - -@ECHO OFF -SETLOCAL ENABLEDELAYEDEXPANSION -CD /D "%~dp0" -SET "PATH=%CD%\bin;%CD%\script;%PATH%" - -::в -:: 1: ļ -IF EXIST "%~1" ( - SET "CFGFILE=%~1" -) ELSE ( - SET "CFGFILE=%~dpn0.cfg" -) - -::ʼִ -CALL :ECHO "========== ʼִ " " ==========" -FOR /F "eol=# tokens=1,* delims== usebackq" %%I IN ("%CFGFILE%") DO ( - CALL :TRIM "VARNAME" "%%I" - CALL :TRIM "VARDATA" "%%J" - IF /I "!VARNAME!" == "RUN" ( - CALL :ECHO "##" ": !VARDATA!" - CALL :GET_PATH "RUN_PATH" "!VARDATA!" - START "!VARDATA!" /D "!RUN_PATH!" !VARDATA! - SET "RUN_PATH=" - ) - IF /I "!VARNAME!" == "RUNWAIT" ( - CALL :ECHO "##" "еȴ: !VARDATA!" - CALL :GET_PATH "RUN_PATH" "!VARDATA!" - START /WAIT "!VARDATA!" /D "!RUN_PATH!" !VARDATA! - SET "RUN_PATH=" - ) - IF /I "!VARNAME!" == "URL" ( - CALL :ECHO "##" "ַ: !VARDATA!" - CALL :CHECK_URL "!VARDATA!" - ) - IF /I "!VARNAME!" == "SLEEP" ( - CALL :ECHO "##" "ȴʱ: !VARDATA!" - CALL :SLEEP !VARDATA! - ) - IF /I "!VARNAME!" == "ECHO" ( - ECHO.!VARDATA! - ) -) - -::ִн -CALL :ECHO "========== ִн " " ==========" -GOTO :EOF - - -::ַ -:: 1: ַ -:CHECK_URL -FOR /F "tokens=*" %%I IN ('curl -I -m 10 -o NUL -s -w %%{http_code} "%~1"') DO ( - IF NOT "%%I" == "200" IF NOT "%%I" == "302" ( - CALL :SLEEP 3 - GOTO :CHECK_URL - ) -) -GOTO :EOF - -::ӳ -:: 1: ʱ() -:SLEEP -IF "%~1" == "" GOTO :EOF -CHOICE /T "%~1" /D "Y" 1>NUL 2>NUL -SET "SLEEPPARAM=" -GOTO :EOF - -::ʱ -:: 1: ǰ׺ -:: 2: ׺ -:ECHO -@ECHO %~1 %DATE% %TIME% %~2 -GOTO :EOF - -::ȥո -:: 1: -:: 2: Ŀַ -:TRIM -SET "TRIMSTR=%~2" -:TRIMLEFT -IF "%TRIMSTR:~0,1%" == " " ( - SET "TRIMSTR=%TRIMSTR:~1%" - GOTO :TRIMLEFT -) -:TRIMRIGHT -IF "%TRIMSTR:~-1%" == " " ( - SET "TRIMSTR=%TRIMSTR:~0,-1%" - GOTO :TRIMLEFT -) -SET "%~1=%TRIMSTR%" -SET "TRIMSTR=" -GOTO :EOF - -::ȡļ· -:: 1: 浽 -:: 2: ļ· -:GET_PATH -SET "%~1=%~dp2" -GOTO :EOF +::˳ű +::@author FB +::@version 1.02 + +@ECHO OFF +SETLOCAL ENABLEDELAYEDEXPANSION +CD /D "%~dp0" +SET "PATH=%CD%\bin;%CD%\script;%PATH%" + +::в +:: 1: ļ +IF EXIST "%~1" ( + SET "CFGFILE=%~1" +) ELSE ( + SET "CFGFILE=%~dpn0.cfg" +) + +::ʼִ +ECHO ========== ʼִ !DATE! !TIME! ========== +FOR /F "eol=# tokens=1,* usebackq delims==" %%I IN ("%CFGFILE%") DO ( + CALL Common.CMD TRIM %%I + SET "VARNAME=!$!" + CALL Common.CMD TRIM %%J + SET "VARDATA=!$!" + IF /I "!VARNAME!" == "RUN" ( + ECHO ## !DATE! !TIME! : !VARDATA! + CALL :RUN !VARDATA! + ) + IF /I "!VARNAME!" == "RUNWAIT" ( + ECHO ## !DATE! !TIME! вȴ: !VARDATA! + CALL :RUNWAIT !VARDATA! + ) + IF /I "!VARNAME!" == "URL" ( + ECHO ## !DATE! !TIME! ȴַ: !VARDATA! + CALL :URL "!VARDATA!" + ) + IF /I "!VARNAME!" == "PORT" ( + ECHO ## !DATE! !TIME! ȴ˿: !VARDATA! + FOR /F "tokens=1,* delims=:" %%A IN ("!VARDATA!") DO CALL :PORT "%%A" "%%B" + ) + IF /I "!VARNAME!" == "ZOOKEEPER" ( + ECHO ## !DATE! !TIME! ȴZookeeper: !VARDATA! + FOR /F "tokens=1,* delims=:" %%A IN ("!VARDATA!") DO CALL :ZOOKEEPER "%%A" "%%B" + ) + IF /I "!VARNAME!" == "SLEEP" ( + ECHO ## !DATE! !TIME! ȴ: !VARDATA! + CALL Common.CMD SLEEP !VARDATA! + ) + IF /I "!VARNAME!" == "ECHO" ( + ECHO.!VARDATA! + ) +) + +::ִн +ECHO ========== ִн !DATE! !TIME! ========== +GOTO :EOF + +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + +::ִ +:: 1: +:RUNWAIT +CALL Common.CMD GET_PATH "%~1" +START "!VARDATA!" /WAIT /D "!$!" %* +GOTO :EOF + +::ִȴ +:: 1: +:RUN +CALL Common.CMD GET_PATH "%~1" +START "!VARDATA!" /D "!$!" %* +GOTO :EOF + +::ȴַ +:: 1: ַ +:URL +FOR /F "tokens=*" %%I IN ('curl -I -m 10 -o NUL -s -w %%{http_code} "%~1"') DO ( + IF NOT "%%I" == "200" IF NOT "%%I" == "302" ( + CALL Common.CMD SLEEP 3 + GOTO :URL + ) +) +GOTO :EOF + +::ȴ˿ +:: 1: ַ +:: 2: ˿ +:PORT +nc.exe -z "%~1" "%~2" 1>NUL 2>&1 +IF "%ERRORLEVEL%" == "0" GOTO :EOF +CHOICE /T 3 /D Y 1>NUL 2>&1 +GOTO :PORT + +::ȴZookeeper +:: 1: ַ +:: 2: ˿ +:ZOOKEEPER +ECHO stat | nc.exe "%~1" "%~2" | find /I "Zookeeper" 1>NUL 2>&1 +IF "%ERRORLEVEL%" == "0" GOTO :EOF +CHOICE /T 3 /D Y 1>NUL 2>&1 +GOTO :ZOOKEEPER + diff --git a/SequentialStartup.cfg b/SequentialStartup.cfg index b0934b1..0e1c906 100644 --- a/SequentialStartup.cfg +++ b/SequentialStartup.cfg @@ -2,15 +2,19 @@ ## 注意:注释符前不能有空格 # 运行命令 -## RUN=xxx.cmd +## Run=xxx.cmd # 运行等待 -## RUNWAIT=xxx.cmd +## RunWait=xxx.cmd # 检查并等待URL可以访问 -## URL=https://www.baidu.com +## Url=https://www.baidu.com +# 检查并等待端口可以访问 +## Port=localhost:8443 +# 检查并等待Zookeeper可以访问 +## Zookeeper=10.0.253.5:2181 # 等待时间(秒) -## SLEEP=12 +## Sleep=12 # 显示信息 -## ECHO=正在载入... +## Echo=正在载入... # # 脚本顺序解析配置文件 # 当遇到以上某一个元素时,执行对应操作 diff --git a/script/Common.CMD b/script/Common.CMD new file mode 100644 index 0000000..d2b4709 --- /dev/null +++ b/script/Common.CMD @@ -0,0 +1,68 @@ +::ͨӳ +::@author FB +::@version 0.1 + +@ECHO OFF +CALL :%* +GOTO :EOF + +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + +::ȥβո +:: *: Ŀַ +:: $: ַ +:TRIM +SET "$=%*" +GOTO :EOF + +::ȡ· +:: 1: Ŀ· +:: $: · +:FULL_PATH +SET "$=%~f1" +GOTO :EOF + +::ȡļ· +:: 1: ļ· +:: $: · +:GET_PATH +SET "$=%~dp1" +GOTO :EOF + + +::ȡַ +:: 1: ַ +:: $: +:GET_SIZE +SET "$STR=%~1#" +SET "$=0" +FOR %%I IN (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) DO ( + IF NOT "!$STR:~%%I,1!" == "" ( + SET /A "$+=%%I" + SET "$STR=!$STR:~%%I!" + ) +) +SET "$STR=" +GOTO :EOF + +::жַǷַָβ +:: 1: Ŀַ +:: 2: ַָ +:: $: TRUE/FALSE +:END_WITH +SET "$STR=%~1" +CALL :GET_SIZE "%~2" +IF /I "!$STR:~-%$%!" == "%~2" ( + SET "$=TRUE" +) ELSE ( + SET "$=FALSE" +) +SET "$STR=" +GOTO :EOF + +::ӳ +:: 1: ʱ() +:SLEEP +SET /A "$=%~1 + 0" +CHOICE /T "%$%" /D "Y" 1>NUL 2>NUL +GOTO :EOF diff --git a/script/WaitPort.cmd b/script/WaitPort.cmd deleted file mode 100644 index 6cdd141..0000000 --- a/script/WaitPort.cmd +++ /dev/null @@ -1,7 +0,0 @@ -@ECHO OFF - -:LOOP -nc.exe 127.0.0.1 2181 1>NUL 2>&1 -IF "%ERRORLEVEL%" == "0" GOTO :EOF -CHOICE /T 3 /D Y 1>NUL 2>&1 -GOTO :LOOP diff --git a/script/WaitZookeeper.cmd b/script/WaitZookeeper.cmd deleted file mode 100644 index f3dacb7..0000000 --- a/script/WaitZookeeper.cmd +++ /dev/null @@ -1,7 +0,0 @@ -@ECHO OFF - -:LOOP -ECHO stat | nc.exe 127.0.0.1 2181 | find "Zookeeper" 1>NUL 2>&1 -IF "%ERRORLEVEL%" == "0" GOTO :EOF -CHOICE /T 3 /D Y 1>NUL 2>&1 -GOTO :LOOP