7

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?

3
  • Define "interact" - what do you need to do exactly? What/how would you do it if you started it manually?
    – Byte Commander
    Jan 12, 2017 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. Jan 12, 2017 at 20:21
  • Could you achieve your requirements by spawning the minecraft process in gnu screen ?
    – earthmeLon
    Jan 12, 2017 at 20:31

1 Answer 1

8

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 nogui   
    
  • This is what you'd do from command-line to find your session:

    screen -ls
    

    Example 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

2
  • 2
    An 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. Jan 12, 2017 at 22:22
  • 2
    P.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. Jan 12, 2017 at 22:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .