Created
January 8, 2015 05:41
-
-
Save Techcable/07e0125ff7bf4af2ee67 to your computer and use it in GitHub Desktop.
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/bash | |
# /etc/init.d/bungeecord | |
### BEGIN INIT INFO | |
# Provides: bungeecord | |
# Required-Start: $local_fs $remote_fs screen-cleanup | |
# 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: Bungee Cord Minecraft Proxy | |
# Description: Starts the bunggecord proxy | |
### END INIT INFO | |
#Settings | |
SERVICE='BungeeCord.jar' | |
USERNAME='minecraft' | |
WORLD='world' | |
HISTORY=256 | |
PROXY_PATH='/home/minecraft/bungeecord' | |
MAXHEAP=256 | |
MINHEAP=128 | |
CPU_COUNT=1 | |
INVOCATION="java -Xmx${MAXHEAP}M -Xms${MINHEAP}M -XX:+UseConcMarkSweepGC \ | |
-XX:+CMSIncrementalPacing -XX:ParallelGCThreads=$CPU_COUNT -XX:+AggressiveOpts \ | |
-jar $SERVICE" | |
ME=`whoami` | |
as_user() { | |
if [ $ME == $USERNAME ] ; then | |
bash -c "$1" | |
else | |
su - $USERNAME -c "$1" | |
fi | |
} | |
proxy_start() { | |
if pgrep -u $USERNAME -f $SERVICE > /dev/null | |
then | |
echo "$SERVICE is already running!" | |
else | |
echo "Starting $SERVICE..." | |
cd $PROXY_PATH | |
as_user "cd $PROXY_PATH && screen -h $HISTORY -dmS bungeecord $INVOCATION" | |
sleep 7 | |
if pgrep -u $USERNAME -f $SERVICE > /dev/null | |
then | |
echo "$SERVICE is now running." | |
else | |
echo "Error! Could not start $SERVICE!" | |
fi | |
fi | |
} | |
proxy_stop() { | |
if pgrep -u $USERNAME -f $SERVICE > /dev/null | |
then | |
echo "Stopping $SERVICE" | |
as_user "screen -p 0 -S bungeecord -X eval 'stuff \"alert SERVER SHUTTING DOWN IN 10 SECONDS.\"\015'" | |
sleep 10 | |
as_user "screen -p 0 -S bungeecord -X eval 'stuff \"end\"\015'" | |
sleep 7 | |
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 | |
} | |
proxy_command() { | |
command="$1"; | |
if pgrep -u $USERNAME -f $SERVICE > /dev/null | |
then | |
pre_log_len=`wc -l "$PROXY_PATH/proxy.log.0" | awk '{print $1}'` | |
echo "$SERVICE is running... executing command" | |
as_user "screen -p 0 -S bungeecord -X eval 'stuff \"$command\"\015'" | |
sleep 3 # assumes that the command will run and print to the log file in less than 3 seconds | |
# print output | |
tail -n $[`wc -l "$PROXY_PATH/proxy.log.0" | awk '{print $1}'`-$pre_log_len] "$PROXY_PATH/proxy.log.0" | |
fi | |
} | |
#Start-Stop here | |
case "$1" in | |
start) | |
proxy_start | |
;; | |
stop) | |
proxy_stop | |
;; | |
restart) | |
proxy_stop | |
proxy_start | |
;; | |
status) | |
if pgrep -u $USERNAME -f $SERVICE > /dev/null | |
then | |
echo "$SERVICE is running." | |
else | |
echo "$SERVICE is not running." | |
fi | |
;; | |
command) | |
if [ $# -gt 1 ]; then | |
shift | |
proxy_command "$*" | |
else | |
echo "Must specify server command (try 'help'?)" | |
fi | |
;; | |
*) | |
echo "Usage: $0 {start|stop|status|restart|command \"server command\"}" | |
exit 1 | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment