Author Topic: Empty Server Auto Restart  (Read 1619 times)

rayolko

  • *
  • Posts: 20
    • View Profile
Empty Server Auto Restart
« on: March 29, 2018, 09:28:19 am »
HELLO

I am looking for a plugin that would restart the server 10 seconds after all players have left the server and the server is empty.

The reason I need a plugin like this is I have an issue on my server where weapons & items don't load after the first game on the server. If I restart the server, it fixes it for 1 game and then any game after that, the issue comes up again. It is likely some plugin bug or conflict, but not sure exactly what is causing it and have spent hours trying to figure it out. So I am thinking this auto server restart could be a nice bandaid solution.

Anyway, hoping someone can help with this, thanks!

CONTACT ME: http://steamcommunity.com/id/rayolkoo
.

dustin

  • *
  • Posts: 45
    • View Profile
Re: Empty Server Auto Restart
« Reply #1 on: March 29, 2018, 10:49:27 pm »
I have a plugin that does this but it's kinda hacky - as in it needs some afk cvars set in the server.cfg so that the server can remain idle when all players leave the game. Also needs a cron job script to reboot the server (not sure if you're on linux or windows).

Sir probably has a more optimized server restarter plugin if you wanna ask him.

rayolko

  • *
  • Posts: 20
    • View Profile
Re: Empty Server Auto Restart
« Reply #2 on: March 30, 2018, 04:42:22 am »
I use windows and I tried to get in touch with him, but he did not answer me... you could not try to connect with him or if he does not know about this yet?

thank you
.

dustin

  • *
  • Posts: 45
    • View Profile
Re: Empty Server Auto Restart
« Reply #3 on: March 31, 2018, 07:34:07 pm »
Ok well this is the original plugin I use:
https://pastebin.com/WhEFna2p

