Minecraft restart bash script won't run init.d/service command
What I intend to do
I'm attempting to make a restart script for my Minecraft server so my friends can use the /restart
command in-game because they don't have SSH access to my server to restart Minecraft.
My script
Currently my restart.sh
script contains
exec >> zzz.log
exec 2>&1
set -x
sleep 5
exec /etc/init.d/minecraft start
Script break down
The first two lines will redirect standardout and standarderror (as Linux fluent users will already know) into the zzz.log
file, this is just so I can capture the output to help me figure what's going on.
set -x
is also another part to help me figure what's going on, this will output each line that is executed into zzz.log
because the above lines redirect the output to there.
sleep(5)
as it suggests will make the script pause for 5 seconds, this is just to ensure Minecraft has had enough time to shutdown.
exec
will make the following command /etc/init.d/minecraft start
run in a different process. Since I do not know how the script is invoked, I assumed this could be a child process of the Minecraft server and thus if the Minecraft server process dies, the script will too, having it this way should ensure the command is run.
My issue
Now, if the Minecraft server is offline and I execute ./restart.sh
the server starts up perfectly fine. When in-game if I type /restart
the Minecraft server shuts down like its supposed to, but never re-launches again. Looking at my zzz.log
file I can see the problem lays around the exec /etc/init.d/minecraft start
command, this line is never successfully executed when Minecraft executes the restart.sh
script. Why is this?
init script
I obtained the init script from here. This allows me to start
, stop
, restart
the Minecraft server along with various other commands to control the Minecraft server.
Best Answer
In bash exec replaces the current script with the command argument without forking a new process. If restart.sh is being run under a process that goes down, I imagine it would take restart.sh with it.
Pictures about "Minecraft restart bash script won't run init.d/service command"
How do I force a Minecraft server to restart?
To do this:How do you make a Minecraft server startup script?
You start your server using "systemctl start minecraft@FTBBeyond" and stop it using "systemctl stop minecraft@FTBBeyond". The part behind the "@" is your instance name e. g. the Folder Name. This script also takes care to automatically stop your minecraft server if you reboot the server.How do you open the Minecraft startup script?
Most shared Minecraft hosts will create a launch script for you....Running a Launch ScriptHow do I write a script to restart a server?
How To Use a Bash Script To Restart Linux Server ServicesMinecraft restart script fuer Linux
Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.
Images: Sora Shimazaki, Markus Spiske, Markus Spiske, Mary Taylor