Created
September 8, 2017 09:42
-
-
Save Synergyst/82ec520bd31238d2ba98187cf40ca385 to your computer and use it in GitHub Desktop.
A TS3AudioBot daemon script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Copyright (c) 2010 TeamSpeak Systems GmbH (edited by Pawkow for use with TS3AudioBot: https://github.com/Splamy/TS3AudioBot) | |
# All rights reserved | |
# Drop this script into the folder with the TS3AudioBot.exe binary and run! :D | |
COMMANDLINE_PARAMETERS="${2}" #add any command line parameters you want to pass here | |
D1=$(readlink -f "$0") | |
BINARYPATH="$(dirname "${D1}")" | |
cd "${BINARYPATH}" | |
LIBRARYPATH="$(pwd)" | |
if [ -e TS3AudioBot.exe ]; then | |
if [ -z "`uname | grep Linux`" -o ! -z "`uname -m | grep 64`" ]; then | |
echo "Do you have the right TS3AudioBot package for your system? You have: `uname` `uname -m`, not Linux i386." | |
fi | |
BINARYNAME="TS3AudioBot.exe" | |
elif [ -e TS3AudioBot.exe ]; then | |
if [ -z "`uname | grep Linux`" -o -z "`uname -m | grep 64`" ]; then | |
echo "Do you have the right TS3AudioBot package for your system? You have: `uname` `uname -m`, not Linux x86_64." | |
fi | |
BINARYNAME="TS3AudioBot.exe" | |
else | |
echo "Could not locate binary file, aborting" | |
exit 5 | |
fi | |
case "$1" in | |
start) | |
if [ -e ts3audiobot.pid ]; then | |
if ( kill -0 $(cat ts3audiobot.pid) 2> /dev/null ); then | |
echo "The bot is already running, try restart or stop" | |
exit 1 | |
else | |
echo "ts3audiobot.pid found, but no server running. Possibly your previously started server crashed" | |
echo "Please view the logfile for details." | |
rm ts3audio.pid | |
fi | |
fi | |
if [ "${UID}" = "0" ]; then | |
echo WARNING ! For security reasons we advise: DO NOT RUN THE SERVER AS ROOT | |
c=1 | |
while [ "$c" -le 10 ]; do | |
echo -n "!" | |
sleep 1 | |
c=$(($c+1)) | |
done | |
echo "!" | |
fi | |
echo "Starting the TeamSpeak 3 AudioBot" | |
if [ -e "$BINARYNAME" ]; then | |
if [ ! -x "$BINARYNAME" ]; then | |
echo "${BINARYNAME} is not executable, trying to set it" | |
chmod u+x "${BINARYNAME}" | |
fi | |
if [ -x "$BINARYNAME" ]; then | |
export LD_LIBRARY_PATH="${LIBRARYPATH}:${LD_LIBRARY_PATH}" | |
mono "./${BINARYNAME}" ${COMMANDLINE_PARAMETERS} > /dev/null & | |
echo $! > ts3audiobot.pid | |
echo "TeamSpeak 3 AudioBot started, for details please view the log file" | |
else | |
echo "${BINARNAME} is not exectuable, cannot start TeamSpeak 3 AudioBot" | |
fi | |
else | |
echo "Could not find binary, aborting" | |
exit 5 | |
fi | |
;; | |
stop) | |
if [ -e ts3audiobot.pid ]; then | |
echo -n "Stopping the TeamSpeak 3 AudioBot" | |
if ( kill -TERM $(cat ts3audiobot.pid) 2> /dev/null ); then | |
c=1 | |
while [ "$c" -le 300 ]; do | |
if ( kill -0 $(cat ts3audiobot.pid) 2> /dev/null ); then | |
echo -n "." | |
sleep 1 | |
else | |
break | |
fi | |
c=$((++c)) | |
done | |
fi | |
if ( kill -0 $(cat ts3audiobot.pid) 2> /dev/null ); then | |
echo "AudioBot is not shutting down cleanly - killing" | |
kill -KILL $(cat ts3audiobot.pid) | |
else | |
echo "done" | |
fi | |
rm ts3audiobot.pid | |
else | |
echo "No AudioBot running (ts3audiobot.pid is missing)" | |
exit 7 | |
fi | |
;; | |
restart) | |
$0 stop && $0 start || exit 1 | |
;; | |
status) | |
if [ -e ts3audiobot.pid ]; then | |
if ( kill -0 $(cat ts3audiobot.pid) 2> /dev/null ); then | |
echo "AudioBot is running" | |
else | |
echo "AudioBot seems to have died" | |
fi | |
else | |
echo "No AudioBot running (ts3audiobot.pid is missing)" | |
fi | |
;; | |
*) | |
echo "Usage: ${0} {start|stop|restart|status}" | |
exit 2 | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment