Community Forums Today's Posts     Member List     Archive    
Results 1 to 8 of 8
  1. #1
    Join Date
    May 2011
    Posts
    5

    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; 04-05-2011 at 01:40.

  2. #2
    Join Date
    Jan 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
    Jul 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
    Jan 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
    Jan 2010
    Location
    Germany
    Posts
    2,039
    Nope needs to be the full path.

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

    I recommend!
    Last edited by LS_ARRoW; 15-07-2012 at 11:22.

  7. #7
    Join Date
    Jun 2011
    Location
    Russian Federation
    Posts
    208
    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
    Jun 2009
    Location
    Australia
    Posts
    11
    AFAIK another script isn't necessary and you can just cron the start script itself?

    Please correct me if I am wrong.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 1
    Last Post: 07-04-2010, 14:34
  2. Auto start without root privileges
    By chx86 in forum [TeamSpeak 2] Server Support
    Replies: 2
    Last Post: 15-07-2007, 10:22
  3. Auf den Root laufenden server mit dem root draufconnecten?
    By XpLoDeR24 in forum [TeamSpeak 2] Server Support
    Replies: 10
    Last Post: 20-05-2006, 11:20
  4. Err with start under not root user
    By Sandr in forum [TeamSpeak 2] Server Support
    Replies: 1
    Last Post: 13-02-2005, 03:48
  5. Startup script NOT AS ROOT
    By Heavenstrash in forum [TeamSpeak 2] Server Support
    Replies: 10
    Last Post: 05-07-2003, 05:45

Posting Permissions

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