Title Image

Owner’s Corner: Start Script

So, a minecraft server is a java .jar program, which is a cross-platform executable. If you wanna be really pure about it, the way to start a minecraft server is the following command:

java -server -Xmx3400M -jar craftbukkit-1.3.2-R1.0.jar nogui

What that is doing is saying "Run a java program, allocate it 3.4GB of RAM, it's a .jar file which is a library of multiple .java files, here is the archive's name, and run it without the user interface.

Nevertheless, this won't actually work. On a linux machine, when you initiate a process like this server, you have to keep the window open to keep the process alive. So, if I'm on my work computer, and the server goes down, and I log in and restart it, then go to close my work computer down...the server dies until I restart it. What NEEDS to happen is to initiate a program and then disconnect from it, and that is done primarily with the linux command "screen." You should read the whole description for that here. What your'e doing is creating like a virtual screen which is running the server process, then we can connect and disconnect from that screen from other places. It allows the server to run on its own.

So, we could initiate the server now with the following command:

screen -dmS Bukkit java -server -Xmx3400M -jar craftbukkit-1.3.2-R1.0.jar nogui

This command uses 3 flags, -dmS, which basically say "kill any existing screens using the name Bukkit, then make a new one with the name Bukkit, and in that screen run the start server command." From in here, you can run the command "screen -x Bukkit" and re-attach to that screen, or from inside the screen "ctrl+a ctrl+d" to go back out to the main command line. Also, from the command line, we can type "screen -dr Bukkit -p 0 -X stuff "$(printf "say I Am Poop\r")"" to send the command "say I Am Poop" which prints "I Am Poop" in game, and that can be used to send any command in-game without being logged into the console.

Still, there's issues with that. Let's say IMGArY started the server, and I didn't know it, so I accidentally kill his version and log everyone out, then start it over. It's messy...what you'd have to do is pull a list of existing screens with "screen -ls" and if it's active, connect to it, and if not, start it. That's not very tidy. What's better is a script, that runs the check for existing screens, and if it finds one, connects to it, and if not, starts it. But what if the name of the server executable changes, like with a new version of bukkit? Ask a whole series of what-ifs and you come up with a pretty decent server-running script that does everything you want. We didn't write this, and cnc made some mods to it, but for the most part it's how it was when we found it:

Spoiler Inside SelectShow

So, when we log into the back-end, and type "sh stargserver.sh" it brings us to a page with a bunch of options. It's smart enough to update the system, and not let you do anything stupid to break things. I think I may do some work to clean it up when we move, but this is how it exists now.

When you pay someone to host your minecraft server, and it's someone that has a specific "run minecraft server" business, they have some sort of a website GUI that controls a lot of these commands, which is what we used to use. Remember back in the day having to wait for the host to allow us to use dev bukkit versions? It's just less control, for our purposes, running the server on a blank linux system is much better.