goofdad
09-06-2006, 19:41
Kernel version: 2.6.16-1.2108_FC4
I used my knowledge of the Fedora startup system, combined with this thread http://forum.goteamspeak.com/showthread.php?t=29684 to create a Fedora friendly startup script to put into the init.d directory. Save this code as /etc/init.d/teamspeak
This script assumes the server is to be run as user teamspeak. You will need to create that user and install the ts server into ~teamspeak/tss2_rc2 (or change the variables at the top of the script).
This script replaces the teamspeak2-server_startscript, rather than calling it as the original thread did. This is because much of what the two scripts did was redundant.
After placing this script into /etc/init.d, simply run chkconfig --add teamspeak to get it to start running automatically, and service teamspeak start to start it now.
#!/bin/bash
#
# chkconfig: 2345 95 15
# description: Starts and stops Team Speak Server
#
# for an explanation of the whole "/var/lock/subsys" thing, see
# http://www.redhat.com/magazine/008jun05/departments/tips_tricks/
# Source function library.
. /etc/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
prog=$"TeamSpeak server"
USER=teamspeak
DAEMONDIR=/home/${USER}/tss2_rc2/
SERVER=server_linux
SCRIPTNAME=/etc/init.d/teamspeak
DAEMON=${DAEMONDIR}${SERVER}
PIDFILE=${DAEMONDIR}teamspeakd.pid
TSstatus() {
local pid
# First try "pidof"
pid=`pidof -o $$ -o $PPID -o %PPID -x ${SERVER}`
if [ -n "$pid" ]; then
echo $"${prog} (pid $pid) is running..."
return 0
fi
# Next try pid file
if [ -f ${PIDFILE} ] ; then
read pid < ${PIDFILE}
if [ -n "$pid" ]; then
echo $"${prog} appears to be dead but pid file exists"
return 1
fi
fi
# See if /var/lock/subsys/teamspeak exists
if [ -f /var/lock/subsys/teamspeak ]; then
echo $"${SERVER} dead but subsys locked"
return 2
fi
echo $"${SERVER} is stopped"
return 3
}
start() {
local pid
echo -n $"Starting $prog: "
ulimit -S -c 0 >/dev/null 2>&1
RETVAL=0
if [ -e ${PIDFILE} ]; then
read pid < ${PIDFILE}
if `kill -CHLD $pid > /dev/null 2>&1`; then
echo "${prog} is already running"
exit 0
fi
# if it's not running...
echo "Stale ${PIDFILE}, erasing"
rm -f ${PIDFILE}
fi
runuser -l ${USER} -c "cd ${DAEMONDIR} && setarch i386 ./${SERVER} -PID=${PIDFILE} > /dev/null 2>&1"
RETVAL=$?
[ "$RETVAL" -eq 0 ] && success $"teamspeak startup" || \
failure $"teamspeak start"
echo
[ "$RETVAL" -eq 0 ] && touch /var/lock/subsys/teamspeak
}
stop() {
local pid
echo -n $"Shutting down $prog: "
RETVAL=0
if [ -e ${PIDFILE} ]; then
read pid < ${PIDFILE}
else
echo "${prog} does not appear to be running. ${PIDFILE} does not exist"
RETVAL=7
return
fi
if ( kill -TERM $pid ); then
for c in $(seq 1 300); do
if [ -e ${PIDFILE} ]; then
echo -n "."
sleep 1
fi
done
fi
if [ -e ${PIDFILE} ]; then
echo "server did not shutdown cleanly -- killing"
kill -KILL $pid
rm ${PIDFILE}
sleep 5
fi
[ "$RETVAL" -eq 0 ] && success $"vncserver shutdown" || \
failure $"vncserver shutdown"
echo
[ "$RETVAL" -eq 0 ] && rm -f /var/lock/subsys/teamspeak
}
passwords() {
if [ -e ${DAEMONDIR}server.log ]; then
date=$(cat ${DAEMONDIR}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 ${DAEMONDIR}server.log | grep "superadmin account info: username: superadmin" | tail -n 1 | sed "s/^.*username: superadmin password: \([a-z0-9]\+\).*$/\1/")
pass=$(cat ${DAEMONDIR}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 "${DAEMONDIR}server.log not found, maybe you did not start the server yet ?"
exit 1
fi
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
stop
sleep 3
start
;;
condrestart)
if [ -f /var/lock/subsys/teamspeak ]; then
stop
sleep 3
start
fi
;;
status)
TSstatus
;;
passwords)
passwords
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart|status|passwords}"
exit 1
esac
I used my knowledge of the Fedora startup system, combined with this thread http://forum.goteamspeak.com/showthread.php?t=29684 to create a Fedora friendly startup script to put into the init.d directory. Save this code as /etc/init.d/teamspeak
This script assumes the server is to be run as user teamspeak. You will need to create that user and install the ts server into ~teamspeak/tss2_rc2 (or change the variables at the top of the script).
This script replaces the teamspeak2-server_startscript, rather than calling it as the original thread did. This is because much of what the two scripts did was redundant.
After placing this script into /etc/init.d, simply run chkconfig --add teamspeak to get it to start running automatically, and service teamspeak start to start it now.
#!/bin/bash
#
# chkconfig: 2345 95 15
# description: Starts and stops Team Speak Server
#
# for an explanation of the whole "/var/lock/subsys" thing, see
# http://www.redhat.com/magazine/008jun05/departments/tips_tricks/
# Source function library.
. /etc/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
prog=$"TeamSpeak server"
USER=teamspeak
DAEMONDIR=/home/${USER}/tss2_rc2/
SERVER=server_linux
SCRIPTNAME=/etc/init.d/teamspeak
DAEMON=${DAEMONDIR}${SERVER}
PIDFILE=${DAEMONDIR}teamspeakd.pid
TSstatus() {
local pid
# First try "pidof"
pid=`pidof -o $$ -o $PPID -o %PPID -x ${SERVER}`
if [ -n "$pid" ]; then
echo $"${prog} (pid $pid) is running..."
return 0
fi
# Next try pid file
if [ -f ${PIDFILE} ] ; then
read pid < ${PIDFILE}
if [ -n "$pid" ]; then
echo $"${prog} appears to be dead but pid file exists"
return 1
fi
fi
# See if /var/lock/subsys/teamspeak exists
if [ -f /var/lock/subsys/teamspeak ]; then
echo $"${SERVER} dead but subsys locked"
return 2
fi
echo $"${SERVER} is stopped"
return 3
}
start() {
local pid
echo -n $"Starting $prog: "
ulimit -S -c 0 >/dev/null 2>&1
RETVAL=0
if [ -e ${PIDFILE} ]; then
read pid < ${PIDFILE}
if `kill -CHLD $pid > /dev/null 2>&1`; then
echo "${prog} is already running"
exit 0
fi
# if it's not running...
echo "Stale ${PIDFILE}, erasing"
rm -f ${PIDFILE}
fi
runuser -l ${USER} -c "cd ${DAEMONDIR} && setarch i386 ./${SERVER} -PID=${PIDFILE} > /dev/null 2>&1"
RETVAL=$?
[ "$RETVAL" -eq 0 ] && success $"teamspeak startup" || \
failure $"teamspeak start"
echo
[ "$RETVAL" -eq 0 ] && touch /var/lock/subsys/teamspeak
}
stop() {
local pid
echo -n $"Shutting down $prog: "
RETVAL=0
if [ -e ${PIDFILE} ]; then
read pid < ${PIDFILE}
else
echo "${prog} does not appear to be running. ${PIDFILE} does not exist"
RETVAL=7
return
fi
if ( kill -TERM $pid ); then
for c in $(seq 1 300); do
if [ -e ${PIDFILE} ]; then
echo -n "."
sleep 1
fi
done
fi
if [ -e ${PIDFILE} ]; then
echo "server did not shutdown cleanly -- killing"
kill -KILL $pid
rm ${PIDFILE}
sleep 5
fi
[ "$RETVAL" -eq 0 ] && success $"vncserver shutdown" || \
failure $"vncserver shutdown"
echo
[ "$RETVAL" -eq 0 ] && rm -f /var/lock/subsys/teamspeak
}
passwords() {
if [ -e ${DAEMONDIR}server.log ]; then
date=$(cat ${DAEMONDIR}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 ${DAEMONDIR}server.log | grep "superadmin account info: username: superadmin" | tail -n 1 | sed "s/^.*username: superadmin password: \([a-z0-9]\+\).*$/\1/")
pass=$(cat ${DAEMONDIR}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 "${DAEMONDIR}server.log not found, maybe you did not start the server yet ?"
exit 1
fi
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
stop
sleep 3
start
;;
condrestart)
if [ -f /var/lock/subsys/teamspeak ]; then
stop
sleep 3
start
fi
;;
status)
TSstatus
;;
passwords)
passwords
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart|status|passwords}"
exit 1
esac