[nSLUG] Startup scripts

David Payne dapayne12 at gmail.com
Sat Jan 6 01:48:52 AST 2007


Hi,

Been a while since I posted to this group.  I am not new to Linux but
I am new to startup scripts and scripts in general.  I will show you
everything I have then I will explain my problem at the bottom of the
message.

I am running the newest release of Debian stable.  I did a net install
yesterday.

I installed a Teamspeak server in /opt/tss2_rc2.  Then I did chown
tsd.root -R tss2_rc2.  tsd is a user I created just for the ts server.
 Teamspeak comes with a startup script
/opt/tss2_rc2/teamspeak2-server_startupscript that takes a bunch of
options, including start and stop.

This is a script I created, I placed it in /etc/init.d/

#!/bin/sh

#This line is just here for debugging:
echo Running ts server with this command: $0 $1

cd /opt/tss2_rc2
su tsd -m -c ./teamspeak2-server_startupscript $1

#end of script

And this is the script located at
/opt/tss2_rc2/teamspeak2-server_startupscript.  Before you read this
and try to debug it, you might want to skip past it, I don't think
there is a problem with this script.  Read what I have to say after
it.

#
#! /bin/bash
#
# Copyright (c) 2004 TeamSpeak team   All rights reserved.
#
#
#
# Author: pwk.linuxfan 2004
#
#
#

case "$1" in
        start)
                if [ -e 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
                                echo WARNING ! For security reasons we
advise: DO NOT RUN THE SERVER AS ROOT
                                for c in $(seq 1 10); do
                                        echo -n "!"
                                        sleep 1
                                done
                                echo !
                        fi
                        echo "starting the teamspeak2 server"
                        if [ -e server_linux ]; then
                                if [ ! -x server_linux ]; then
                                        echo "server_linux is not
executable, trying to set it"
                                        chmod u+x server_linux
                                fi
                                if [ -x server_linux ]; then
                                        ./server_linux -PID=tsserver2.pid
                                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 tsserver2.pid ]; then
                        echo -n "stopping the teamspeak2 server"
                        if ( kill -TERM `cat tsserver2.pid` ); then
                                for c in $(seq 1 300); do
                                        if [ -e tsserver2.pid ]; then
                                                echo -n "."
                                                sleep 1
                                        fi
                                done
                        fi
                        if [ -e tsserver2.pid ]; then
                                echo "server does not shutdown cleanly
- killing"
                                kill -KILL `cat tsserver2.pid`
                                rm tsserver2.pid
                                sleep 5
                        else
                                echo "done"
                        fi
                else
                        echo "tsserver2.pid is missing, no started server ?"
                        exit 7
                fi
        ;;
        restart)
                $0 stop && $0 start || exit 1
        ;;
        status)
                if [ -e tsserver2.pid ]; then
                        echo "the server seems to be running"
                        exit 0
                else
                        echo "the server seems to be stopped"
                        exit 3
                fi
        ;;
        passwords)
                if [ -e server.log ]; then
                        date=$(cat 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 server.log | grep "superadmin
account info: username: superadmin" | tail -n 1 | sed "s/^.*username:
superadmin password:
\([a-z0-9]\+\).*$/\1/")
                        pass=$(cat 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 you did not
start the server yet ?"
                        exit 1
                fi
        ;;
        *)
                echo "Usage: $0 {start|stop|restart|status|passwords}"
                exit 2
esac
exit 0

#End of the script

During startup I see the following line:

Running ts server with this command: /etc/rc2.d/S20tsscript start

The ts server does not start up.  But once I log in as root (the root
account executes the script) and execute the script by typing the
following:

/etc/rc2.d/S20tsscript start

or the following line:

/etc/init.d/tssscript start (it doesn't make a difference what one I use)

I get the following output and the ts server comes up:

Running the ts server with this command: /etc/init.d/tsscript start
starting the teamspeak2 server

I investigated further by adding a -x to the top of each script as
someone suggested in #debian on freenode and this is what I found that
at startup the first script is executed but the second isn't.  Once I
execute the first script after the system boots both scripts gets
executed.  The problem seems to be on the line "su tsd -m -c
./teamspeak2-server_startupscript $1", it doesn't work at startup but
it does work after startup.

But no one in #debian seems to know what is wrong and I don't know
what is wrong.

I'm sorry if I gave way too much information, I just wanted to make
sure you got the full story, but if someone knows how this can be
fixed the help would be greatly appreciated.

David Payne

!DSPAM:459f39bf133258412246093!




More information about the nSLUG mailing list