Results 1 to 10 of 10

Thread: Linux Autostart scripts

  1. #1
    Administrator JoTo's Avatar
    Join Date
    May 2010
    Location
    www.scapp.net
    Posts
    1,952

    Default Linux Autostart scripts

    If you own a game server running on a linux box and you are in need of a auto restart function for your game server these scripts may be of use for you:

    create the files "gsload.sh" and "gs.sh" with any editor (notepad or vi) and copy paste the following code:

    gsload.sh
    Code:
     
    #!/bin/bash
    NAME=gs1_port12205
    DESC="Medal of Honor v1.12"
    DIR=/home/gs1
    SCRIPT=gs.sh
    DAEMON=$DIR/$SCRIPT
    
    case "$1" in
    start)
    if [[ `screen -ls |grep $NAME` ]]
    then
    echo -n "Stopping $DESC: $NAME "
    kill `screen -ls |grep $NAME |awk -F . '{print $1}'|awk '{print $1}'`
    echo " ... Server stopped ... Start will be executed"
    else
    echo ""
    fi
    echo "Starting $DESC: $NAME"
    cd $DIR
    screen -d -m -S $NAME $DAEMON
    ;;
    
    stop)
    
    if [[ `screen -ls |grep $NAME` ]]
    then
    echo -n "Stopping $DESC: $NAME"
    kill `screen -ls |grep $NAME |awk -F . '{print $1}'|awk '{print $1}'`
    echo " ... Server stopped."
    else
    echo "Found no server with PID -- $DESC --  "
    fi
    ;;
    
    restart)
    if [[ `screen -ls |grep $NAME` ]]
    then
    echo -n "Stopping $DESC: $NAME "
    kill `screen -ls |grep $NAME |awk -F . '{print $1}'|awk '{print $1}'`
    echo " ... Server stopped ... Start will be executed"
    else
    echo "Found no server with PID -- $DESC -- ... Start couldn't executed"
    fi
    
    echo -n "Starting $DESC: $NAME"
    cd $DIR
    screen -d -m -S $NAME $DAEMON
    ;;
    
    *)
    echo "Usage: $0 Parameter {start|stop|restart}"
    exit 1
    ;;
    esac
    
    exit 0
    gs.sh
    Code:
    #! /bin/bash
    
    echo "Launching Mohaa Server Port 12205"
    
    cd server
    
    while true
    do
    
       ./mohaa_lnxded "+set dedicated 1 +set net_port 12205 +exec server.cfg"
    
       sleep 2
    
    done
    Now you need to edit some values so that it match your server layout:

    in "gsload.sh" edit these values:

    NAME=gs1_port12205 <==== change the port here to the port your server listens to, if you are running multiple servers with these scripts its important that the name is unique
    DIR=/home/gs1 <==== change to the root directory

    In this example "gs1" is the root directory where the files "gsload.sh" and "gs.sh" are located. The server itself is located in a subdirectory of the root directory called "server"

    change accordingly in "gs.sh" these values:

    echo "Launching Mohaa Server Port 12205" <==== change the port here to the port your server listens to
    cd server <==== change to the subdirectory your server is located in
    ./mohaa_lnxded "+set dedicated 1 +set net_port 12205 +exec server.cfg" <====== change the port here and the arguments to your needs here


    To initially start the server type:

    Code:
    ./gsload.sh start
    for stopping the server type:

    Code:
    ./gsload.sh stop
    for restarting the server type:

    Code:
    ./gsload.sh restart

  2. #2

    Default

    Hi Joto. How would one backup the log and save it in date format? Would this work?

    # Get Date
    $ NOW=$(date +"%m-%d-%H-%M")

    # save last copy of log file
    cp ~/.mohaa/main/qconsole.log ~/.mohaa/main/logs/$NOW.log

    # truncate log
    > ~/.mohaa/main/qconsole.log

    # compress backup log
    gzip ~/.mohaa/main/logs/log-$NOW.log

    I don't have linux, but was going to give this to my server company.

  3. #3

    Default

    Thx JoTo, finaly i got that for my Linux
    Will place it on. And yes would be nice if we can save logs. Can we do that on Linux?
    [IMG]http://i253.photobucket.com/albums/hh77/TDogg1100/pee1.gif[/IMG]

  4. #4
    Administrator JoTo's Avatar
    Join Date
    May 2010
    Location
    www.scapp.net
    Posts
    1,952

    Default

    I will test it and come back to you.

  5. #5

    Default

    I submitted that to my server company, and they got it working, but don't know if they used what I sent them or not, lol.

  6. #6

    Default

    I'm using ubuntu 18.4 and not working for me
    Any idea plz?

  7. #7

    Default

    Quote Originally Posted by Ahmed2020 View Post
    I'm using ubuntu 18.4 and not working for me
    Any idea plz?
    Please post your problem on a new thread and shows a log or screenshot showing is not working and the steps you have done when you have try to make him work.

    Thanks

  8. #8

    Default

    evry thing done as in the post and im changed my files names to be the same in the post and this the code
    root@instance-1:~# cd /home/gs1
    root@instance-1:/home/gs1# ./gsload.sh start
    bash: ./gsload.sh: /bin/bash^M: bad interpreter: No such file or directory
    root@instance-1:/home/gs1#

    any suggestions?

  9. #9

    Default

    i writed a new post but not appear why

  10. #10

    Default

    Solved thank you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •