I am trying to set up a Minecraft server. However, the basic startup scripts provided do not fit my needs. I want a script that will:
- Start a new
screen
running the jarfile and (pretty much) only the jarfile (so i can^C
it if needed without killing other things like screen or my gzip commands) - Gzip any logs that weren't gzipped automatically by the jarfile (for if/when i
^C
'ed the server, or if it crashed) - Run a command with
sudo
to set the process in the first argument to a high priority (/usr/bin/oom-priority
) - Run a
http-server
on theresource-pack
directory in a differentscreen
and send^C
to it when the server closes
I have these three commands. I run startserver
to start the server.
startserver
:
#!/bin/bash
set -m
cd /home/minecraftuser/server/
echo
screen -dm -S http-server http-server ./resource-pack
screen -dm -S my-mc-server startserver_command
(sleep 1; startserver_after) &
screen -S my-mc-server
startserver_command
:
#!/bin/bash
set -m
cd /home/minecraftuser/server/
echo
java -Xmx768M -Xms768M -jar ./craftbukkit.jar $@ &
env MC_PID=$! > /dev/null
(sleep 0.5; sudo /usr/bin/oom-priority $MC_PID) &
fg 1
echo
read -n 1 -p 'Press any key to continue...'
and startserver_after
:
#!/bin/bash
cd /home/minecraftuser/server/
wait $MC_PID
find /home/minecraftuser/server/logs -type f -name "*.log" -print | while read file; do gzip $file &
done
screen -S http-server -p 0 -X stuff \^c\\r
Edit: When I run startserver
, I get a command prompt then a bunch of gzip
errors of files already existing (I am expecting these errors, but when I run startserver
I'm supposed to get the java program). Somehow I am in a screen
because when I do ^A d
, I am brought to a new prompt.
Once I am out of the screen, screen -ls
returns two instances of my-mc-server
. One is a blank command prompt, the other is the server running successfully.
Edit 2: I changed startserver_command to remove the asterisk from env MC_PID=$! &
(not needed there) and added it to (sleep 1; startserver_after)
(makes it faster), redirected env
line to /dev/null
(removes entire environment listing at beginning of output). Still didn't fix the entire problem.