• If you need help or want to discuss things, you now can also join us on our Discord Server!
  • A first preview of the unlimited version of SinusBot can be found in the Upcoming Changes thread. A version for Windows will follow, but we don't have a release date, yet.

Where do I put this, to for my SinusBOT crash when closing SSH

Status
Not open for further replies.

Hudson Ramalho

New Member
When I close SSH, my SinusBOT Script stops working, I need this AutoStart to stop it, I do not know where to put that code help me

#! /bin/bash

##################################################################################
# #
# Usage: ./launch.sh {start|stop|status|restart|console} #
# - start: start the bot #
# - stop: stop the bot #
# - status: display the status of the bot (down or up) #
# - restart: restart the bot #
# - console: display the bot console #
# To exit the console without stopping the server, press CTRL + A then D. #
# #
##################################################################################

SCREEN_NAME="ts3bot"
USER="xuxe"
DIR_ROOT="/opt/ts3soundboard/"
BOT_RUNCMD="./sinusbot"

# No edits necessary beyond this line
PATH=/bin:/usr/bin:/sbin:/usr/sbin
if [ ! -x `which awk` ]; then echo "ERROR: You need awk for this script (try apt-get install awk)"; exit 1; fi
if [ ! -x `which screen` ]; then echo "ERROR: You need screen for this script (try apt-get install screen)"; exit 1; fi

function start {
if [ ! -d $DIR_ROOT ]; then echo "ERROR: $DIR_ROOT is not a directory"; exit 1; fi
if status; then echo "$SCREEN_NAME is already running"; exit 1; fi

# Start bot
if [ `whoami` = root ]
then
su - $USER -c "cd $DIR_ROOT ; screen -AmdS $SCREEN_NAME $BOT_RUNCMD"
else
cd $DIR_ROOT
screen -AmdS $SCREEN_NAME $BOT_RUNCMD
fi
}

function stop {
if ! status; then echo "$SCREEN_NAME could not be found. Probably not running."; exit 1; fi

if [ `whoami` = root ]
then
su - $USER -c "killall sinusbot -u $USER"
else
killall ts3bot -u $USER
fi
}

function status {
if [ `whoami` = root ]
then
su - $USER -c "screen -ls" | grep [.]$SCREEN_NAME[[:space:]] > /dev/null
else
screen -ls | grep [.]$SCREEN_NAME[[:space:]] > /dev/null
fi
}

function console {
if ! status; then echo "$SCREEN_NAME could not be found. Probably not running."; exit 1; fi

if [ `whoami` = root ]
then
tmp=$(su - $USER -c "screen -ls" | awk -F . "/\.$SCREEN_NAME\t/ {print $1}" | awk '{print $1}')
su - $USER -c "screen -r $tmp"
else
screen -r $(screen -ls | awk -F . "/\.$SCREEN_NAME\t/ {print $1}" | awk '{print $1}')
fi
}

function usage {
echo "Usage: $0 {start|stop|status|restart|console}"
echo "On console, press CTRL+A then D to stop the screen without stopping the server."
}

case "$1" in

start)
echo "Starting $SCREEN_NAME..."
start
sleep 5
echo "$SCREEN_NAME started successfully"
;;

stop)
echo "Stopping $SCREEN_NAME..."
stop
sleep 5
echo "$SCREEN_NAME stopped successfully"
;;

restart)
echo "Restarting $SCREEN_NAME..."
status && stop
sleep 10
start
sleep 5
echo "$SCREEN_NAME restarted successfully"
;;

status)
if status
then echo "$SCREEN_NAME is UP"
else echo "$SCREEN_NAME is DOWN"
fi
;;

console)
echo "Open console on $SCREEN_NAME..."
console
;;

*)
usage
exit 1
;;

esac

exit 0
 

dshimen2

Donor
is awesome!
Try too start your bot with /screen -S sinusbot ./sinusbot

Then when it's starts press ctrl +a +d , but remember to start it from different user than root and this user need to have all permissions for files in /opt/sinusbot
 
Status
Not open for further replies.
Top