Advertisement
Guest User

Untitled

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