Minecraft Wiki
Advertisement

Page creation

Done with my first draft... Comments, modification, experiences, help? Cheers Sakamura 20:50, 26 February 2011 (UTC)

Just got done setting up this up on a Mini Server running OS X Server and here's a few things I learned. I think it might help make this guide a little clearer to just remove all the references to the "easy ways" to do things. My Java process does stop properly but the tail hangs around (naturally) so my script kills the tail command after Java exits. I want to be able to run a second server in the future so my scripts include a "server name". I don't know if anyone else wants to do that, but here's my setup in case:
#!/bin/bash

server_name=server_ross

cd /Users/_minecraft/${server_name}

trap '{ echo "$(date) Killing Minecraft, ${server_name}."; ./stop.sh; exit 0; }' TERM INT

ipconfig waitall

echo "$(date) Starting Minecraft, ${server_name}."

./start.sh &
wait

echo "$(date) Minecraft, ${server_name} done."
Here's my start.sh. The pipe file has been renamed to include the server name so stop.sh can find the tail process to kill it. The -Dnet.minecraft.server=${server_name} is also just there for finding the right server when stopping.
#!/bin/bash

server_name=server_ross

cd /Users/_minecraft/${server_name}

rm command_pipe.${server_name}
touch command_pipe.${server_name}
tail -f command_pipe.${server_name} | java -Xmx1G -Xms1G -Dnet.minecraft.server=${server_name} -jar minecraft_server.jar nogui
Finally, my stop.sh script which also kills the tail process.
#!/bin/bash

server_name=server_ross

cd /Users/_minecraft/${server_name}

echo stop >> command_pipe.${server_name}

while ps -u _minecraft | grep "net.minecraft.server=${server_name}" | grep -qv grep
do
	sleep 1
done

# We have to kill the tail that was feeding Java.
tailpid=$(ps -u _minecraft | grep command_pipe.${server_name} | grep -v grep | cut -c 6-11)
kill $tailpid
Rossiam 01:00, 3 May 2011 (UTC)

On-demand start & stop daemon

Hello,

I think you did a fantastic job here, considering that I have now my own minecraft server properly configured to start along with my Mac while I am not really accustomed to the Mac command line (I must admit I'm mostly a PC user).

I still have a few questions about this tutorial (please pardon my noobfullness) :

  • Is it possible to adapt your daemon to launch on demand, i.e. when the first client asks for server connection (by listening to port 25565 connection attempts maybe ?)
  • ... and to stop when the last client disconnects, i.e. when nobody's using the server
  • and (maybe) also to launch updates automatically (I've seen some linux scripts available online1 that can do that among other thinks, but I have no idea how to adapt them).

Also, I had to use portmap2 to force port forwarding on my router (did not work without it). Is there a way to include start portmap with the server daemon as well ?

Finally, I understand the security concern, but is there an easy way to administer files in the _minecraft folder. Files are accessible of course, as you can modify them through terminal using the sudo nano command (sudo nano server.properties to edit the server.properties, for instance). But, at this point, modifying those files remains complicated, especially if a lot of them are involved. Concerning this point, is it acceptable to allow a user to access minecraft server files ? And then how should you do it without compromising security ?

Thank you again for sharing your Minecraft Server Startup Daemon with the community.


1, like here : planetminecraft.com/blog/automatically-stop-a-server-when-nobodys-playing

2, www.codingmonkeys.de/portmap/

posted by --Oulipion (talk) 15:45, 7 October 2013 (UTC)
and modified --Oulipion (talk) 21:20, 8 October 2013 (UTC)

Response - SapiusN

Let me try to answer your questions:

1) Yes, Automatic startup/shutdown is possible. See the new section of the article associated with this discussion.

2) Yes it would be fairly straightforward to add an update checker, but updates are something that can break world files and cause other havoc, and should be done manually when you're ready.

3) Yes, bash scripts are designed primarily to run programs at specific times (such as portmap, although I am unfamiliar with it). To run this program at the begining of the script, simply insert the command line call you would make to run program from the shell after #!/bin/bash. If the program is a mac application (ie: something.app) then the executable will be under the contents of the .app directory in the MacOS folder.

4) I'm not sure what you mean about 'letting a user access the files' but if you want to access them without sudo all the time, you could run the startup script as a login script, and put the files in a dicectory owned by the user. This itself is not security optimal, because if an attacker hack Minecraft, they get access to that user's files in addition to the server files. Accessing the server files with sudo stored in a separate user is as safe as it gets.
You may be able to give the daemon user a password, and distribute that password to other users of your system without needing to give them root access, but I don't know enough to be sure of that with out researching it.

5) 'Too complicated' ... maybe your problem here is that you're using nano. try Vi improved (ie: Vim) ;-D

       ________ ++     ________
      /VVVVVVVV\++++  /VVVVVVVV\
      \VVVVVVVV/++++++\VVVVVVVV/
       |VVVVVV|++++++++/VVVVV/'
       |VVVVVV|++++++/VVVVV/'
      +|VVVVVV|++++/VVVVV/'+
    +++|VVVVVV|++/VVVVV/'+++++
  +++++|VVVVVV|/VVV___++++++++++
    +++|VVVVVVVVVV/##/ +_+_+_+_
      +|VVVVVVVVV___ +/#_#,#_#,\
       |VVVVVVV//##/+/#/+/#/'/#/
       |VVVVV/'+/#/+/#/+/#/ /#/
       |VVV/'++/#/+/#/ /#/ /#/
       'V/'  /##//##//##//###/
                ++

--SapiusN (talk) 10:37, 18 February 2014 (UTC)

Advertisement