I have a script that runs from rc.local (a minecraft server in this case) with which I need to be able to interact (connect to its STDIN and STDOUT later). How can I do this?
Asked
Active
Viewed 564 times
7
muru
- 193,181
- 53
- 473
- 722
Th3Harbinger
- 91
- 4
-
Define "interact" - what do you need to do exactly? What/how would you do it if you started it manually? – Byte Commander Jan 12 '17 at 20:14
-
When started manually, it launches an interactive prompt where you can issue commands, OP users, change settings, restart the server, and other such things. – Th3Harbinger Jan 12 '17 at 20:21
-
Could you achieve your requirements by spawning the minecraft process in gnu `screen` ? – earthmeLon Jan 12 '17 at 20:31
1 Answers
7
What you want to do is use screen. It allows spawning a process inside its session and detaching from it. Essentially , your question is similar to this.
The 3 steps that you want to do:
The line below has to go into your
/etc/rc.local. Add&sign at the end of it ( important !)screen -S MyMinecraftServer -d -m java -jar ./SOMEFILES/CLEANUP/minecraft_server.1.8.8.jar noguiThis is what you'd do from command-line to find your session:
screen -lsExample output:
There is a screen on: 1720.MyMinecraftServer (2017年01月12日 13时54分36秒) (Detached) 1 Socket in /var/run/screen/S-xieerqi.And this is how you attach to it:
screen -x 1720.MyMinecraftServer
NOTE: starting minecraft server from /etc/rc.local can be a potential security hole. Consider using su username -c '<screen command here>' & to run the server as a different user. See also : https://serverfault.com/a/422952/363611
Sergiy Kolodyazhnyy
- 103,293
- 19
- 273
- 492
-
2An alternative to `screen` would be the somewhat more modern `tmux`. The principle remains the same though the command-line options are all a little different. – David Foerster Jan 12 '17 at 22:22
-
2P.S.: Since you're doing all of this from `rc.local`: you shouldn't run a Minecraft server with super-user privileges – especially if it's ports are publicly accessible. – David Foerster Jan 12 '17 at 22:25