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?

muru
  • 207,228

1 Answers1

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