Talk:Tutorials/Create a Mac OS X startup daemon

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

tailpid=$(ps -u _minecraft | grep command_pipe.${server_name} | grep -v grep | cut -c 6-11) kill $tailpid 
 * 1) We have to kill the tail that was feeding Java.


 * 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  command (  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)

Upgrading these instructions for OS X, 2017
I'm about to do this on my mac mini, and this page is really helpful! I really appreciate all the work people have put into it.

One thing that is confusing is the number of different ways shown to do it. Someone coming to the page is usually looking for a set of instructions that will work so they know what they can do to accomplish their goal. Having many options can make it seem impossibly complicated. But as improvements have been added, they have been appended to the page, so the reader doesn't really know which one is better, or how to choose between them. They don't need to know many possibilities, they need to know one thing they can do that works, even if other options are available.

So I was thinking that while I set my system up, I'd clean up this page to present the simplest of the options to the user as "how to do it", rather than keep the original but more complicated options at the top. Any other approaches could be at the end for advanced users. But most readers would know that, once they reached the end of the first set of instructions, they don't have to know more.

Before any rework of this magnitude, I want to let folks know and give them a chance to advise, object, or whatever.

I haven't yet set up my server, but my expectation is that I would start with the single-script version. I would tell folks to create a new account, but would say they could use their own if they don't mind those security risks. I wouldn't even tell people about running as root because that seems like an insane choice. Running as themselves as simple as root, if the account creation intimates them. I would add a simple script for sending commands to the server that used the fifo. And that would be about it. Of course, all existing contributors would be included in acknowledgements.

I would also change Tutorials/Setting up a server to simply point to here, no point in having two things going on this subject.

Any thoughts, dissuasions, ideas, are solicited.

207.198.105.20 18:58, 1 February 2017 (UTC)


 * Looking at the page history, this article hasn't been edited in two years, so if you want to make improvements, go right ahead. The 'Setting up a server' tutorial covers multiple operating systems, so it wouldn't be appropriate to redirect that entire page to here. Adding a link in its OS X section could be useful, though. -- Orthotopetalk 01:31, 2 February 2017 (UTC)