adduser samp
passwd samp
nano /home/samp/samp-server.sh
#!/bin/sh # Copyright © 2017 Faskis # (Also technically Copyright © 2010 TeamSpeak Systems GmbH as this is copied from ts3server_startscript.sh) # All rights reserved COMMANDLINE_PARAMETERS="&" #add any command line parameters you want to pass here D1=$(readlink -f "$0") BINARYPATH="$(dirname "${D1}")" cd "${BINARYPATH}" LIBRARYPATH="$(pwd)" BINARYNAME="samp03svr" case "$1" in start) if [ -e samp.pid ]; then if ( kill -0 $(cat samp.pid) 2> /dev/null ); then echo "The server is already running, try restart or stop" exit 1 else echo "samp.pid found, but no server running. Possibly your previously started server crashed" echo "Please view server_log.txt for details." rm samp.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 SA-MP server" 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}" "./${BINARYNAME}" ${COMMANDLINE_PARAMETERS} > /dev/null & PID=$! ps -p ${PID} > /dev/null 2>&1 if [ "$?" -ne "0" ]; then echo "The SA-MP server could not start" else echo $PID > samp.pid echo "SA-MP server started, for details please view server_log.txt" fi else echo "${BINARNAME} is not exectuable, cannot start the SA-MP server" fi else echo "Could not find binary, aborting" exit 5 fi ;; stop) if [ -e samp.pid ]; then echo -n "Stopping the SA-MP server" if ( kill -TERM $(cat samp.pid) 2> /dev/null ); then c=1 while [ "$c" -le 300 ]; do if ( kill -0 $(cat samp.pid) 2> /dev/null ); then echo -n "." sleep 1 else break fi c=$(($c+1)) done fi if ( kill -0 $(cat samp.pid) 2> /dev/null ); then echo "Server is not shutting down cleanly - killing" kill -KILL $(cat samp.pid) else echo "done" fi rm samp.pid else echo "No server running (samp.pid is missing)" exit 7 fi ;; restart) $0 stop && $0 start ${COMMANDLINE_PARAMETERS} || exit 1 ;; status) if [ -e samp.pid ]; then if ( kill -0 $(cat samp.pid) 2> /dev/null ); then echo "Server is running" else echo "Server seems to have died" fi else echo "No server running (samp.pid is missing)" fi ;; *) echo "Usage: ${0} {start|stop|restart|status}" exit 2 esac exit 0
nano /lib/systemd/system/samp.service
[Unit] Description=SA-MP Server After=network.target [Service] WorkingDirectory=/home/samp/ User=samp Group=samp Type=forking ExecStart=/home/samp/samp-server.sh start ExecStop=/home/samp/samp-server.sh stop PIDFile=/home/samp/sampmain.pid RestartSec=15 Restart=always [Install] WantedBy=multi-user.target
systemctl --system daemon-reload systemctl start samp.service systemctl enable samp.service
You have probably saved me countless hours of ps aux | grep samp & kill xxx.. Thank you! <3
|