tests_ts3server.sh 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. #!/bin/bash
  2. # TravisCI Tests
  3. # Server Management Script
  4. # Author: Daniel Gibbs
  5. # Website: http://gameservermanagers.com
  6. version="011115"
  7. #### Variables ####
  8. # Notification Email
  9. # (on|off)
  10. emailnotification="on"
  11. email="me@danielgibbs.co.uk"
  12. # Start Variables
  13. updateonstart="off"
  14. # Server Details
  15. gamename="Teamspeak 3"
  16. servername="Teamspeak 3 Server"
  17. servicename="ts3-server"
  18. # Directories
  19. rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  20. selfname="$(basename $0)"
  21. lockselfname=".${servicename}.lock"
  22. filesdir="${rootdir}/serverfiles"
  23. systemdir="${filesdir}"
  24. executabledir="${filesdir}"
  25. executable="./ts3server_startscript.sh"
  26. servercfg="${servicename}.ini"
  27. servercfgdir="${filesdir}"
  28. servercfgfullpath="${servercfgdir}/${servercfg}"
  29. backupdir="${rootdir}/backups"
  30. # Logging
  31. logdays="7"
  32. gamelogdir="${filesdir}/logs"
  33. scriptlogdir="${rootdir}/log/script"
  34. scriptlog="${scriptlogdir}/${servicename}-script.log"
  35. emaillog="${scriptlogdir}/${servicename}-email.log"
  36. scriptlogdate="${scriptlogdir}/${servicename}-script-$(date '+%d-%m-%Y-%H-%M-%S').log"
  37. ##### Script #####
  38. # Do not edit
  39. fn_runfunction(){
  40. # Functions are downloaded and run with this function
  41. if [ ! -f "${rootdir}/functions/${functionfile}" ]; then
  42. cd "${rootdir}"
  43. if [ ! -d "functions" ]; then
  44. mkdir functions
  45. fi
  46. cd functions
  47. echo -e " loading ${functionfile}...\c"
  48. wget -N /dev/null https://raw.githubusercontent.com/dgibbs64/linuxgsm/master/functions/${functionfile} 2>&1 | grep -F HTTP | cut -c45-
  49. chmod +x "${functionfile}"
  50. cd "${rootdir}"
  51. fi
  52. source "${rootdir}/functions/${functionfile}"
  53. }
  54. fn_functions(){
  55. # Functions are defined in fn_functions.
  56. functionfile="${FUNCNAME}"
  57. fn_runfunction
  58. }
  59. fn_functions
  60. fn_currentstatus(){
  61. if [ "${gamename}" == "Teamspeak 3" ]; then
  62. fn_check_ts3status
  63. ts3status=$(${executable} status servercfgfullpathfile=${servercfgfullpath})
  64. else
  65. pid=$(tmux list-sessions 2>&1 | awk '{print $1}' | grep -Ec "^${servicename}:")
  66. fi
  67. if [ "${pid}" != "0" ]||[ "${ts3status}" == "Server is running" ]; then
  68. currentstatus="ONLINE"
  69. else
  70. currentstatus="OFFLINE"
  71. fi
  72. }
  73. fn_setstatus(){
  74. fn_currentstatus
  75. echo""
  76. echo "Required status: ${requiredstatus}"
  77. counter=0
  78. echo "Current status: ${currentstatus}"
  79. while [ "${requiredstatus}" != "${currentstatus}" ]; do
  80. counter=$((counter+1))
  81. fn_currentstatus
  82. echo -ne "New status: ${currentstatus}\\r"
  83. if [ "${requiredstatus}" == "ONLINE" ]; then
  84. (fn_start > /dev/null 2>&1)
  85. else
  86. (fn_stop > /dev/null 2>&1)
  87. fi
  88. if [ "${counter}" -gt "5" ]; then
  89. currentstatus="FAIL"
  90. echo "Current status: ${currentstatus}"
  91. echo ""
  92. echo "Unable to start or stop server."
  93. exit 1
  94. fi
  95. done
  96. echo -ne "New status: ${currentstatus}\\r"
  97. echo -e "\n"
  98. echo "Test starting:"
  99. echo ""
  100. sleep 0.5
  101. }
  102. echo "================================="
  103. echo "TravisCI Tests"
  104. echo "Linux Game Server Manager"
  105. echo "by Daniel Gibbs"
  106. echo "http://gameservermanagers.com"
  107. echo "================================="
  108. echo ""
  109. sleep 1
  110. echo "================================="
  111. echo "Server Tests"
  112. echo "Using: ${gamename}"
  113. echo "================================="
  114. echo ""
  115. sleep 1
  116. echo "1.0 - start - no files"
  117. echo "================================="
  118. echo "Description:"
  119. echo "test script reaction to missing server files."
  120. echo ""
  121. (fn_start)
  122. echo ""
  123. echo "Test complete!"
  124. sleep 1
  125. echo ""
  126. echo "1.1 - getopt"
  127. echo "================================="
  128. echo "Description:"
  129. echo "displaying options messages."
  130. echo ""
  131. (fn_getopt)
  132. echo ""
  133. echo "Test complete!"
  134. sleep 1
  135. echo ""
  136. echo "2.0 - install"
  137. echo "================================="
  138. echo "Description:"
  139. echo "install ${gamename} server."
  140. fn_autoinstall
  141. echo ""
  142. echo "Test complete!"
  143. sleep 1
  144. echo ""
  145. echo "3.1 - start"
  146. echo "================================="
  147. echo "Description:"
  148. echo "start ${gamename} server."
  149. requiredstatus="OFFLINE"
  150. fn_setstatus
  151. fn_start
  152. echo ""
  153. echo "Test complete!"
  154. sleep 1
  155. echo ""
  156. echo "3.2 - start - online"
  157. echo "================================="
  158. echo "Description:"
  159. echo "start ${gamename} server while already running."
  160. requiredstatus="ONLINE"
  161. fn_setstatus
  162. (fn_start)
  163. echo ""
  164. echo "Test complete!"
  165. sleep 1
  166. echo ""
  167. echo "3.3 - start - updateonstart"
  168. echo "================================="
  169. echo "Description:"
  170. echo "will update server on start."
  171. requiredstatus="OFFLINE"
  172. fn_setstatus
  173. (
  174. updateonstart="on"
  175. fn_start
  176. )
  177. echo ""
  178. echo "Test complete!"
  179. sleep 1
  180. echo ""
  181. echo "3.4 - stop"
  182. echo "================================="
  183. echo "Description:"
  184. echo "stop ${gamename} server."
  185. requiredstatus="ONLINE"
  186. fn_setstatus
  187. fn_stop
  188. echo ""
  189. echo "Test complete!"
  190. sleep 1
  191. echo ""
  192. echo "3.5 - stop - offline"
  193. echo "================================="
  194. echo "Description:"
  195. echo "stop ${gamename} server while already stopped."
  196. requiredstatus="OFFLINE"
  197. fn_setstatus
  198. (fn_stop)
  199. echo ""
  200. echo "Test complete!"
  201. sleep 1
  202. echo ""
  203. echo "3.6 - restart"
  204. echo "================================="
  205. echo "Description:"
  206. echo "restart ${gamename}."
  207. requiredstatus="ONLINE"
  208. fn_setstatus
  209. fn_restart
  210. echo ""
  211. echo "Test complete!"
  212. sleep 1
  213. echo ""
  214. echo "3.7 - restart - offline"
  215. echo "================================="
  216. echo "Description:"
  217. echo "restart ${gamename} while already stopped."
  218. requiredstatus="OFFLINE"
  219. fn_setstatus
  220. fn_restart
  221. echo ""
  222. echo "Test complete!"
  223. sleep 1
  224. echo ""
  225. echo "4.1 - update"
  226. echo "================================="
  227. echo "Description:"
  228. echo "check for updates."
  229. requiredstatus="OFFLINE"
  230. fn_setstatus
  231. fn_update_check
  232. echo ""
  233. echo "Test complete!"
  234. sleep 1
  235. echo ""
  236. echo "4.1 - update - old version"
  237. echo "================================="
  238. echo "Description:"
  239. echo "change the version number tricking LGSM to update."
  240. requiredstatus="OFFLINE"
  241. sed -i 's/[0-9]\+/0/g' ${gamelogdir}/ts3server*_0.log
  242. fn_setstatus
  243. fn_update_check
  244. echo ""
  245. echo "Test complete!"
  246. sleep 1
  247. echo ""
  248. echo "5.1 - monitor - online"
  249. echo "================================="
  250. echo "Description:"
  251. echo "run monitor server while already running."
  252. requiredstatus="ONLINE"
  253. fn_setstatus
  254. (fn_monitor)
  255. echo ""
  256. echo "Test complete!"
  257. sleep 1
  258. echo ""
  259. echo "5.2 - monitor - offline - no lockfile"
  260. echo "================================="
  261. echo "Description:"
  262. echo "run monitor while server is offline with no lockfile."
  263. requiredstatus="OFFLINE"
  264. fn_setstatus
  265. (fn_monitor)
  266. echo ""
  267. echo "Test complete!"
  268. sleep 1
  269. echo ""
  270. echo "5.3 - monitor - offline - with lockfile"
  271. echo "================================="
  272. echo "Description:"
  273. echo "run monitor while server is offline with no lockfile."
  274. requiredstatus="OFFLINE"
  275. fn_setstatus
  276. fn_printinfonl "creating lockfile."
  277. date > "${rootdir}/${lockselfname}"
  278. (fn_monitor)
  279. echo ""
  280. echo "Test complete!"
  281. sleep 1
  282. echo ""
  283. echo "5.4 - monitor - gsquery.py failure"
  284. echo "================================="
  285. echo "Description:"
  286. echo "gsquery.py will fail to query port."
  287. requiredstatus="ONLINE"
  288. fn_setstatus
  289. sed -i 's/[0-9]\+/0/' "${servercfgfullpath}"
  290. (fn_monitor)
  291. echo ""
  292. fn_printinfonl "Reseting ${servercfg}."
  293. fn_install_config
  294. echo ""
  295. echo "Test complete!"
  296. sleep 1
  297. echo ""
  298. echo "6.0 - details"
  299. echo "================================="
  300. echo "Description:"
  301. echo "display details."
  302. requiredstatus="ONLINE"
  303. fn_setstatus
  304. fn_details
  305. echo ""
  306. echo "Test complete!"
  307. sleep 1
  308. echo ""
  309. echo "================================="
  310. echo "Server Tests - Complete!"
  311. echo "Using: ${gamename}"
  312. echo "================================="
  313. echo ""
  314. sleep 1
  315. fn_printinfo "Tidying up directories."
  316. sleep 1
  317. rm -rfv ${serverfiles}
  318. echo "END"