Community Forums Today's Posts     Member List     Archive    
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2004
    Location
    USA
    Posts
    2

    Start stop script for TeamSpeak daemon (init)

    The script to handle starting and stopping of TeamSpeak that comes with the latest versions has a lot of problems. Namely, it doesn't work with the init system on Linux and therefore won't start TS when your system is rebooted. And the restart option doesn't work correctly.

    This version fixes those issues and others and cleans up some of the code.

    This script should go in "/etc/init.d/tss". Make links in "/etc/rc3.d" like "ln -s ../../init.d/tss S85tss" and "ln -s ../../init.d/tss K15tss". Make sure to change the config section. You should install TeamSpeak to run under some user - NOT ROOT - like voice or tss or something. Change "USER" to that username. Change "DIR" to the path to your TeamSpeak directory.

    Now do "service start/stop/restart tss" (pick one of start, stop, or restart) as root or a sudo priviledged user. This is how it *should* be.

    Cheers.

    Derek "Cybernaut"
    www.DigitalNines.com - Web Hosting, Game Hosting, etc.

    Code:
    #! /bin/bash
    # Copyright (c) 2004 TeamSpeak team   All rights reserved.
    #
    # Author: pwk.linuxfan 2004
    # Modified by Derek "Cybernaut" Jackson - www.DigitalNines.com
    #
    # chkconfig: 345 85 15
    # description: Runs and kills TeamSpeak Voice server at boot time and shutdown.            
    # Source function library.
    #. /etc/rc.d/init.d/functions
    
    # START OF CONFIG SECTION
    # WARNING ! For security reasons we advise: DO NOT RUN THE SERVER AS ROOT
    USER=voice
    DIR=/home/voice/tss2_rc2
    # END OF CONFIG SECTION
    
    # See how we were called.
    case "$1" in
            start)
                    if [ -e $DIR/tsserver2.pid ]; then
                            echo "tsserver2.pid already exists...server already started ?";
                            echo "If you are sure the server is not running, delete tsserver2.pid"
                            exit 1
                    else
                            if [ "$UID" = "0" ]; then
                                    for c in $(seq 1 10); do
                                            echo -n "!"
                                            sleep 1
                                    done
                                    echo !
                            fi
                            echo "Starting the TeamSpeak Voice server..."
                            if [ -e $DIR/server_linux ]; then
                                    if [ ! -x $DIR/server_linux ]; then
                                            echo "server_linux is not executable; trying to set it."
                                            chmod u+x $DIR/server_linux
                                    fi
                                    if [ -x $DIR/server_linux ]; then
                                            WD=`pwd`
                                            cd $DIR
                                            su $USER -c "$DIR/server_linux -PID=tsserver2.pid" &
                                            cd $WD
                                    else
                                            echo "server_linux is not executable; fix this."
                                            exit 4
                                    fi
                            else
                                    echo "Couldnt find server_linux."
                                    exit 5
                            fi
                    fi
            ;;
        stop)
                    if [ -e $DIR/tsserver2.pid ]; then
                            echo -n "Stopping the TeamSpeak Voice server..."
                            if ( kill -TERM `cat $DIR/tsserver2.pid` ); then
                                    for c in $(seq 1 300); do
                                            if [ -e $DIR/tsserver2.pid ]; then
                                                    echo -n "."
                                                    sleep 1
                                            fi
                                    done
                            fi
                            if [ -e $DIR/tsserver2.pid ]; then
                                    echo "server does not shutdown cleanly - killing"
                                    kill -KILL `cat $DIR/tsserver2.pid`
                                    rm $DIR/tsserver2.pid
                                    sleep 5
                            else
                                    echo "done"
                            fi
                    else
                            echo "tsserver2.pid is missing; is the server stopped already?"
                            #exit 7 - Should not be here as doesn't allow restart if server is already stopped.
                    fi
            ;;
            restart)
                    $0 stop && $0 start || exit 1
            ;;
            status)
                    if [ -e $DIR/tsserver2.pid ]; then
                            echo "The TeamSpeak Voice server is running."
                            exit 0
                    else
                            echo "The TeamSpeak Voice server is stopped."
                            exit 3
                    fi
            ;;
            passwords)
                    if [ -e $DIR/server.log ]; then
                            date=$(cat $DIR/server.log | grep "admin account info: username: admin" | tail -n 1 | sed "s/^\([0-9]\+-[0-9]\+-[0-9]\+ [0-9]\+:[0-9]\+:[0-9]\+\).*$/\1/")
                            spass=$(cat $DIR/server.log | grep "superadmin account info: username: superadmin" | tail -n 1 | sed "s/^.*username: superadmin password: \([a-z0-9]\+\).*$/\1/")
                            pass=$(cat $DIR/server.log | grep "admin account info: username: admin" | tail -n 1 | sed "s/^.*username: admin password: \([a-z0-9]\+\).*$/\1/")
                            echo "Following passwords were generated on $date"
                            echo "superadmin = \"$spass\""
                            echo "admin      = \"$pass\""
                    else
                            echo "server.log not found; maybe the server has not been started yet?" 
                            exit 1
                    fi
            ;;
            *)
                    echo "Usage: $0 {start|stop|restart|status|passwords}"
                    exit 2
    esac
    exit 0
    Edit: not a suggestion, moved.
    Last edited by Peter; 13-11-2004 at 23:18.

  2. #2
    Join Date
    Sep 2002
    Location
    Milano, Italy
    Posts
    7
    Nice one, Cybernaut; only the double quotes in the activation command didn't work for me... anyways, great job. Perhaps it's also worth to mention that you can register the script with 'chkconfig --add scriptname' on FC/RH, so that you can manage TS activation/deactivation with the Services graphical interface. Now it runs harmlessly as 'nobody' on my box.... thanks to you

  3. #3
    Join Date
    Jun 2004
    Location
    VA
    Posts
    13
    Thanks dude...I kinda got a headache trying to find out why mine wasn't working.

    Thanks.

    Workng Mandrake 10.....waddatah!!

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Need help on a start stop script.
    By Jere in forum [TeamSpeak 2] Server Support
    Replies: 1
    Last Post: 17-03-2004, 06:08
  2. [debian]Start/stop script
    By muldereric in forum [TeamSpeak 2] Server Support
    Replies: 2
    Last Post: 03-02-2004, 12:12
  3. Teamspeak RC2 daemon fails to start
    By Toff in forum [TeamSpeak 2] Server Support
    Replies: 7
    Last Post: 03-03-2003, 01:35
  4. Cant start -> "Error stating daemon. Aborted"
    By swafnir in forum [TeamSpeak 2] Server Support
    Replies: 2
    Last Post: 17-09-2002, 18:15
  5. Start script..
    By NitroSniper in forum [TeamSpeak 2] Addons & Scripts
    Replies: 3
    Last Post: 27-08-2002, 07:12

Posting Permissions

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