3

I started running a Minecraft server recently.

I couldn't find out how to not kill the process after exiting the console or putty.

The command is:

Java -jar minecraft_server.1.10.2.jar

but sometimes:

Java -Xmx1024M -Xms1024M -jar minecraft_server.1.10.2.jar
  • We can guess, but it would help in your question to show the command you use in starting minecraft. – Thomas Dickey Sep 10 '16 at 14:31
  • The command is Java -jar minecraft_server.1.10.2.jar but sometimes Java -Xmx1024M -Xms1024M -jar minecraft_server.1.10.2.jar – Ben Sep 10 '16 at 14:37
  • 1
    Ben please put it in your question. Not in the comments. – roaima Sep 10 '16 at 14:58
  • If any of these answers solved your problem, it might help if you mark them one as the accepted answer. – starbeamrainbowlabs Mar 4 '19 at 23:40
4

When you close PuTTY, it sends a hang-up signal to the computer, which is caught by various programs (including minecraft). You could use nohup, and redirect the standard output and standard error of minecraft to a file (or /dev/null), but some people find it simpler to install screen or tmux and leave a session of those running on the computer. That way, when you close screen/tmux, you can come back later and look at the messages.

I usually use screen, which uses fewer keystrokes than tmux. For instance,

  • run screen
  • press return to get a shell
  • run minecraft
  • type controlAd (control/A followed by d) to detach
  • close PuTTY

which reminds me that some screen default configurations still close the session when closing the terminal. If that is a problem, details can be added...

| improve this answer | |
  • Oh, and by the way, I SUCK at screen. Is there any chance you could tell what command I would run? – Ben Sep 10 '16 at 14:43
  • Which systems would kill screen on logout? Except for some new misconfigured systemd systems, that is... – ilkkachu Sep 10 '16 at 15:01
  • offhand, I don't recall, but do recall it being answered a couple of times. ymmv. – Thomas Dickey Sep 10 '16 at 15:05
1

I used to run a Terraria Server on a Raspberry Pi, and had the same problem.

The solution for me was screen

Install it using sudo apt install screen, then run the minecraft server but put screen before it.

The command would be: screen Java -Xmx1024M -Xms1024M -jar minecraft_server.1.10.2.jar

| improve this answer | |
0

I'm not 100% sure what you're asking, but I'll try to answer anyway :) When you connect to a remote system using ssh a terminal emulator (e.g. putty) and run a "foreground process" (i.e. something that stays opened, not a daemon that runs in the background) in that terminal, that process will terminate once you disconnect from your ssh session. If you run a background process, i.e. a daemon, it will continue to run even after the remote session ends. (You can "daemonize" most foreground processes by appending & at the end of the command you start that process with.) To kill it from another session you need to know its PID number (obtained e.g. via ps aux | grep 'name_of_process' or using top or htop utilities, or by issuing killall name command... and dozen other ways probably). On the other hand, to keep a foreground process alive between sessions, you need to use something like screen,tmux or byobu terminal multiplexors. They can be detached into background upon disconnecting and reattached the next time you log in, with all the processes running inside them intact. (Of course, if they die or are killed, everything in them dies as well).

The command is Java -jar minecraft_server.1.10.2.jar but sometimes Java -Xmx1024M -Xms1024M -jar minecraft_server.1.10.2.jar

If it stays in the background, you can kill it next time you log in by one of the kill commands, either killall java (which will kill all java processes running!) or ps aux |grep minecraft, which will spit out all processes with the word "minecraft" in them (incl the ps aux|grep minecraft probably), an the number next to the username is the PID. Then, just kill PID (where PID is the number from the previous command....) should do the trick. Verify by running ps aux |grep minecraft again. (If it's still running, try kill -9 PID next.)

| improve this answer | |
  • mm, & just starts the process in the background, but it's still bound to the terminal and should still get a SIGHUP and die if the terminal closes. – ilkkachu Sep 10 '16 at 16:49
0

The reason this occurs is because when you close your SSH session, your SSH server kills all the processes you had running.

Solutions offered here so far talk about using screen - which basically lets you disconnect from a terminal session, log out, and then reconnect to it at a later date - leaving all your processes still running.

This solution, however, does not take into account your server process crashing, the server restarting, or something else weird happening.

To that end, I recommend you investigate how to create a system service for your server. How one defines such a thing varies from system to system, but the genera principle is that a service is started by your server automatically once it's dependencies have started up, and will optionally restart it if it dies. You can even ask many programs to save their output to a log file instead of writing to the standard output.

If you have the systemctl command in your terminal, you probably have systemd. Here's a tutorial I found on setting up a minecraft service file for systemd-based systems.

If you don't have systemctl, then you probably have either an OpenRC-based or an upstart-based system. In these cases, you should investigate the existing services in /etc/init.d, and create your own based on that. (If anyone knows of a good tutorial on the subject, please edit t!)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.