-
-
Save h4rm0n1c/6a3e7c5c4bbcbfa0bb21 to your computer and use it in GitHub Desktop.
NodePAMasterless version of the planetary annihilation init.d script
This file contains hidden or 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/bash | |
# /etc/init.d/planetary | |
# version 0.0.3 2015-04-25 (YYYY-MM-DD) | |
# caveat emptor, don't copy and paste and just hope it'll work, READ AND COMPREHEND. | |
### BEGIN INIT INFO | |
# Provides: planetary | |
# Required-Start: $local_fs $remote_fs | |
# Required-Stop: $local_fs $remote_fs | |
# Should-Start: $network | |
# Should-Stop: $network | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: planetary annihilation server | |
# Description: Starts the planetary annihilation server | |
### END INIT INFO | |
#Settings | |
#set this a word out of the server's name as specified below, do not put in spaces, just one word or pgrep will be unhappy. | |
#this just helps the script to find the server process itself via its name, for status monitoring. | |
#using "server" as the value is a bad idea, it will catch ssh as it has the word "server" in the process name. | |
SERVICE='GOAT' | |
#this is the user the server is running under | |
USERNAME='planetary' | |
#full path to he server executable | |
PAPATH="/home/planetary/.local/Uber Entertainment/Planetary Annihilation/stable/" | |
#server invocation command | |
INVOCATION="./server --headless --game-mode Config --allow-lan --server-name GOAT Squad Private --port 20545" | |
ME=$(whoami) | |
as_user() { | |
if [ "$ME" == $USERNAME ] ; then | |
bash -c "$1" | |
else | |
su - $USERNAME -c "$1" | |
fi | |
} | |
pa_start() { | |
if pgrep -u $USERNAME -f "${SERVICE}" > /dev/null | |
then | |
echo "$SERVICE is already running!" | |
else | |
echo "Starting $SERVICE..." | |
cd "${PAPATH}" | |
as_user "cd '${PAPATH}' && screen -dmS planetary while true; do sleep 1; if pgrep -u \"$USERNAME\" -f \"$SERVICE\"; then echo \"Planetary Annihilation: Stopped. Restarting in 1 second.\"; else \"$INVOCATION\" & fi; done" | |
sleep 2 | |
if pgrep -u $USERNAME -f "${SERVICE}" > /dev/null | |
then | |
echo "$SERVICE is now running." | |
else | |
echo "Error! Could not start $SERVICE!" | |
fi | |
fi | |
} | |
pa_stop() { | |
if pgrep -u $USERNAME -f "${SERVICE}" > /dev/null | |
then | |
echo "Stopping $SERVICE" | |
as_user "screen -p 0 -S planetary -X quit" | |
else | |
echo "$SERVICE was not running." | |
fi | |
if pgrep -u $USERNAME -f "${SERVICE}" > /dev/null | |
then | |
echo "Error! $SERVICE could not be stopped." | |
else | |
echo "$SERVICE is stopped." | |
fi | |
} | |
pa_update() { | |
if pgrep -u $USERNAME -f "${SERVICE}" > /dev/null | |
then | |
echo "$SERVICE is running! Will not start update." | |
else | |
echo "TODO: Update Script" | |
fi | |
} | |
#Start-Stop here | |
case "$1" in | |
start) | |
pa_start | |
;; | |
stop) | |
pa_stop | |
;; | |
restart) | |
pa_stop | |
pa_start | |
;; | |
update) | |
pa_stop | |
pa_update | |
pa_start | |
;; | |
status) | |
if pgrep -u $USERNAME -f "${SERVICE}" > /dev/null | |
then | |
echo "$SERVICE is running." | |
else | |
echo "$SERVICE is not running." | |
fi | |
;; | |
*) | |
echo "Usage: /etc/init.d/planetary {start|stop|update|status|restart}" | |
exit 1 | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment