[nSLUG] Startup scripts

Scott Walsh scottwalsh at gmail.com
Sat Jan 6 04:14:04 AST 2007

Hi David,

I'm sure that the following were probably suggested in #debian, but just in
case they were not...

1. Check your runlevel with the 'runlevel' command, if you haven't used
init, or telinit you will see "N 1-5" where the second is your runlevel. My
Etch(you said stable, so I'm assuming Sarge, even though Etch is frozen, it
isn't the stable yet) install defaulted to rc2(I had incorrectly assumed rc3
initially). If you aren't seeing "N 2" after a reboot, that is your culprit,
as your rc2 init's are not being executed.

2. I've has su username -c behave unxpectedly in the past when not quoting
the actual command that is going to be executed as the user, but you being
able to use the script and bring up the server indicates that it's working
for you. I'd personally go with something more like:

su tsd -c "/opt/tss2_rc2/teamspeak2-server_startupscript $1"

wrapped in something like:

#! /bin/sh
case "$1" in
        su tsd -c "/opt/tss2_rc2/teamspeak2-server_startupscript start"
        su tsd -c "/opt/tss2_rc2/teamspeak2-server_startupscript restart"
       su tsd -c "/opt/tss2_rc2/teamspeak2-server_startupscript stop"
        echo "Usage: $0 start|stop|restart" >&2
        exit 1

3. You could just specify su tsd -c
"/opt/tss2_rc2/teamspeak2-server_startupscript start"  in it's own little
script and add it to all of your runlevels using 'update-rc.d', I wouldn't
really recommend this due to the PID locking in the actual server startup
though, because you'll end up with a PID file on restart and the server will
fail to start. This method is more useful for maintaining things like
firewall rules than this application.

I'm tired right now, so I'll use that as my excuse if I have glaring errors
in the above suggestions.




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

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

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/*


#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

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

case "$1" in
               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
                       if [ "$UID" = "0" ]; then
                               echo WARNING ! For security reasons we
                               for c in $(seq 1 10); do
                                       echo -n "!"
                                       sleep 1
                               echo !
                       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
                               if [ -x server_linux ]; then
                                       ./server_linux -PID=tsserver2.pid
                                       echo "server_linux is not
executable, fix this"
                                       exit 4
                               echo "Couldnt find server_linux"
                               exit 5
               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
                       if [ -e tsserver2.pid ]; then
                               echo "server does not shutdown cleanly
- killing"
                               kill -KILL `cat tsserver2.pid`
                               rm tsserver2.pid
                               sleep 5
                               echo "done"
                       echo "tsserver2.pid is missing, no started server ?"
                       exit 7
               $0 stop && $0 start || exit 1
               if [ -e tsserver2.pid ]; then
                       echo "the server seems to be running"
                       exit 0
                       echo "the server seems to be stopped"
                       exit 3
               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]\+
                       spass=$(cat server.log | grep "superadmin
account info: username: superadmin" | tail -n 1 | sed "s/^.*username:
superadmin password:
                       pass=$(cat server.log | grep "admin account
info: username: admin" | tail -n 1 | sed "s/^.*username: admin
password: \([a-z0-9]\+\).*
                       echo "Following passwords were generated on $date"
                       echo "superadmin = \"$spass\""
                       echo "admin      = \"$pass\""
                       echo "server.log not found, maybe you did not
start the server yet ?"
                       exit 1
               echo "Usage: $0 {start|stop|restart|status|passwords}"
               exit 2
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

/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

nSLUG mailing list
nSLUG at nslug.ns.ca

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://nslug.ns.ca/mailman/private/nslug/attachments/20070106/93cfa401/attachment-0001.html>

More information about the nSLUG mailing list