Results 1 to 5 of 5

Thread: Help with screen

  1. #1
    Join Date
    Feb 2021
    Beans
    2

    Help with screen

    Hello, I am running a mc sever on a Ubuntu Server 20.04 LTS. I’ve recently started using screen to run my sever but whenever I close my terminal from my pc I’m unable to bring up that screen page. Any help would be very helpful

  2. #2
    Join Date
    Oct 2006
    Beans
    57,593

    Re: Help with screen

    Thread moved to the "Server Platforms" forum.

  3. #3
    Join Date
    Sep 2011
    Location
    Behind you!
    Beans
    1,533
    Distro
    Ubuntu 20.04 Focal Fossa

    Re: Help with screen

    I can help you with that. Forgive me if I present typos or forget steps/commands....its been a long time since I setup a Minecraft server.

    I assume you are wanting to run multiple Minecraft servers so I will show you how this is done with 2 servers running 2 different accounts so you can see what changes in each of the commands used and what stays the same.

    The 1st step is to create low-rights groups/users that cannot login via SSH or the console and grant that user ownership/permissions to your Minecraft folder/sub-folders.

    Example:
    Code:
    sudo mkdir -p /opt/minecraft
    sudo addgroup minecraft
    sudo chown root:minecraft /opt/minecraft
    sudo chmod 0750 /opt/minecraft
    sudo useradd --comment "Minecraft Server" --shell /bin/false --home /opt/minecraft/spigot --gid minecraft spigot
    sudo useradd --comment "Minecraft Server" --shell /bin/false --home /opt/minecraft/hungergames --gid minecraft hungergames
    Substitute your own server path(s) and user accounts you want to use.

    Place the server files in the destination locations. The absolute minimum is the server.jar file and eula.txt file.

    Make sure the ownership and permissions are set correctly for initial setup and after the server has started and created its files/folders. Run these commands after getting the files in place and before you run the server the 1st time. Then again after stopping the server. You could schedule these to run inside a script that runs daily or in the startup/shutdown scripts you use to start/stop the servers to ensure permissions are always correct...and make adjustments as necessary.

    Code:
    chown --recursive spigot:minecraft /opt/minecraft/spigot
    find /opt/minecraft/spigot -type d -exec chmod 0750 {} \;
    find /opt/minecraft/spigot -type f -exec chmod 0640 {} \;
    chmod --recursive 440 /opt/minecraft/spigot/*.jar
    Code:
    chown --recursive hungergames:minecraft /opt/minecraft/hungergames
    find /opt/minecraft/hungergames -type d -exec chmod 0750 {} \;
    find /opt/minecraft/hungergames -type f -exec chmod 0640 {} \;
    chmod --recursive 440 /opt/minecraft/hungergames/*.jar
    You then start Minecraft using that account inside a screen session. You never actually login using that account. You just run screen/Minecraft with that account.

    Here is the crux to the main command to start Minecraft:

    Code:
    su spigot --command "screen -d -m -S spigot -t spigot java -d64 -XX:MaxPermSize=256M -Xincgc -Xmx4096 -jar /opt/minecraft/spigot/server.jar --log-strip-color"
    The user in the above example is called "spigot" as signified in the switch user part: "su spigot"
    I also used the same name for the screen session name "-S spigot" and the screen title "-t spigot" but that is not important other than signifying which user is attached to that screen when you have many screens running.
    The folder path used is /opt/minecraft/spigot/ in this example. Others could be placed in similar location reflecting a different username/folder such as hungergames "/opt/minecraft/hungergames/"

    Once the screen session is running, you need a way to send console commands such as the command to "stop" the server.

    Here is an example for stopping the server that was started from the example above using the "spigot" user:

    Code:
    su spigot --command "screen -S spigot -p spigot -X stuff \"stop\""
    su spigot --command "screen -S spigot -p spigot -X eval \"stuff \015\""
    Here is an example for stopping the server that was started from the example above using the "hungergames" user:

    Code:
    su spigot --command "screen -S hungergames -p hungergames -X stuff \"stop\""
    su spigot --command "screen -S hungergames -p hungergames -X eval \"stuff \015\""
    The user is switched to the specified user (spigot or hungergames in these examples) and runs the screen command specifying the session and pre-selects the screen window and pushes the characters stop but because the command is already encased in quotes because of --command, we must escape the quote used to encase the stuff parameter which just means you add a backslash for each of the inside quotes used.

    The 2nd line does the same thing but presses the carriage return key which is needed or the console will never execute what was typed in. The ASCII value for carriage return is 015 and the eval lets it translate that code into the actual return key.

    All of this and more can be placed in scripts to help automate everything. Daily reboots, shutdown notifications, repeating messages to online players, etc.

    I think I have covered your question as thorough as I can. Feel free to ask for more clarification if needed.

    LHammonds
    Last edited by LHammonds; February 18th, 2021 at 02:21 PM.

  4. #4
    Join Date
    Aug 2020
    Location
    Denmark
    Beans
    70
    Distro
    Ubuntu 20.04 Focal Fossa

    Re: Help with screen

    Quote Originally Posted by LHammonds View Post
    its been a long time since I setup a Minecraft server.
    I was at a loss at first, but then noticed the very subtle "mc server" - I didn't spot it had anything to do with minecraft at first.
    Last edited by ameinild; February 18th, 2021 at 03:23 PM.
    Supermicro Server :: Atom C3558 (4) @ 2.2 GHz :: 32 GB DDR4-2400 :: 512 GB NVMe :: 4x 2 TB SSD @ RAID-Z :: 1x Raspberry Pi 4 Server

    Scripts: directory-tools | rsync-backup | add-apt-key

  5. #5
    Join Date
    Feb 2021
    Beans
    2

    Re: Help with screen

    Thank you very much for the help. It seems to be working great so far

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •