I'm working on MSCT, a little Minecraft server administration utility for personal use (for now). I'm starting the server in a screen session, and it's working just fine. I'm just having no luck getting the screen to start attached or getting MSCT to resume the screen.
Repo is here: https://github.com/nathanpaulyoung/msct/blob/master/msct.go
The relevant function on line 48 is:
resumeCommand()
And here's a snippet:
func resumeCommand() cli.Command {
command := cli.Command{
Name: "resume",
Aliases: []string{"r"},
Usage: "resume a server's screen session",
Action: func(c *cli.Context) {
servername := c.Args().First()
screenname := buildScreenName(servername)
args := []string{"-x", screenname}
cmd := exec.Command("screen", args...)
if serverExists(servername) {
output, _ := cmd.Output()
println(output)
} else {
println("No server known by the name \"" + servername + "\". Either server.jar is missing or the server directory was not configured before compilation.")
os.Exit(999)
}
},
}
return command
}
I feel like it must be something I am simply unaware of, like some sort of special way to invoke a new tty or something. If any of you know of the solution, please chip in with advice or a pull request.
That said, I've been thinking more about the real goal here, and figured I'd mention that, in case that yields a solution that is equally satisfactory if not what I expected. I want the Minecraft server to continue running even when I'm not actively looking at the server console. Whether that means when I'm not currently ssh'd in to the box it's running on, or (in the case of screen) not actually connected to the screen session, it should keep running without my eyes on it. If there's a way to, perhaps, pipe screen content into a custom golang terminal session using https://golang.org/x/crypto/ssh/terminal, or a way to create something similar to screen wherein the Minecraft server can run, those would be just as satisfactory.