But it requires these cvars be set in the server.cfg (so the server doesn't automatically change maps when all players DC):
Code: [Select]
// idle settings
sm_cvar director_afk_timeout 999999999999
sm_cvar mp_allowspectators 1
sm_cvar allow_all_bot_survivor_team 1
sm_cvar mp_autokick 0

If you don't want to set those cvars permamently in your server.cfg you could probably use this:
https://forums.alliedmods.net/showthread.php?t=306494
It's kind of hacky tho (every time a player DC's, it sets the AFK cvars briefly then sets them back if there's still human players on the server) but at least you won’t have to wait for the bots to die before the round ends.




Both of those plugins stop the screen / game session entirely. In linux you'd need to set up a cronjob to auto-reboot the server back up:

auto-restart.sh (l4d2 screen session name: 'left4dead2_server' )
Code: [Select]
#!/bin/bash

alive=`ps ux | grep 'left4dead2_server' | wc -l | awk '{ print $1 }'`

if [ $alive -lt 2 ]; then
        echo "First Check: l4d2 server offline."
        sleep 3s

alive2=`ps ux | grep 'left4dead2_server' | wc -l | awk '{ print $1 }'`
if [ $alive2 -lt 2 ]; then
echo "Second Check: l4d2 server still offline."
sleep 3s

alive3=`ps ux | grep 'left4dead2_server' | wc -l | awk '{ print $1 }'`
if [ $alive3 -lt 2 ]; then
echo "Third Check: Starting l4d2 server..."
sleep 2s
/root/start.sh
else
echo "Third Check: L4D2 server already active. Terminating.."
sleep 3s
fi
else
echo "Second Check: L4D2 server already active. Terminating.."
sleep 3s
fi

else
echo "First Check: L4D2 server already active. Terminating.."
sleep 3s
fi

Cronjob (crontab -e)
Code: [Select]
# Automatically reboot the server if it goes down
* * * * * ( sleep 10 ; /root/auto-restart.sh)


I never worked with windows servers before so I'm not sure if there's a way to automatically reboot the server every so often.

edit: modified auto-restart.sh to include some additional checks before launching the server.
edit2: Second link (got someone to clean up the code quite a bit and posted it to alliedmodders)
« Last Edit: April 02, 2018, 03:04:11 pm by dustin »

dustin

  • *
  • Posts: 45
    • View Profile
Re: Empty Server Auto Restart
« Reply #4 on: April 05, 2018, 01:42:31 am »
Modified the automated restart script for users who have multiple L4D2 servers on the same machine (can be any amount of servers).

Also someone cleaned up the code quite a bit from that alliedmodders post so I'd suggest just using that version of the plugin and not setting those cvars permanently.

auto-restart.sh
Code: [Select]
#!/bin/bash

#    ###############################
#    ##     ~About / How to use this~ #
#    ###############################
#
#    auto-restart.sh
#
#    This script is intended to be launched by a cronjob task every minute
#    to check for any offline L4D2 servers. The cronjob would look like this:
#        * * * * * /path/to/auto-restart.sh
#
#    (this script assumes every server has it's own startup script)
#
#    However many servers you put as "NUM_SERVERS" should also be equal to
#    the amount of screen names and start paths. Keep the naming consistant.
#
#    Example of single L4D2 server on a machine:
#
#        NUM_SERVERS=1
#        server1=screen_name
#        start_svr1=/path/to/start.sh
#
#    Example of 3 L4D2 servers on a single machine:
#
#        NUM_SERVERS=3
#
#        server1=screen_name
#        server2=screen_name
#        server3=screen_name
#
#        start_svr1=/path/to/start.sh
#        start_svr2=/path/to/start.sh
#        start_svr3=/path/to/start.sh
#
#
#    This script basically just loops through the amount of "NUM_SERVERS"
#    and changes certain numbers after each loop (e.g. start_svr2 on second loop,
#    start_svr3 on third loop). Obviously the screen names should all be unique
#    for each server.

#    You can add as many servers as you like. HOWEVER, keep the name the same
#    BEFORE the equal sign. e.g. server1, server2, server3. & start_svr1, start_svr2,
#    start_svr3.
#

#############################
# Customization starts HERE #
#############################

# How many L4D2 servers on your machine?
NUM_SERVERS=2

###########################################
# Edit your L4D2 server screen names HERE #
###########################################
#note: DON'T edit before the equal sign

server1=screen_name_here
server2=screen_name_here

#server3=  #screen name for server 3
#server4=  #screen name for server 4
#etc..

####################################
# Edit path to launch scripts HERE #
####################################
#note: DON'T edit before the equal sign

start_svr1=/path/to/start.sh
start_svr2=/path/to/start.sh

#start_svr3= #/path/to/start.sh for server 3
#start_svr4= #/path/to/start.sh for server 4
#etc..

###############################
# Customization ends HERE     #
###############################

# Don't edit this part:

i=1;
while [[ i -le ${NUM_SERVERS} ]] ;
do


var="server$i"
var2="start_svr$i"

echo ""
echo "--------------------------------"
echo ""
echo "Initiating check on server #${i}"
echo ""
sleep 1s

alive=`ps ux | grep "${!var}" | wc -l | awk '{ print $1 }'`
 
if [ $alive -lt 2 ]; then
        echo "Check #1: l4d2 server offline."
        sleep 3s
       
        alive2=`ps ux | grep "${!var}" | wc -l | awk '{ print $1 }'`
        if [ $alive2 -lt 2 ]; then
            echo "Check #2: l4d2 server still offline."
            sleep 3s
           
            alive3=`ps ux | grep "${!var}" | wc -l | awk '{ print $1 }'`
            if [ $alive3 -lt 2 ]; then
                echo "Check #3: Starting l4d2 server..."
                sleep 3s
                ${!var2}
            else
                echo "Third Check: L4D2 server already active. Terminating.."
                sleep 3s
            fi
        else
            echo "Second Check: L4D2 server already active. Terminating.."
            sleep 3s
        fi
   
else
    echo "First Check: L4D2 server already active. Terminating.."
    sleep 3s
fi

i=$((i+1));

echo ""
done

exit 
« Last Edit: April 05, 2018, 03:03:07 am by dustin »

rayolko

  • *
  • Posts: 20
    • View Profile
Re: Empty Server Auto Restart
« Reply #5 on: April 08, 2018, 06:10:19 am »
thank you :) work
.

 

A dedicated community website to competitive L4D and L4D2, ran by the community, for the community. L4DNation supports all continents of play and focuses on bringing together the community as a whole to a central hub of information.