From 99d42cdf9bf7b645de1792b598c6b9a6eb52d745 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=5F=E8=80=81=E9=A9=AC=5F?= Date: Fri, 13 Sep 2024 01:09:56 +0000 Subject: [PATCH] =?UTF-8?q?!90=20=E6=96=B0=E5=A2=9Ewindow=E7=9A=84?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=20*=20=E6=B7=BB=E5=8A=A0snail-job=E7=9A=84wi?= =?UTF-8?q?ndow=E5=90=AF=E5=8A=A8=E8=84=9A=E6=9C=AC.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/script/snail-job.bat | 93 ++++++++++++++++++++++++++++++++++++++++ doc/script/snail-job.sh | 1 - 2 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 doc/script/snail-job.bat diff --git a/doc/script/snail-job.bat b/doc/script/snail-job.bat new file mode 100644 index 000000000..97c61cc09 --- /dev/null +++ b/doc/script/snail-job.bat @@ -0,0 +1,93 @@ +@echo off +REM snail-job.bat start|stop|restart|status +set AppName=snail-job-server-exec.jar + +REM JVM options +set JVM_OPTS=-Dname=%AppName% -Duser.timezone=Asia/Shanghai -XX:+HeapDumpOnOutOfMemoryError -XX:+UseZGC +set APP_HOME=%cd% + +REM Check if an action is passed, default to "start" if empty +if "%1"=="" ( + echo No action provided, default to: start + set ACTION=start +) else ( + set ACTION=%1 +) + +if "%AppName%"=="" ( + echo No application name provided + exit /b 1 +) + +REM Check the action before executing +if /i "%ACTION%"=="start" ( + call :Start +) else if /i "%ACTION%"=="stop" ( + call :Stop +) else if /i "%ACTION%"=="restart" ( + call :Restart +) else if /i "%ACTION%"=="status" ( + call :Status +) else ( + echo Invalid action. Valid actions are: {start|stop|restart|status} + exit /b 1 +) + +goto :eof + +:Start +REM Check if the program is already running using jps +for /f "tokens=1" %%i in ('jps -l ^| findstr %AppName%') do set PID=%%i + +if defined PID ( + echo %AppName% is already running with PID %PID%... +) else ( + start "" /b javaw %JVM_OPTS% -jar %AppName% + echo Start %AppName% success... +) +goto :eof + +:Stop +set "PID=" + +REM Find the process using jps and stop it +for /f "tokens=1" %%i in ('jps -l ^| findstr %AppName%') do ( + set "PID=%%i" +) + +REM Removing any extra spaces from PID (just in case) +for /f "tokens=* delims= " %%i in ("%PID%") do set "PID=%%i" + +REM Verify if PID is defined +if defined PID ( + REM Using TASKKILL to kill the process + taskkill /PID %PID% /T /F + + REM Check if taskkill was successful + if %errorlevel% NEQ 0 ( + echo Failed to stop %AppName% with PID %PID%. Error level: %errorlevel% + ) else ( + echo %AppName% with PID %PID% has been stopped. + ) +) else ( + echo %AppName% is already stopped or not running. +) +goto :eof + + +:Restart +call :Stop +timeout /t 2 >nul +call :Start +goto :eof + +:Status +REM Check if the program is running using jps +for /f "tokens=1" %%i in ('jps -l ^| findstr %AppName%') do set PID=%%i + +if defined PID ( + echo %AppName% is running with PID %PID%... +) else ( + echo %AppName% is not running... +) +goto :eof diff --git a/doc/script/snail-job.sh b/doc/script/snail-job.sh index 1107f7abc..6eacdcec5 100644 --- a/doc/script/snail-job.sh +++ b/doc/script/snail-job.sh @@ -5,7 +5,6 @@ AppName=snail-job-server-exec.jar # JVM参数 JVM_OPTS="-Dname=$AppName -Duser.timezone=Asia/Shanghai -XX:+HeapDumpOnOutOfMemoryError -XX:+UseZGC" APP_HOME=`pwd` -LOG_PATH=$APP_HOME/logs/$AppName.log # 检查传入的操作名参数,如果为空则默认设置为 "start" if [ "$1" = "" ]; then