Last active
June 30, 2020 19:42
-
-
Save Jofkos/a736e40ea701a0d705c1 to your computer and use it in GitHub Desktop.
BungeeCord/Spigot tmux bash start 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 | |
#base directory is this script's parent dir | |
cd $(dirname "$0") | |
#server/proxy directories, first one has to be the bungeecord directory | |
servers=("bungee" "lobby" "serverone" "servertwo") | |
#dir which contains the server/proxy directories (`pwd` -> current dir) | |
basedir="`pwd`" | |
#tmux session name (`basename \"$basedir\"` -> basedir's name) | |
session="`basename \"$basedir\"`" | |
if [[ basedir != */ ]] | |
then | |
basedir+="/" | |
fi | |
start() { | |
tmux new-session -d -s $session | |
counter=0 | |
for i in "${servers[@]}" | |
do | |
if (( $counter == 0 )) | |
then | |
tmux rename-window -t $session:$counter $i | |
else | |
tmux new-window -t $session:$counter -n $i | |
fi | |
echo "Starting server $i" | |
tmux send-keys -t $session:$i "cd $basedir$i" C-m | |
tmux send-keys -t $session:$i "bash start.sh" C-m | |
((counter++)) | |
done | |
echo "Server started. Attaching session..." | |
sleep 0.5 | |
tmux attach-session -t $session:0 | |
} | |
stop() { | |
for i in "${servers[@]}" | |
do | |
case "$i" in | |
"${servers[0]}") | |
tmux send-keys -t $session:$i "e" | |
tmux send-keys -t $session:$i "nd" C-m | |
;; | |
*) | |
tmux send-keys -t $session:$i "stop" C-m | |
;; | |
esac | |
echo "Stopping $i" | |
done | |
for i in {5..1..-1} | |
do | |
echo -ne "\rWaiting for shutdown... $i" | |
sleep 1 | |
done | |
echo "" | |
echo "Killing tmux session" | |
tmux kill-session -t $session | |
echo "Server stopped" | |
} | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
attach) | |
tmux attach -t $session | |
;; | |
restart) | |
stop | |
sleep 0.8 | |
echo "Restarting server..." | |
sleep 0.8 | |
start | |
;; | |
*) | |
echo "Usage: start.sh (start|stop|restart|attach)" | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment