runserver.bat 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. @echo off
  2. rem This is and auto-restart script for the rAthena Ragnarok Online Server Emulator.
  3. rem It will also keep the map server OPEN after it crashes to that errors may be
  4. rem more easily identified
  5. rem Writen by Jbain
  6. rem modified by lighta
  7. set SOURCE_DIR=%~dp0
  8. cd %SOURCE_DIR%
  9. if ["%~1"]==[""] (
  10. REM this is for backward compatibility
  11. set "target=watch"
  12. ) else set target=%~1
  13. echo "target=%target%"
  14. REM to avoid any localization issue
  15. set "login_running=false"
  16. set "char_running=false"
  17. set "web_running=false"
  18. set "map_running=false"
  19. if "%target%" == "status" (
  20. call :getStatus
  21. ) else if "%target%" == "watch" (
  22. call :Watch
  23. ) else if "%target%" == "stop" (
  24. call :Stop
  25. ) else if "%target%" == "stop" (
  26. call :Stop
  27. ) else if "%target%" == "start" (
  28. call :Start
  29. )
  30. goto :EOF
  31. :Stop
  32. echo "Stoping all serv"
  33. call :stopLogin
  34. call :stopChar
  35. call :stopWeb
  36. call :stopMap
  37. goto :EOF
  38. :Watch
  39. REM this is to align terminology with athena-start, (start with restart mode)
  40. echo "Starting all serv"
  41. set "restart_mode=on"
  42. call :startLogin
  43. call :startChar
  44. call :startWeb
  45. call :startMap
  46. goto :EOF
  47. :Start
  48. echo "Starting all serv"
  49. set "restart_mode=off"
  50. call :startLogin
  51. call :startChar
  52. call :startWeb
  53. call :startMap
  54. goto :EOF
  55. :getStatus
  56. echo "Getting status of all serv"
  57. call :getLoginStatus
  58. call :getCharStatus
  59. call :getWebStatus
  60. call :getMapStatus
  61. if "%login_running%" == "false" ( echo "login_serv is not running"
  62. ) else echo "login_serv is running pid=%LoginServPID%"
  63. if "%char_running%" == "false" ( echo "char_serv is not running"
  64. ) else echo "char_serv is running pid=%CharServPID%"
  65. if "%web_running%" == "false" ( echo "web_serv is not running"
  66. ) else echo "web_serv is running pid=%WebServPID%"
  67. if "%map_running%" == "false" ( echo "map_serv is not running"
  68. ) else echo "map_serv is running pid=%MapServPID%"
  69. goto :EOF
  70. REM ====
  71. REM sub targets (a target per serv)
  72. REM ====
  73. REM stop sub targets
  74. :stopLogin
  75. call :getLoginStatus
  76. if "%login_running%" == "true" Taskkill /PID %LoginServPID% /F
  77. goto :EOF
  78. :stopChar
  79. call :getCharStatus
  80. if "%char_running%" == "true" Taskkill /PID %CharServPID% /F
  81. goto :EOF
  82. :stopWeb
  83. call :getWebStatus
  84. if "%web_running%" == "true" Taskkill /PID %WebServPID% /F
  85. goto :EOF
  86. :stopMap
  87. call :getMapStatus
  88. if "%map_running%" == "true" Taskkill /PID %MapServPID% /F
  89. goto :EOF
  90. REM start sub targets
  91. :startLogin
  92. call :getLoginStatus
  93. if "%login_running%" == "false" ( start cmd /k logserv.bat %restart_mode%
  94. ) else echo "Login serv is already running pid=%LoginServPID%"
  95. goto :EOF
  96. :startChar
  97. call :getCharStatus
  98. if "%char_running%" == "false" ( start cmd /k charserv.bat %restart_mode%
  99. ) else echo "Char serv is already running, pid=%CharServPID%"
  100. goto :EOF
  101. :startWeb
  102. call :getWebStatus
  103. if "%web_running%" == "false" ( start cmd /k webserv.bat %restart_mode%
  104. ) else echo "Web serv is already running, pid=%WebServPID%"
  105. goto :EOF
  106. :startMap
  107. call :getMapStatus
  108. if "%map_running%" == "false" ( start cmd /k mapserv.bat %restart_mode%
  109. ) else echo "Map serv is already running, pid=%MapServPID%"
  110. goto :EOF
  111. REM status sub targets
  112. :getLoginStatus
  113. for /F "TOKENS=1,2,*" %%a in ('tasklist /FI "IMAGENAME eq login-server.exe"') do set LoginServPID=%%b
  114. echo(%LoginServPID%|findstr "^[-][1-9][0-9]*$ ^[1-9][0-9]*$ ^0$">nul&& set "login_running=true" || set "login_running=false"
  115. goto :EOF
  116. :getCharStatus
  117. for /F "TOKENS=1,2,*" %%a in ('tasklist /FI "IMAGENAME eq char-server.exe"') do set CharServPID=%%b
  118. echo(%CharServPID%|findstr "^[-][1-9][0-9]*$ ^[1-9][0-9]*$ ^0$">nul&& set "char_running=true" || set "char_running=false"
  119. goto :EOF
  120. :getWebStatus
  121. for /F "TOKENS=1,2,*" %%a in ('tasklist /FI "IMAGENAME eq web-server.exe"') do set WebServPID=%%b
  122. echo(%WebServPID%|findstr "^[-][1-9][0-9]*$ ^[1-9][0-9]*$ ^0$">nul&& set "Web_running=true" || set "web_running=false"
  123. goto :EOF
  124. :getMapStatus
  125. for /F "TOKENS=1,2,*" %%a in ('tasklist /FI "IMAGENAME eq map-server.exe"') do set MapServPID=%%b
  126. echo(%MapServPID%|findstr "^[-][1-9][0-9]*$ ^[1-9][0-9]*$ ^0$">nul&& set "map_running=true" || set "map_running=false"
  127. goto :EOF