Как я могу управлять своим сервером minecraft, когда запускаю его при загрузке с помощью скрипта rc.local?

506

У меня вопрос к вам, ребята. Я управляю сервером MC до сих пор так здорово. Чтобы сделать его автономным, я запускаю его при загрузке с загрузкой скрипта bash в rc.local, просто.

#!/bin/bash cd /home/minecraft sudo java -Xms512M -Xmx1008M -jar /home/minecraft/spigot-1.9.jar nogui 

Хорошо, проблема в том, что когда я подключаюсь через ssh, я не вижу сервер. Он работает, потому что я могу играть без проблем, но я не могу получить контроль над ним.

Когда я запускаю сервер с командой из сценария, но не при загрузке, сервер остается на экране, ожидая команды и показывая информацию, но когда я запускаю его из сценария загрузки, я ничего не вижу.

Как я могу получить контроль или увидеть экран сервера, если я запускаю его из загрузки и подключаюсь через ssh позже?

Я надеюсь, вы понимаете, о чем я. Заранее спасибо, и хорошего дня.

2

1 ответ на вопрос

3
chicks

The console output for most things started in the rc scripts is unavailable to you unless you attach to the physical console for your device. The same would be true if you started the MC server by hand and then logged out. You could log the output to a file, but that doesn't help you type commands into it later. Two tools are available to work around this issue: and . Either will hold onto the input and output handles for your process and let you reattach to them later. screen has been around forever but was not designed for automation. tmux is newer and not as well known, but it is much easier to automate so I'll demonstrate that:

tmux new-session -s demo -n tab_name -d "sudo top" 

Will start a new tmux session named demo with one tab in it named tab_name running sudo top. When you run this control returns to the shell and you won't see the top immediately. This is good because it means you can put it in your rc scripts and it won't stop them in their tracks. Then whenever you want to get to it simply:

tmux attach 

as the same user you started things with and you will have access to the input and output of the command. To escape tmux press ctrl-b, d which will take you back to your shell outside of tmux.

This is an intro you might find a good next step in learning tmux.

Похожие вопросы