Skip to content

Instantly share code, notes, and snippets.

@rickselby
Last active January 5, 2017 08:47
Show Gist options
  • Select an option

  • Save rickselby/dfc6d2463af803dca5b4c76a1d1921b0 to your computer and use it in GitHub Desktop.

Select an option

Save rickselby/dfc6d2463af803dca5b4c76a1d1921b0 to your computer and use it in GitHub Desktop.
ACSR files
#/bin/bash
ASSETTO_DIR="/home/steam/assetto/"
PIDFILE="$ASSETTO_DIR/acServer.pid"
LOGFILE="$ASSETTO_DIR/acServer.log"
DAEMON="$ASSETTO_DIR/acServer"
case $1 in
start)
# Startas bash and pass an bash exec
# this allows the log output to be captured
# See: http://stackoverflow.com/questions/8251933/how-can-i-log-the-stdout-of-a-process-started-by-start-stop-daemon
start-stop-daemon --start \
--background \
--user steam \
--name acServer \
--make-pidfile \
--pidfile $PIDFILE \
--chdir "$ASSETTO_DIR" \
--chuid steam \
--startas /bin/bash \
-- -c "exec \"$ASSETTO_DIR/acServer\" &> $LOGFILE"
if [ $? -eq 0 ] ; then
echo "Server Started"
else
echo "Server Start Failed!"
fi
;;
stop)
start-stop-daemon --stop \
--user steam \
--name acServer \
--pidfile $PIDFILE \
--retry 5
if [ $? -eq 0 ] ; then
echo "Server Stopped"
else
echo "Can't stop server"
fi
rm $PIDFILE
mv $LOGFILE $LOGFILE.last
;;
restart)
$0 stop && sleep 2 && $0 start
;;
status)
status="Not Running"
read pidtest < $PIDFILE &>/dev/null
if [ -n pidtest ] ; then
/bin/ps "${pidtest:-}" >/dev/null 2>&1
if [ $? -eq 0 ] ; then
status="Running"
fi
fi
echo "Server is $status"
;;
tail)
tail -f $LOGFILE
;;
*)
echo "Usage: $0 {start|stop|restart|status|tail}"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment