Advertisement
Nasdero

Arma 3 Linux powerfull startupscript V1.01

Mar 21st, 2015
631
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 10.36 KB | None | 0 0
  1. #!/bin/bash
  2. # armaserver: ArmA 3 Linux Dedicated Server Control Script
  3. #
  4. # original was:
  5. # armaserver: ArmA 2 Linux Dedicated Server Control Script
  6. #  (c) 2010 BIStudio
  7. #  ArmA 2 binary version must be 1.04 or later
  8. #
  9. ##
  10. ### modified by Nasdero
  11. ### V 1.01 - 28.03.2015
  12. ### added BEPATH and changed handling of logfiles in ${ARMA_DIR}
  13. #=======================================================================
  14. #========               CONFIGURATION PARAMETERS                ========
  15. #======== MUST BE EDITED MANUALLY TO FIT YOUR SYSTEM PARAMETERS ========
  16. #=======================================================================
  17. ARMA_DIR=/home/steam/arma3
  18. PORT=2302
  19. NAME=tdm
  20. #NAME= your game name, if you run a Team Death Match server Name=tdm
  21. #but you need a folder called tdm in the ${CFG_DIR} folder
  22. #run the "check" parameter on this file here, it will give you all infos
  23. DELDAYS=7
  24. #DELDAYS=7 => old logfiles will be deleted after 7 days
  25. #
  26. OTHERPARAMS="-maxMem=2047 -nosound -exthreads=1 -noCB"
  27. # sample in the next row
  28. #OTHERPARAMS="-cpucount=4 -maxMem=2047 -nosound -exthreads=1 -noCB"
  29. MODS=
  30. # sample in the next row
  31. #MODS=@CBA_A3\;@tmr_alt\;@a3mp
  32. #MODS=@epoch\;@epochhive
  33. #=======================================================================
  34. # !!!!!!!!!! DO NOT EDIT ANYTHING BELOW THIS LINE !!!!!!!!!!
  35. #=======================================================================
  36. CFG_DIR=${ARMA_DIR}/sc/users
  37. CONFIG=${CFG_DIR}/${NAME}/server.cfg
  38. CFG=${CFG_DIR}/${NAME}/basic.cfg
  39. LOG_DIR=${ARMA_DIR}/logs
  40. BEPATH=${CFG_DIR}/${NAME}/battleye/
  41. #PROFILES= not working on linux as far as I know, arma 3 uses Player
  42. #what ever we try until now, don't use -profiles= in startcmd !!!!!
  43. #PROFILES=${CFG_DIR}/${NAME}
  44. PROFILES=${NAME}
  45. PIDFILE=${ARMA_DIR}/${PORT}.pid
  46. RUNFILE=${ARMA_DIR}/${PORT}.run
  47. LOGFILE=${LOG_DIR}/port_${PORT}.`date +%d.%m.%y_%H%M`.log
  48. SERVER=${ARMA_DIR}/arma3server
  49. #=======================================================================
  50. ulimit -c 1000000
  51.  
  52. case "$1" in
  53.  
  54.  
  55. start)
  56. # check if there is a server running or not
  57. ps ax | grep ${SERVER} | grep ${PORT}  > /dev/null
  58. if [ $? -eq 0 ]; then
  59. echo -e "\033[31mThere is a Server already running (${SERVER} at Port ${PORT})\033[0m"
  60. echo -e "\033[31mIt can happen, when you started a Server and stopped it to fast!\033[0m"
  61. echo -e "\033[31mJust stop the Server again and it should be good to start!\033[0m"
  62. echo $output | ps ax | grep ${SERVER} | grep ${PORT}
  63. else
  64. echo -e "Starting A3 server @PORT \033[35m${PORT}\033[0m..."
  65. # file to mark we want server running...
  66. echo "go" >${RUNFILE}
  67. # launch the background watchdog process to run the server
  68. nohup </dev/null >/dev/null $0 watchdog &
  69. fi
  70. ;;
  71.  
  72. stop)
  73. echo -e "Stopping A3 server if there is one (Port=\033[35m${PORT}\033[0m)..."
  74. if [ -f ${RUNFILE} ]; then
  75. # ask watcher process to exit by deleting its runfile...
  76. rm -f ${RUNFILE}
  77. else
  78. echo -e "\033[31mThere is no runfile (${RUNFILE}), Server shouldn't be up, will shut it down if it is up!\033[0m"
  79. fi
  80. # and terminate ArmA 3 server process
  81. if [ -f ${PIDFILE} ]; then
  82. kill -TERM $(< ${PIDFILE})
  83. if [ -f ${PIDFILE} ]; then
  84. rm -f ${PIDFILE}
  85. fi
  86. fi
  87. ;;
  88.  
  89. status)
  90. if [ -f ${RUNFILE} ]; then
  91. echo -e "\033[32mRunfile exist, Server should be up or is starting...\033[0m"
  92. echo -e "\033[35mIf the Server is \033[31mnot done\033[35m with its start, you will \033[31mnot get\033[35m a PID file info in the next rows.\033[0m"
  93. echo -e "\033[35mIf the Server is \033[32mdone\033[35m with its start, you will \033[32mget\033[35m a PID file and process info in the next rows.\033[0m"
  94. else
  95. echo -e "\033[31mRunfile doesn't exist, Server should be down or is going down...\033[0m"
  96. fi
  97. if [ -f ${PIDFILE} ]; then
  98. PID=$(< ${PIDFILE})
  99. echo -e "\033[32mPID file exists (PID=\033[35m${PID}\033[0m)..."
  100. if [ -f /proc/${PID}/cmdline ]; then
  101. echo -e "\033[32mServer process seems to be running...\033[0m"
  102. echo $output | ps ax | grep ${SERVER} | grep ${PORT}
  103. fi
  104. fi
  105. ;;
  106.  
  107. restart)
  108. $0 stop
  109. sleep 5s
  110. $0 start
  111. ;;
  112.  
  113. watchdog)
  114. # zip old logfile and move it to old directory
  115. cd ${LOG_DIR}
  116. if [ -f port_${PORT}*.log ]; then
  117. for i in port_${PORT}*.log; do tar -cvzf $i.tgz $i; rm $i; done
  118. mv port_${PORT}*.tgz old/
  119. echo >>${LOGFILE} "WATCHDOG ($$): [$(date)] Zipping logfiles from ${LOG_DIR} to ${LOG_DIR}/old"
  120. else
  121. echo >>${LOGFILE} "WATCHDOG ($$): [$(date)] No old logfile to zip in ${LOG_DIR}"
  122. fi
  123.  
  124. # zip old logfiles and move them to old directory
  125. cd ${ARMA_DIR}
  126. if  find ./*.log -type f; then
  127. for i in *.log; do tar -cvzf $i.`date +%d.%m.%y_%H%M`.tgz $i; rm $i; done
  128. mv *.tgz log ${LOG_DIR}/old
  129. echo >>${LOGFILE} "WATCHDOG ($$): [$(date)] Zipping logfiles from ${ARMA_DIR} to ${LOG_DIR}/old"
  130. else
  131. echo >>${LOGFILE} "WATCHDOG ($$): [$(date)] No old logfiles to zip in ${ARMA_DIR}"
  132. fi
  133.  
  134. # delete old logs when older then ${DELDAYS} days
  135. find ${LOG_DIR}/old -iname "*log.tgz" -mtime +${DELDAYS} -delete
  136. echo >>${LOGFILE} "WATCHDOG ($$): [$(date)] Deleting all zipped logfile in ${LOG_DIR}/old when older then ${DELDAYS} days."
  137.  
  138. # this is a background watchdog process. Do not start directly
  139. while [ -f ${RUNFILE} ]; do
  140. # launch the server...
  141. cd ${ARMA_DIR}
  142. echo >>${LOGFILE} "WATCHDOG ($$): [$(date)] Starting server (port ${PORT})..."
  143. export LD_LIBRARY_PATH=.:${ARMA_DIR}:${ARMA_DIR}/@epochhive:$LD_LIBRARY_PATH
  144.  
  145. ${SERVER} >>${LOGFILE} 2>&1 -config=${CONFIG} -cfg=${CFG} -port=${PORT} -name=${NAME} -pid=${PIDFILE} -mod=${MODS} -bepath=${BEPATH} ${OTHERPARAMS}
  146.  
  147. if [ -f ${RUNFILE} ]; then
  148. echo >>${LOGFILE} "WATCHDOG ($$): [$(date)] Server died, waiting to restart..."
  149. sleep 5s
  150. else
  151. echo >>${LOGFILE} "WATCHDOG ($$): [$(date)] Server shutdown intentional, watchdog terminating"
  152. fi
  153. done
  154. ;;
  155.  
  156. check)
  157. clear
  158. echo -ne "\033[33mArmA 3 directory:\033[0m ${ARMA_DIR} "
  159. if [ -d ${ARMA_DIR} ]; then
  160. echo -e "\033[32mOK\033[0m"
  161. else
  162. echo -e "\033[31mMISSING!\033[0m"
  163. echo -e "========= Check your settings (ARMA_DIR)! =========\n"
  164. fi
  165.  
  166. echo -ne "\033[33mServer executable:\033[0m ${SERVER} "
  167. if [ -x ${SERVER} ]; then
  168. echo -e "\033[32mOK\033[0m"
  169. else
  170. echo -e "\033[31mMISSING!\033[0m"
  171. echo -e "========= Server executable not found, arma3server should be in that folder when path is right =========\n"
  172. fi
  173.  
  174. echo -ne "\033[33mCFG directory:\033[0m ${CFG_DIR}/${NAME} "
  175. if [ -d ${CFG_DIR}/${NAME} ]; then
  176. echo -e "\033[32mOK\033[0m"
  177. else
  178. echo -e "\033[31mMISSING!\033[0m"
  179. echo -e "========= We need that folder for the config files! You can use the next row to create it: ========="
  180. echo -e "\033[35mmkdir ${CFG_DIR}/${NAME}\033[0m\n"
  181. fi
  182.  
  183. echo -ne "\033[33mConfig file:\033[0m ${CONFIG} "
  184. if [ -f ${CONFIG} ]; then
  185. echo -e "\033[32mOK\033[0m"
  186. else
  187. echo -e "\033[31mMISSING!\033[0m"
  188. echo -e "========= We need this file in that folder =========\n"
  189. fi
  190.  
  191. echo -ne "\033[33mBasic file:\033[0m ${CFG} "
  192. if [ -f ${CFG} ]; then
  193. echo -e "\033[32mOK\033[0m"
  194. else
  195. echo -e "\033[31mMISSING!\033[0m"
  196. echo -e "========= We need this file in that folder =========\n"
  197. fi
  198.  
  199. echo -ne "\033[33mBattleye directory:\033[0m ${BEPATH} "
  200. if [ -d ${BEPATH} ]; then
  201. echo -e "\033[32mOK\033[0m"
  202. else
  203. echo -e "\033[31mMISSING!\033[0m"
  204. echo -e "========= We need that folder for the Battleye files! You can use the next row to create it: ========="
  205. echo -e "\033[35mmkdir ${BEPATH}\033[0m\n"
  206. fi
  207.  
  208. echo -ne "\033[33mArma3Profile:\033[0m ${CFG_DIR}/${NAME}/${NAME}.arma3profile "
  209. if [ -f ${CFG_DIR}/${NAME}/${NAME}.arma3profile ]; then
  210. echo -e "\033[32mOK\033[0m"
  211. else
  212. echo -e "\033[31mMISSING!\033[0m"
  213. echo -e "========= We need that file! You can create it like this, edit it then for your need later: ========="
  214. echo -e "========= ( https://community.bistudio.com/wiki/Arma_3_Dedicated_Server) ****.Arma3Profile  =========\033[35m"
  215. echo -n 'echo -e "version=2;\nviewDistance=3000;\npreferredObjectViewDistance=3000;\nterrainGrid=12.5;\nactiveKeys[]=\n{\n};" > '
  216. echo -n "${CFG_DIR}/${NAME}/${NAME}.arma3profile"
  217. echo -e "\n\033[0m"
  218. fi
  219.  
  220. echo -ne "\033[33mLog directory:\033[0m ${LOG_DIR} "
  221. if [ -d ${LOG_DIR} ]; then
  222. echo -e "\033[32mOK\033[0m"
  223. else
  224. echo -e "\033[31mMISSING!\033[0m"
  225. echo -e "========= We need that folder. You can use the next row to create it: ========="
  226. echo -e "\033[35mmkdir ${LOG_DIR}\033[0m\n"
  227. fi
  228.  
  229. echo -ne "\033[33mOld Log directory:\033[0m ${LOG_DIR}/old "
  230. if [ -d ${LOG_DIR}/old ]; then
  231. echo -e "\033[32mOK\033[0m"
  232. else
  233. echo -e "\033[31mMISSING!\033[0m"
  234. echo -e "========= We need that folder. You can use the next row to create it: ========="
  235. echo -e "\033[35mmkdir ${LOG_DIR}/old\033[0m\n"
  236. fi
  237.  
  238. echo -ne "\033[33mProfile directory:\033[0m ~/.local/share/Arma\ 3\ -\ Other\ Profiles/${NAME} "
  239. if [ -d ~/.local/share/Arma\ 3\ -\ Other\ Profiles/${NAME} ]; then
  240. echo -e "\033[32mOK\033[0m"
  241. else
  242. echo -e "\033[31mMISSING!\033[0m"
  243. echo -e "========= You should create this folder. You can use the next row for that: ========="
  244. echo -e "=========       ( Not sure if we need this? Capital letters are ok ?)       ========="
  245. echo -e "\033[35mmkdir -p ~/.local/share/Arma\ 3\ -\ Other\ Profiles/${NAME}\033[0m\n"
  246. fi
  247.  
  248. echo -ne "\033[33mArma3Profile symlink:\033[0m ~/.local/share/Arma\ 3\ -\ Other\ Profiles/${NAME}/${NAME}.Arma3Profile "
  249. if [ -L ~/.local/share/Arma\ 3\ -\ Other\ Profiles/${NAME}/${NAME}.Arma3Profile ]; then
  250. echo -e "\033[32mOK\033[0m"
  251. else
  252. echo -e "\033[31mMISSING!\033[0m"
  253. echo -e "========= You should creat this symlink. You can use the next row for that: ========="
  254. echo -e "=========       ( Capital letters are ok in ~/.local/share/Arma 3.. !)      ========="
  255. echo -e "\033[35mln -s ${CFG_DIR}/${NAME}/${NAME}.arma3profile ~/.local/share/Arma\ 3\ -\ Other\ Profiles/${NAME}/${NAME}.Arma3Profile\033[0m\n"
  256. fi
  257.  
  258. echo -e "\n\033[33mPort number will be: \033[0m${PORT}"
  259. echo -e "\033[33mPID file will be: \033[0m${PIDFILE}"
  260. echo -e "\033[33mRUN file will be: \033[0m${RUNFILE}"
  261.  
  262. echo -e "\n\033[33mStart cmd will be:\033[0m"
  263. echo -e "${SERVER} >>${LOGFILE} 2>&1 -config=${CONFIG} -cfg=${CFG} -port=${PORT} -name=${NAME} -pid=${PIDFILE} -mod=${MODS} ${OTHERPARAMS}"
  264.  
  265. echo -e "\n\033[31mIf you got something MISSING, you have to work from the top to the bottom, fix the top issue and start the check again!\033[0m"
  266. ;;
  267.  
  268. log)
  269. # you can see the logfile in realtime, no more need for screen or something else
  270. clear
  271. echo "To stop viewing the logfile press CTRL+C"
  272. echo "========================================"
  273. sleep 1s
  274. tail -f ${LOG_DIR}/port_${PORT}*.log
  275. ;;
  276.  
  277. *)
  278. echo "$0 (start|stop|restart|status|check|log)"
  279. ;;
  280. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement