Advertisement
Guest User

Untitled

a guest
Oct 24th, 2014
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.89 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # armaserver: ArmA 2 Linux Dedicated Server Control Script
  4. #  (c) 2010 BIStudio
  5. #  ArmA 2 binary version must be 1.04 or later
  6. #
  7.  
  8. #=======================================================================
  9. #========               CONFIGURATION PARAMETERS                ========
  10. #======== MUST BE EDITED MANUALLY TO FIT YOUR SYSTEM PARAMETERS ========
  11. #=======================================================================
  12. ARMA_DIR=/home/propslam/arma2
  13. CONFIG=server.cfg
  14. PORT=2302
  15. PIDFILE=${ARMA_DIR}/${PORT}.pid
  16. RUNFILE=${ARMA_DIR}/${PORT}.run
  17. LOGFILE=${ARMA_DIR}/log.${PORT}.txt
  18. SERVER=${ARMA_DIR}/server
  19. OTHERPARAMS="-cpucount=2 -mod=ca"
  20. #=======================================================================
  21. ulimit -c 1000000
  22.  
  23. case "$1" in
  24.  
  25.  
  26.     start)
  27.     if [ -f ${RUNFILE} ]; then
  28.         $0 stop
  29.     fi
  30.     echo "Starting ArmA 2 server..."
  31.     # file to mark we want server running...   
  32.     echo "go" >${RUNFILE}
  33.     # launch the background watchdog process to run the server
  34.     nohup </dev/null >/dev/null $0 watchdog &
  35.     ;;
  36.    
  37.     stop)
  38.     echo "Stopping ArmA 2 server..."
  39.     if [ -f ${RUNFILE} ]; then
  40.     # ask watcher process to exit by deleting its runfile...
  41.         rm -f ${RUNFILE}
  42.     fi
  43.     # and terminate ArmA 2 server process
  44.     if [ -f ${PIDFILE} ]; then
  45.         kill -TERM $(< ${PIDFILE})
  46.         if [ -f ${PIDFILE} ]; then
  47.         rm -f ${PIDFILE}
  48.         fi
  49.     fi
  50.     ;;
  51.    
  52.    
  53.     status)
  54.     if [ -f ${RUNFILE} ]; then
  55.         echo "Server should be running..."
  56.     else
  57.         echo "Server should not be running..."
  58.     fi
  59.     if [ -f ${PIDFILE} ]; then
  60.         PID=$(< ${PIDFILE})
  61.         echo "PID file exists (PID=${PID})..."
  62.         if [ -f /proc/${PID}/cmdline ]; then
  63.         echo "Server process seems to be running..."
  64.         fi
  65.     fi
  66.     ;;
  67.    
  68.    
  69.     check)
  70.     echo -n "ArmA 2 directory: ${ARMA_DIR} "
  71.     if [ -d ${ARMA_DIR} ]; then
  72.         echo "OK"
  73.     else
  74.         echo "MISSING!"
  75.     fi
  76.    
  77.     echo -n "Server executable: ${SERVER} "
  78.     if [ -x ${SERVER} ]; then
  79.         echo "OK"
  80.     else
  81.         echo "ERROR!"
  82.     fi
  83.    
  84.     echo "Port number: ${PORT}"
  85.    
  86.     echo -n "Config file: ${CONFIG} "
  87.     if [ -f ${CONFIG} ]; then
  88.         echo "OK"
  89.     else
  90.         echo "MISSING!"
  91.     fi
  92.    
  93.     echo "PID file: ${PIDFILE}"
  94.     echo "RUN file: ${RUNFILE}"
  95.    
  96.     ;;
  97.  
  98.     restart)
  99.     $0 stop
  100.     $0 start
  101.         ;;
  102.  
  103.     watchdog)
  104.     # this is a background watchdog process. Do not start directly
  105.     while [ -f ${RUNFILE} ]; do
  106.     # launch the server...
  107.         cd ${ARMA_DIR}
  108.         echo >>${LOGFILE} "WATCHDOG ($$): [$(date)] Starting server (port ${PORT})..."
  109.         ${SERVER} >>${LOGFILE} 2>&1 -server -config=${CONFIG} -port=${PORT} -pid=${PIDFILE} ${OTHERPARAMS}
  110.         if [ -f ${RUNFILE} ]; then
  111.         echo >>${LOGFILE} "WATCHDOG ($$): [$(date)] Server died, waiting to restart..."
  112.         sleep 5s
  113.         else
  114.         echo >>${LOGFILE} "WATCHDOG ($$): [$(date)] Server shutdown intentional, watchdog terminating"
  115.         fi
  116.     done    
  117.     ;;
  118.     *)
  119.     echo "$0 (start|stop|restart|status|check)"
  120.     ;;
  121. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement