runserver.bat 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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%" == "start" (
  26. call :Start
  27. )
  28. goto :EOF
  29. :Stop
  30. echo "Stoping all serv"
  31. call :stopLogin
  32. call :stopChar
  33. call :stopWeb
  34. call :stopMap
  35. goto :EOF
  36. :Watch
  37. REM this is to align terminology with athena-start, (start with restart mode)
  38. echo "Starting all serv"
  39. set "restart_mode=on"
  40. call :startLogin
  41. call :startChar
  42. call :startWeb
  43. call :startMap
  44. goto :EOF
  45. :Start
  46. echo "Starting all serv"
  47. set "restart_mode=off"
  48. call :startLogin
  49. call :startChar
  50. call :startWeb
  51. call :startMap
  52. goto :EOF
  53. :getStatus
  54. echo "Getting status of all serv"
  55. call :getLoginStatus
  56. call :getCharStatus
  57. call :getWebStatus
  58. call :getMapStatus
  59. if "%login_running%" == "false" ( echo "login_serv is not running"
  60. ) else echo "login_serv is running pid=%LoginServPID%"
  61. if "%char_running%" == "false" ( echo "char_serv is not running"
  62. ) else echo "char_serv is running pid=%CharServPID%"
  63. if "%web_running%" == "false" ( echo "web_serv is not running"
  64. ) else echo "web_serv is running pid=%WebServPID%"
  65. if "%map_running%" == "false" ( echo "map_serv is not running"
  66. ) else echo "map_serv is running pid=%MapServPID%"
  67. goto :EOF
  68. REM ====
  69. REM sub targets (a target per serv)
  70. REM ====
  71. REM stop sub targets
  72. :stopLogin
  73. call :getLoginStatus
  74. if "%login_running%" == "true" Taskkill /PID %LoginServPID% /F
  75. goto :EOF
  76. :stopChar
  77. call :getCharStatus
  78. if "%char_running%" == "true" Taskkill /PID %CharServPID% /F
  79. goto :EOF
  80. :stopWeb
  81. call :getWebStatus
  82. if "%web_running%" == "true" Taskkill /PID %WebServPID% /F
  83. goto :EOF
  84. :stopMap
  85. call :getMapStatus
  86. if "%map_running%" == "true" Taskkill /PID %MapServPID% /F
  87. goto :EOF
  88. REM start sub targets
  89. :startLogin
  90. call :getLoginStatus
  91. if "%login_running%" == "false" ( start cmd /k logserv.bat %restart_mode%
  92. ) else echo "Login serv is already running pid=%LoginServPID%"
  93. goto :EOF
  94. :startChar
  95. call :getCharStatus
  96. if "%char_running%" == "false" ( start cmd /k charserv.bat %restart_mode%
  97. ) else echo "Char serv is already running, pid=%CharServPID%"
  98. goto :EOF
  99. :startWeb
  100. call :getWebStatus
  101. if "%web_running%" == "false" ( start cmd /k webserv.bat %restart_mode%
  102. ) else echo "Web serv is already running, pid=%WebServPID%"
  103. goto :EOF
  104. :startMap
  105. call :getMapStatus
  106. if "%map_running%" == "false" ( start cmd /k mapserv.bat %restart_mode%
  107. ) else echo "Map serv is already running, pid=%MapServPID%"
  108. goto :EOF
  109. REM status sub targets
  110. :getLoginStatus
  111. for /F "TOKENS=1,2,*" %%a in ('tasklist /FI "IMAGENAME eq login-server.exe"') do set LoginServPID=%%b
  112. echo(%LoginServPID%|findstr "^[-][1-9][0-9]*$ ^[1-9][0-9]*$ ^0$">nul&& set "login_running=true" || set "login_running=false"
  113. goto :EOF
  114. :getCharStatus
  115. for /F "TOKENS=1,2,*" %%a in ('tasklist /FI "IMAGENAME eq char-server.exe"') do set CharServPID=%%b
  116. echo(%CharServPID%|findstr "^[-][1-9][0-9]*$ ^[1-9][0-9]*$ ^0$">nul&& set "char_running=true" || set "char_running=false"
  117. goto :EOF
  118. :getWebStatus
  119. for /F "TOKENS=1,2,*" %%a in ('tasklist /FI "IMAGENAME eq web-server.exe"') do set WebServPID=%%b
  120. echo(%WebServPID%|findstr "^[-][1-9][0-9]*$ ^[1-9][0-9]*$ ^0$">nul&& set "Web_running=true" || set "web_running=false"
  121. goto :EOF
  122. :getMapStatus
  123. for /F "TOKENS=1,2,*" %%a in ('tasklist /FI "IMAGENAME eq map-server.exe"') do set MapServPID=%%b
  124. echo(%MapServPID%|findstr "^[-][1-9][0-9]*$ ^[1-9][0-9]*$ ^0$">nul&& set "map_running=true" || set "map_running=false"
  125. goto :EOF