So, I host multiple Minecraft servers on my Ubuntu VM and I've setup a script to start all of them at once. The servers are running in screen sessions and basically what the script does is send the java start command to these screen sessions and if a screen session can't be found creates one. The problem is the screen sessions default to your current working directory and the jars I'm targeting are all in different directories (I.E not my current directory) So, so for example after a reboot, when all the screen sessions are offline and need to be started, they aren't started in the correct directory. So, what I need is these new screen sessions that are created to start in a specific directory or else a way to target the jars from a different directory and set their working directory. I've been trying for a while to find a solution for this but haven't found anything. Here are my scripts:
This is just one of the scripts I use to start my server, but the other scripts are mostly the same just different starting flags. I removed the memory flags as they weren't relevant (to my knowledge) and just made the code block really long.:
#!/bin/bash if screen -S "SMP" -X stuff 'java [Lots of fine-tuned java memory flags] -jar paper.jar nogui^M' then echo "Server starting on prexisting screen" else echo "Cannot find prexsisting screen, attempting to create a new one." screen -dmS "SMP" screen -S "SMP" -X stuff 'java [Lots of fine-tuned java memory flags] -jar paper.jar nogui^M' echo "Loaded server on a new screen" fi
Here is the script I call the above one from. I wrote all the start scripts in their own .sh files and then just call them all from one file (This is the script that I actually use to start my servers):
#!/bin/bash echo "Attempting to start all servers" bash /opt/opt/new_lobby/start.sh bash /opt/opt/new_SMP/start.sh bash /opt/opt/new_creative/start.sh bash /opt/opt/network/start.sh echo "All server start files have attempted to be executed"
If anyone has any ideas on this please help. Also I know this isn't "Ubuntu specific" but it's Bash script and I didn't really know where else to put this as it's Java, Bash, and Minecraft all together. P.S I know there are spelling mistakes in my scripts, but this was the first time I copy/pasted them into something that had an auto correct and I have yet to change them lol.