#!/bin/bash
#Teamspeak 3 startup script
##update-rc.d teamspeak3 defaults
### BEGIN INIT INFO
# Provides: Teamspeak3
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts/stops the Teamspeak3 daemon
### END INIT INFO
PATH=/sbin:/bin:/usr/sbin:/usr/bin:$DIR
#Server options
NAME="TeamSpeak 3 Server"
DESC="tss3"
DIR="/home/mpcom/teamspeak3" # pfad zum Teamspeak3
BIN="ts3server_linux_amd64" # name TS3server bin ; hier die 64bit
PIDFILE="/home/mpcom/teamspeak3/tss3.pid" # Pfad für fuer das pid.file
PARAMS="inifile=ts3server.ini"
USER="mpcom" # User, unter dem TeamSpeak3 ausgeführt wird - DO NOT USE root
GROUP="mpcom" # Gruppe für Teamspeak3 - DO NOT USE root
### Do not edit anything below this line ###
set -e
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:."
. /lib/lsb/init-functions
if [ ! -d "$DIR" ]; then
log_failure_msg "Directory does not exist!"
exit 0
fi
if [ ! -e "$DIR/$BIN" ]; then
log_failure_msg "$BIN does not exist!"
exit 0
fi
if [ ! -x "$DIR/$BIN" ]; then
log_failure_msg "$BIN not executable!"
exit 0
fi
if [ -z "$USER" ]; then
log_failure_msg "Username is not set!"
exit 0
fi
if [ -z "$GROUP" ]; then
log_failure_msg "GROUP is not set!"
exit 0
fi
TEST=`ps ax | grep $BIN | grep -v grep | wc -l`
start()
{
if [ $TEST = 1 ]; then
log_begin_msg "$NAME already running with Pid: `tail $PIDFILE`"
else
export LD_LIBRARY_PATH="${LIBRARYPATH}:${LD_LIBRARY_PATH}"
log_progress_msg "Starting $NAME"
start-stop-daemon --start --chdir $DIR --exec $DIR/$BIN --startas $BIN --make-pidfile --pidfile $PIDFILE --user $USER --group $GROUP --chuid $USER:$GROUP --background -- $PARAMS
chown $USER:$GROUP $PIDFILE
log_end_msg 0
fi
}
stop()
{
if [ ! $TEST = 1 ]; then
log_begin_msg "$NAME not running!"
else
log_progress_msg "Stopping $NAME"
start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE --user $USER --exec $DIR/$BIN
rm -rf $PIDFILE
log_end_msg 0
fi
}
restart()
{
echo "Stopping $NAME"
start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE --user $USER --exec $DIR/$BIN
rm -rf $PIDFILE
sleep 1
echo ...
echo "Starting $NAME"
start-stop-daemon --start --chdir $DIR --exec $DIR/$BIN --startas $BIN --make-pidfile --pidfile $PIDFILE --user $USER --group $GROUP --chuid $USER:$GROUP --background -- $PARAMS
chown $USER:$GROUP $PIDFILE
}
status()
{
if [ $TEST = 1 ]; then
echo "$NAME running with Pid: `tail $PIDFILE`"
else
echo "$NAME not running"
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart|force-reload)
restart
;;
status)
status
;;
*)
log_success_msg "Usage: $0 {start|stop|restart|force-reload|status}" >&2
exit 1
;;
esac
exit 0