Startup Script for Minecraft Server
Alright so I have a Minecraft server running for a couple of friends and I. Right now every time my CentOS box restarts, which isnt a lot, (the computer the server runs off of) I need to manually run the .sh script that starts the server. I want this make this process automatic, however I do not want to make it a service and I also want to be able to see the server console whenever I want to.
What I want- I would like to create a .sh script to run on startup which would make a terminal open when logged in, then execute another .sh script (this other .sh script is the script I currently use the start the server manually) How would I do this? Thanks. |
you can put commands in /etc/rc.local and they will run when the system boots up.
or you can put stuff in ~/.profile or ~/.bash_profile and they will run when that user logs in. or you can put an @reboot entry in your crontab and the command will run after every reboot. |
For the portion of your question concerning being able to see the console whenever you want to, screen would be a great program to look into for this. I keep meaning to learn how to do more with it.
Quote:
Here is an example of using it to start the program top, name the session foo, and immediately detach the screen. Code:
screen -d -m -S foo top Code:
screen -r foo *edit* added this: A less powerful, but simpler way, would be to background the process and redirect output to a file, you could view output by viewing the file, but you would be unable to interact with the console. In this particular situation, it may be better, because there is no need to interact with the minecraft script after its started, but its a good excuse to learn screen. |
Quote:
Quote:
|
Quote:
|
Quote:
|
not really sure what you are trying to do (or why ?) but if all you want to do is have a terminal started when you login try putting this in the last line of .bash_profile:
Code:
/usr/bin/gnome-terminal & |
not sure what the syntax is for gnome-terminal, but for xterm, if you wanted to open up a new terminal window and run a command in it, lets use top for this example, it goes like this.
Code:
xterm -e top & |
Sorry for not being clear. To start my server, I usually launch up a terminal then type in a java command which starts the server (I also sometimes launch a terminal, cd to the directory where my .sh script and then in the terminal run the .sh script). I am basically trying to do this but automatically, would screen be a better option?
|
Quote:
Code:
/usr/bin/gnome-terminal -e top & |
Quote:
Code:
[schneidz@hyper ~]$ cat /etc/rc.local |
screen could be overkill for this particular situation. I know I suggested it earlier, and it is useful, but since there is no need to interact with the script after its started... here is a simpler minecraft server startup script for an example. It is actually what I use on mine.
Code:
java -Xmx1024M -Xms1024M -jar /path/to/the/minecraft_server.1.7.4.jar nogui >> /path/to/the/mc.log 2>&1 & the "&" at the end backgrounds the process the ">> /path/to/the/mc.log 2>&1" sends all output to a file (/path/to/the/mc.log) After this is started, you can view the output of the server by either of these 2 following ways. Code:
cat /path/to/the/mc.log "tail -f" will update the display in the terminal window whenever new text is added. With this script, I would just start it on boot by placinig it in rc.local or whatever your distro uses. Then, anytime you want, you can monitor the output of the server by typing one of the above commands in a terminal. |
Quote:
Question: how would I properly turn off the server, I dont want to shut it off with some hacky method. Should I learn how to use screen? |
it saves some cpu usage and ram, mostly just because you don't have to have a terminal window open. More importantly you dont have to worry about accidentally closing out the terminal and crashing the server.
The best way to shutdown a minecraft server is to issue the commands /save-all and then /stop from within the game. You need to have administrator privileges though. In order to gain administrator priviliges, add your name to the ops.txt file in the games directory and restart. Here are the 2 relevant web pages. http://minecraft.gamepedia.com/Administrator http://minecraft.gamepedia.com/Comma...-only_Commands To force a process to quit, you can find the process's pid and then kill it using the kill command. But, this doesn't kill programs gracefully, it may not save all changes before it exits. Here is an example of what it would look like on my server if I was to shut down minecraft this way. I use the grep command to filter out any process that doesn't have java in the name. If the kill command doesn't work, you may have to add sudo in front of it or use "kill -9" in order force it to stop. Code:
server$ ps -aux | grep java im sure i messed up some of the jargon with that, hope you get the point though. |
All times are GMT -5. The time now is 01:37 AM. |