SillymeX

Debian 8.1 startup script issues

4 posts in this topic

Hello everyone,

I'm currently using this startup script and occasionally it works fine but for majority of the time when I launch my server through it, it will say "server is already running" when it's not. Occasionally when it did that, I managed to find out that some mods were having issues which did not allow the server to start. After fixing the issues, the startup script worked again. This time its different. Firstly I tried running the script with only exile mod just to be sure that it's not an issue in the mods. It would still say "server is already running" which means that it's not a mod issue.  Also I always check if it actually starts the server by doing the top command. Unfortunately, I don't have any processes running, yet it repeats "server is already running". It will not make any logs since the server is not actually up. As soon as I go to my a3 root folder and launch it with the parameters, the server loads up with all of the mods with no errors.

I would appreciate a working solution to this.

Here is the script that I use:

#!/bin/bash
### BEGIN INIT INFO
# Provides:            exile
# Required-Start:   $remote_fs $network
# Required-Stop:    $remote_fs $network
# Should-Start:        mysql
# Should-Stop:      mysql
# Default-Start:    2 3 4 5
# Default-Stop:     0 1 6
# Description:      ArmA 3 Exile init.d Script by Flodding
### END INIT INFO

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

USERNAME="pirkka" # This user *MUST* exist on the system.
EXILE_DIR="/home/${USERNAME}/arma3/" # Change to your path...
NAME="cfg" # You can use any name here, your server, or clan...
CONFIGFOLDER="${EXILE_DIR}/${NAME}"
CONFIG="${NAME}/config.cfg" # Remember to move config files from @exileserver/*.cfg to YOUR_INSTANCE_NAME/!
CFG="${NAME}/basic.cfg" # Remember to move config files from @exileserver/*.cfg to YOUR_INSTANCE_NAME/!
BEPATH="${EXILE_DIR}/battleye"
LOG_DIR="${CONFIGFOLDER}/logs"
PORT=2302
PIDFILE="${CONFIGFOLDER}/${PORT}.pid"
if [ -f ${PIDFILE} ]; then
    RUNNING=1
    PID=$(cat ${PIDFILE} > /dev/null)
else
    RUNNING=0
fi
SERVICE="arma3server"
MODS="@exile"
SERVERMOD="@exileserver"
#CPU_COUNT=2

# Some common options
# -ip=0.0.0.0
# -port=2302 (default)
# -mod=@exile;kart;mark;heli;
# -servermod=@exileserver
# -config=C:\Arma\Server\@exileserver\config.cfg
# -cfg=C:\Arma\Server\@exileserver\basic.cfg
# -name=INSTANCE
# -profiles=INSTANCE
# -log
# -nolog
# -world=empty
# -nosplash
# -nosound
# -nopause
# -malloc=system -malloc=tbbmalloc
# -autoinit

OPTIONS="-port=${PORT} -pid=${PIDFILE} -name=${NAME} -profiles=${NAME} -cfg=${CFG} -config=${CONFIG} -mod=@Exile\;@AllInArmaTerrainPack\;@esseker\; -servermod=@ExileServer\;@infiSTAR_Exile\;@enigma_exile\; -log -nopause -nosound -nosplash -autoinit"
TMUX_SESSION="exile" # You can use any name here.

#=======================================================================
# CONFIG END
#=======================================================================

TMUX=$(which tmux)

[ ! -x "$TMUX" ] && echo "Tmux not found" >&2 && exit 1

if [ ! -d "$LOG_DIR" ]; then
    echo "${LOG_DIR} not found. Creating..."
    mkdir -p $LOG_DIR
fi

