snail-job.bat 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. @echo off
  2. REM snail-job.bat start|stop|restart|status
  3. set AppName=snail-job-server-exec.jar
  4. REM JVM options
  5. set JVM_OPTS=-Dname=%AppName% -Duser.timezone=Asia/Shanghai -XX:+HeapDumpOnOutOfMemoryError -XX:+UseZGC
  6. set APP_HOME=%cd%
  7. REM Check if an action is passed, default to "start" if empty
  8. if "%1"=="" (
  9. echo No action provided, default to: start
  10. set ACTION=start
  11. ) else (
  12. set ACTION=%1
  13. )
  14. if "%AppName%"=="" (
  15. echo No application name provided
  16. exit /b 1
  17. )
  18. REM Check the action before executing
  19. if /i "%ACTION%"=="start" (
  20. call :Start
  21. ) else if /i "%ACTION%"=="stop" (
  22. call :Stop
  23. ) else if /i "%ACTION%"=="restart" (
  24. call :Restart
  25. ) else if /i "%ACTION%"=="status" (
  26. call :Status
  27. ) else (
  28. echo Invalid action. Valid actions are: {start|stop|restart|status}
  29. exit /b 1
  30. )
  31. goto :eof
  32. :Start
  33. REM Check if the program is already running using jps
  34. for /f "tokens=1" %%i in ('jps -l ^| findstr %AppName%') do set PID=%%i
  35. if defined PID (
  36. echo %AppName% is already running with PID %PID%...
  37. ) else (
  38. start "" /b javaw %JVM_OPTS% -jar %AppName%
  39. echo Start %AppName% success...
  40. )
  41. goto :eof
  42. :Stop
  43. set "PID="
  44. REM Find the process using jps and stop it
  45. for /f "tokens=1" %%i in ('jps -l ^| findstr %AppName%') do (
  46. set "PID=%%i"
  47. )
  48. REM Removing any extra spaces from PID (just in case)
  49. for /f "tokens=* delims= " %%i in ("%PID%") do set "PID=%%i"
  50. REM Verify if PID is defined
  51. if defined PID (
  52. REM Using TASKKILL to kill the process
  53. taskkill /PID %PID% /T /F
  54. REM Check if taskkill was successful
  55. if %errorlevel% NEQ 0 (
  56. echo Failed to stop %AppName% with PID %PID%. Error level: %errorlevel%
  57. ) else (
  58. echo %AppName% with PID %PID% has been stopped.
  59. )
  60. ) else (
  61. echo %AppName% is already stopped or not running.
  62. )
  63. goto :eof
  64. :Restart
  65. call :Stop
  66. timeout /t 2 >nul
  67. call :Start
  68. goto :eof
  69. :Status
  70. REM Check if the program is running using jps
  71. for /f "tokens=1" %%i in ('jps -l ^| findstr %AppName%') do set PID=%%i
  72. if defined PID (
  73. echo %AppName% is running with PID %PID%...
  74. ) else (
  75. echo %AppName% is not running...
  76. )
  77. goto :eof