Jump to content
Sign in to follow this  
ALHSLeo

Start Stop Script for FreeBSD

Recommended Posts

Standart start script for arma2 linux server correctly don't work under FreeBSD, server starts, but don't stops.

This is changed startup script - working under FreeBSD :

#!/usr/local/bin/bash

#

# armaserver: ArmA 2 Linux Dedicated Server Control Script

# © 2009 BIStudio

# ArmA 2 binary version must be 1.04 or later

#

#=======================================================================

#======== CONFIGURATION PARAMETERS ========

#======== MUST BE EDITED MANUALLY TO FIT YOUR SYSTEM PARAMETERS ========

#=======================================================================

ARMA_DIR=.

CONFIG=server.cfg

CFG=arma2.cfg # arma 2 server arma2.cfg

PORT=2302

PIDFILE=${ARMA_DIR}/${PORT}.pid

RUNFILE=${ARMA_DIR}/${PORT}.run

LOGFILE=${ARMA_DIR}/log.${PORT}.txt

SERVER=${ARMA_DIR}/server

SERVER_BIN=server ## Arma 2 server binary name

MODS=@beta\; # mods

#=======================================================================

ulimit -c 1000000

case "$1" in

start)

if [ -f ${RUNFILE} ]; then

$0 stop

fi

echo "Starting ArmA 2 server..."

# file to mark we want server running...

echo "go" >${RUNFILE}

# launch the background watchdog process to run the server

nohup </dev/null >/dev/null $0 watchdog &

;;

stop)

echo "Stopping ArmA 2 server..."

if [ -f ${RUNFILE} ]; then

# ask watcher process to exit by deleting its runfile...

rm -f ${RUNFILE}

fi

# and terminate ArmA 2 server process

if [ -f ${PIDFILE} ]; then

killall -TERM ${SERVER_BIN}

if [ -f ${PIDFILE} ]; then

rm -f ${PIDFILE}

fi

fi

;;

status)

if [ -f ${RUNFILE} ]; then

echo "Server should be running..."

else

echo "Server should not be running..."

fi

if [ -f ${PIDFILE} ]; then

PID=$(< ${PIDFILE})

echo "PID file exists (PID=${PID})..."

if [ -f /proc/${PID}/cmdline ]; then

echo "Server process seems to be running..."

fi

fi

;;

check)

echo -n "ArmA 2 directory: ${ARMA_DIR} "

if [ -d ${ARMA_DIR} ]; then

echo "OK"

else

echo "MISSING!"

fi

echo -n "Server executable: ${SERVER} "

if [ -x ${SERVER} ]; then

echo "OK"

else

echo "ERROR!"

fi

echo "Port number: ${PORT}"

echo -n "Config file: ${CONFIG} "

if [ -f ${CONFIG} ]; then

echo "OK"

else

echo "MISSING!"

fi

echo "PID file: ${PIDFILE}"

echo "RUN file: ${RUNFILE}"

;;

restart)

$0 stop

$0 start

;;

watchdog)

# this is a background watchdog process. Do not start directly

while [ -f ${RUNFILE} ]; do

# launch the server...

cd ${ARMA_DIR}

echo >>${LOGFILE} "WATCHDOG ($$): [$(date)] Starting server (port ${PORT})..."

${SERVER} >>${LOGFILE} 2>&1 -server -cfg=${CFG} -config=${CONFIG} -port=${PORT} -pid=${PIDFILE} -mod=${MODS}

if [ -f ${RUNFILE} ]; then

echo >>${LOGFILE} "WATCHDOG ($$): [$(date)] Server died, waiting to restart..."

sleep 5s

else

echo >>${LOGFILE} "WATCHDOG ($$): [$(date)] Server shutdown intentional, watchdog terminating"

fi

done

;;

*)

echo "$0 (start|stop|restart|status|check)"

;;

esac

This script kill by process name all processes, and normally stop arma2 server. But : if you start different arma 2 servers from 1 user shell - then better create different users for different arma 2 servers, or rename binaries, and change line : SERVER_BIN, becouse this scripts kills other arma 2 servers running under this user.

Edited by ALHSLeo

Share this post


Link to post
Share on other sites

Script version 0.2 - added email to admin if server restarts, added normal killing of processes with watchdog - if central server process died ( reason - on the FreeBSD - if the centrall process died - server try to create another processes, but don't kill other running processes - and server can't start after crash).

#!/usr/local/bin/bash
#
# armaserver: ArmA 2 Linux Dedicated Server Control Script
#  (c) 2009 BIStudio
#  ArmA 2 binary version must be 1.04 or later
#
# Modified by ALHS_Leo for FreeBSD Usage

#=======================================================================
#========               CONFIGURATION PARAMETERS                ========
#======== MUST BE EDITED MANUALLY TO FIT YOUR SYSTEM PARAMETERS ========
#=======================================================================
ARMA_DIR=.
CONFIG=server.cfg
CFG=arma2.cfg # arma 2 server arma2.cfg
PORT=2302
PIDFILE=${ARMA_DIR}/${PORT}.pid
RUNFILE=${ARMA_DIR}/${PORT}.run
LOGFILE=${ARMA_DIR}/log.${PORT}.txt
SERVER=${ARMA_DIR}/server
SERVER_BIN=server ## Arma 2 server binary name
MODS=@beta\; # mods
ADMIN_MAIL="Your Email HERE !!!" ## Admin email
#=======================================================================
ulimit -c 1000000

case "$1" in


   start)
       if [ -f ${RUNFILE} ]; then
           $0 stop
           killall -TERM ${SERVER_BIN}
           sleep 2s
       fi
       echo "Starting ArmA 2 server..."
       # file to mark we want server running...
       echo "go" >${RUNFILE}
       # launch the background watchdog process to run the server
       nohup </dev/null >/dev/null $0 watchdog &
       ;;

   stop)
       echo "Stopping ArmA 2 server..."
       if [ -f ${RUNFILE} ]; then
       # ask watcher process to exit by deleting its runfile...
           rm -f ${RUNFILE}
       fi
       # and terminate ArmA 2 server process
       if [ -f ${PIDFILE} ]; then
              killall -TERM ${SERVER_BIN}
           if [ -f ${PIDFILE} ]; then
               rm -f ${PIDFILE}
           fi
       fi
       ;;


   status)
       if [ -f ${RUNFILE} ]; then
           echo "Server should be running..."
       else
           echo "Server should not be running..."
       fi
       if [ -f ${PIDFILE} ]; then
           PID=$(< ${PIDFILE})
           echo "PID file exists (PID=${PID})..."
           if [ -f /proc/${PID}/cmdline ]; then
               echo "Server process seems to be running..."
           fi
       fi
       ;;


   check)
       echo -n "ArmA 2 directory: ${ARMA_DIR} "
       if [ -d ${ARMA_DIR} ]; then
           echo "OK"
       else
           echo "MISSING!"
       fi

       echo -n "Server executable: ${SERVER} "
       if [ -x ${SERVER} ]; then
           echo "OK"
       else
           echo "ERROR!"
       fi

       echo "Port number: ${PORT}"

       echo -n "Config file: ${CONFIG} "
       if [ -f ${CONFIG} ]; then
           echo "OK"
       else
           echo "MISSING!"
       fi

       echo "PID file: ${PIDFILE}"
       echo "RUN file: ${RUNFILE}"

       ;;

   restart)
       $0 stop
       $0 start
       ;;

   watchdog)
       # this is a background watchdog process. Do not start directly
       while [ -f ${RUNFILE} ]; do
       # launch the server...
           cd ${ARMA_DIR}
           killall -TERM ${SERVER_BIN}
           echo >>${LOGFILE} "WATCHDOG ($$): [$(date)] Starting server (port ${PORT})..."
           ${SERVER} >>${LOGFILE} 2>&1 -server -cfg=${CFG} -config=${CONFIG} -port=${PORT} -pid=${PIDFILE} -mod=${MODS}
           if [ -f ${RUNFILE} ]; then
               echo >>${LOGFILE} "WATCHDOG ($$): [$(date)] Server died, waiting to restart..." && /bin/echo "ARMA Server Restarted [$(date)]" | /usr/bin/mail ${ADMIN_MAIL}
               sleep 5s
           else
               echo >>${LOGFILE} "WATCHDOG ($$): [$(date)] Server shutdown intentional, watchdog terminating"
           fi
       done
       ;;
   *)
       echo "$0 (start|stop|restart|status|check)"
       ;;
esac

P.S. If you wanna bind processes for cpecified cores of cpu - change the folloving line :

from :
${SERVER} >>${LOGFILE} 2>&1 -server -cfg=${CFG} -config=${CONFIG} -port=${PORT} -pid=${PIDFILE} -mod=${MODS}
to :
/usr/bin/cpuset -l 0,1,2 -s armaserv ${SERVER} >>${LOGFILE} 2>&1 -server -cfg=${CFG} -config=${CONFIG} -port=${PORT} -pid=${PIDFILE} -mod=${MODS} -cpuCount=3

Edited by ALHSLeo

Share this post


Link to post
Share on other sites

Awesome ! Is there anything like this available for Windows dedicated Servers ? Already searching for a while but I can't find anything....:(

Share this post


Link to post
Share on other sites

Nice to see someone else doing it.

Ever tried djb's daemontools? Handles process supervision very cleanly. I've not got around to setting up the server on FreeBSD yet but I expect that's the way I'd go about it.

Share this post


Link to post
Share on other sites

/usr/ports/sysutils/daemontools/ - this daemon in ports available, but i don;t see, how always, reason to installing another daemon for checking needed daemon, who checks daemontools then ? :)

P.S. Better to insert some changes in standart Linux startup script for FreeBSD usage ( on the freebsd for one arma 2 server i have 6 processes on quad core cpu, standart Linux script kill only first process ), and check server with it, without installing another program.

Edited by ALHSLeo

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×