Forum

Results 1 to 9 of 9
  1. #1
    Join Date
    May 2011
    Posts
    4

    Very simple server auto start method and crash restart script (root & non-root)

    Here is a simple script I wrote to automatically start a TS3 server on boot and auto restart after a crash. Tested with CentOS 5.x and Ubuntu 10 & 11, but should work with most distros.

    For x86:

    Code:
    #!/bin/bash
    
    TEAMSPEAK=`ps ax | grep ts3server_linux_x86 | grep -v grep | wc -l`
    
    if [ $TEAMSPEAK -eq 1 ]
    then
    exit
    else
    cd /path/to/teamspeak ; ./ts3server_startscript.sh start
    fi
    For x64:

    Code:
    #!/bin/bash
    
    TEAMSPEAK=`ps ax | grep ts3server_linux_amd64 | grep -v grep | wc -l`
    
    if [ $TEAMSPEAK -eq 1 ]
    then
    exit
    else
    cd /path/to/teamspeak ; ./ts3server_startscript.sh start
    fi
    Change "/path/to/teamspeak" to your actual TeamSpeak directory.

    Script is also included as an attachment at the bottom, simply put it in a directory on your server (such as the teamspeak directory).

    Login as the user you wish to run this as, this does not have to be root. In crontab add a line such as this:

    Code:
    */2 * * * * sh /path/to/script/script.sh
    Where */2 is 2 minutes, change to */5 for 5 minutes.. and so on. This is after how many minutes to check if the server is running, and if not to attempt to start it.

    This works best when you have an additional line in crontab like:

    Code:
    @reboot cd /path/to/teamspeak ; ./ts3server_startscript.sh start
    Again changing the path. This will start the server automatically after boot (otherwise you would have to wait for the script to run after boot). TeamSpeak server will then run as the same user who added the crontab entries.

    A thing to note, you may have to comment the script line in crontab with # when updating the TeamSpeak server so it doesn't automatically start it. Then uncomment it again after. There is also a limitation, if the server won't start due to error it will keep attempting to start it.

    Disclaimer: Though this script was created by me, I accept no responsibility for data loss or damage by the use of the script though it should be perfectly safe to use.

    Attached file is for x86 server version, for x64 change line 3 from "ts3server_linux_x86" to "ts3server_linux_amd64".
    Attached Files Attached Files
    Last edited by Arandas; September 27th, 2013 at 10:41 PM.

  2. #2
    Join Date
    January 2010
    Location
    The US
    Posts
    10
    I know, I'm practicing thread necromancy, since no one has posted to this thread in more than 2 months, but I just wanted to tell the OP Thank you. Thanks a ton. You solved a problem that stopped me from trying to run my own TS3 server 2 years ago. and you explained it nicely with an attached cron job I was actually able to use as well. Thank you so very much. Someone sticky this please.

  3. #3
    Join Date
    July 2011
    Location
    Scotland
    Posts
    2

    Thumbs up Perfect simple auto start script

    This is perfect, well explained and very easy to implement. Thanks for the file too.

    I have been looking for months for this. Thank you so much.

    I agree this definately deserves a sticky.

  4. #4
    Join Date
    January 2012
    Posts
    9
    This looks like exactly what im looking for but im running in to an issue, if i had my script.sh stored in my Teamspeak Directory at /home/teamspeakserver would the path to teamspeak be /home/teamspeakserver/teamspeak3-server_linux-x86 or just /teamspeak3-server_linux-x86 ?

  5. #5
    Join Date
    January 2010
    Location
    Germany
    Posts
    2,029
    Nope needs to be the full path.

  6. #6
    Join Date
    June 2012
    Location
    Poland
    Posts
    15
    Thanks Arandas this is 100% working
    for boot system, and when TeamSpeak is stopped just worked.

    I recommend!
    Last edited by LS_ARRoW; July 15th, 2012 at 11:22 AM.

  7. #7
    Join Date
    June 2011
    Location
    Russian Federation
    Posts
    204
    how do I:
    Code:
    #!/bin/bash
    
    TEAMSPEAK=`ps ax | grep ts3server_linux_x86 | grep -v grep | wc -l`
    
    if [ $TEAMSPEAK -eq 1 ]
    then
    exit
    else
    cd /home/archi/teamspeak3-server_linux-x86 ; ./ts3server_startscript.sh start
    crontab:
    Code:
    */2 * * * * cd ~/scripts && sh crash.sh
    as a result of the logs, I:
    Code:
    Jul 16 10:08:01 ts3 /USR/SBIN/CRON[5721]: (CRON) error (grandchild #5725 failed with exit status 1)
    Jul 16 10:08:01 ts3 /USR/SBIN/CRON[5721]: (CRON) info (No MTA installed, discarding output)
    after commenting in the crontab "#" of a script error no!

    Question! what's the problem?

  8. #8
    Join Date
    June 2009
    Location
    Australia
    Posts
    14
    AFAIK another script isn't necessary and you can just cron the start script itself?

    Please correct me if I am wrong.

  9. #9
    Join Date
    March 2015
    Posts
    1

    DEBIAN 7 check every XX sec if the server run and auto restart after crash

    everything is in the title, does it possible to check every "xx" seconds if my server run and if not restart it (and also delete the .pid file) ? thanks
    Last edited by dante696; March 9th, 2015 at 11:07 PM. Reason: merged

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 7
    Last Post: August 23rd, 2013, 08:06 PM
  2. Replies: 0
    Last Post: May 4th, 2011, 01:22 AM
  3. Replies: 1
    Last Post: April 7th, 2010, 02:34 PM

Tags for this Thread

Posting Permissions

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