exile_start() {
    if [ ! -f $EXILE_DIR/$SERVICE ]
    then
        echo "$SERVICE not found! Stopping..."
        sleep 1
        exit
    else
        if  [ ${RUNNING} -eq 1 ];
        then
            echo "$SERVICE is already running!"
        else
            echo "Setting Permissions..."
            #chmod -R 0755 $EXILE_DIR
            chown -R $USERNAME:$USERNAME /home/$USERNAME
            echo "Starting $SERVICE..."
            cd $EXILE_DIR
            # Fix: http://exile.majormittens.co.uk/topic/6054-linux-dedicated-server-setup-guide-debian-7/?do=findComment&comment=28274
            find @exile/ -depth -exec rename 's/(.*)\/([^\/]*)/$1\/\L$2/' {} \;
            find @exileserver/ -depth -exec rename 's/(.*)\/([^\/]*)/$1\/\L$2/' {} \;
            if [ "${2}" == "-silent" ]; then
                su ${USERNAME} -c "${TMUX} new-session -d -s ${TMUX_SESSION} \"./${SERVICE} ${OPTIONS} > ${LOG_DIR}/exile.log 2> ${LOG_DIR}/errors.log\""
            else
                su ${USERNAME} -c "${TMUX} new-session -d -s ${TMUX_SESSION} \"./${SERVICE} ${OPTIONS} 2> ${LOG_DIR}/errors.log | tee ${LOG_DIR}/exile.log\""
            fi
            echo "Searching Process ${SERVICE}..."
            sleep 8
            if pgrep -u $USERNAME -f $SERVICE > /dev/null
            then
                echo "$SERVICE is now running."
                RUNNING=1
            else
                echo "Error! Could not start $SERVICE!"
                RUNNING=0
            fi
        fi
    fi
}

exile_stop() {
    if [ ${RUNNING} -eq 1 ];
    then
        echo "Stopping ${SERVICE}..."
        su $USERNAME -c "$TMUX kill-session -t $TMUX_SESSION"
        $TMUX kill-session -t $TMUX_SESSION
        killall -9 $SERVICE
    else
        echo "$SERVICE is stopped."
    fi

    if [ -f ${PIDFILE} ]; then
        rm -f ${PIDFILE}
    fi
}

exile_status() {
    if [ -f ${PIDFILE} ]; then
        PID=$(cat ${PIDFILE})
        echo "Server is running (PID=${PID})..."
    else
        echo "Server not running..."
        exit 0
    fi
}

case "$1" in
    start)
        exile_start
    ;;

    stop)
        exile_stop
    ;;

    restart)
        exile_stop
        exile_start
    ;;

    status)
        exile_status
    ;;

    attach)
        su $USERNAME -c "$TMUX at -t $TMUX_SESSION"
    ;;

    *)
        echo "$0 (start|stop|restart|status|attach)"
        exit 1
    ;;
esac

exit 0

Edited by SillymeX
typos

Share this post


Link to post
Share on other sites

there is a bug in the current arma3server binary for linux, which can only be fixed by BI.

the -pid parameter is broken, and the binary is not writing the processid into a file at all, no matter what you do.

 

your startscript is relying on that file tho, and so it is not able to shut it down.

 

possible workaround:

instead of using the pid to shut it down, just do it by "killall arma3server"

but watch out! if you have multiple servers runnning, this would shut down ALL running servers. you can prevent this by giving all the binaries a unique name like "arma3productive", "arma3test" and so on.

 

EDIT: well actually your script is doing a "killall" already, not really using the pid.

however, it still checks if there IS a pid file, and does nothing if not (even if its not using the pid actually). you basically just need to remove those checks.

Edited by =TBM= BangL

Share this post


Link to post
Share on other sites
Advertisement

I found that issue with no PID file being written, which normally I rely on for writing my start/stop scripts.

I ended up using Debian's Upstart to handle restarts (and recovery) and it works beautifully. Please see this post for my Upstart script.

Share this post


Link to post
Share on other sites

I would just symlink the armaserver for each server & use killall servername.
It will result in alot simplier startup script & less chances of making a mistake.

Share this post


Link to post
Share on other sites
Advertisement

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.