Giter Club home page Giter Club logo

containercarpetserver's Introduction

ContainerCarpetServer

Containerized Servers for Technical Minecraft

Introduction

This project aims to provide a system for running a Fabric Minecraft server(with Carpet!) inside a Podman(or Docker) container for improved security.

The project is developed for and tested with Podman, but Docker likely works near identically. OpenRC currently the only supported init system, but it should not be too hard to write a service script for SystemD. Feel free to submit a PR if you write a script for SystemD to use with this project.

This branch aims to support the latest version of Minecraft, but it should not be hard to make this work with older versions as well. Feel free to submit a PR to support other versions.

Current Minecraft Version: 1.19.2

Installation

Prerequisites

  • Linux
  • Podman
  • OpenRC

System Setup

  1. Create a new user. For example:
    useradd -m -G <GROUPS> -s /bin/bash <USERNAME>
    Include group wheel to allow temporary root access.

  2. Login as the new user.

  3. Create a directory to store server persistent server files in. For example:
    mkdir ~/server/

Installation

  1. While logged in as a non-root user, pull the Container Image from DockerHub.
    podman pull docker.io/thecydonian/container_carpet_server:latest

  2. Run the Container with the following command. Replace <VOLUME PATH> with the absolute path to your persistent server files directory (e.g. /home/minecraft/server/).

podman container run \
          --tty \
          --interactive \
          --volume <VOLUME PATH>:/server/:U,Z \
          --publish 25565:25565/tcp \
          container_carpet_server:latest
  1. After populating your volume directory by installing Fabric, Carpet, and Lithium, the container should fail since you have not agreed to the EULA yet. Run podman unshare vi <VOLUME PATH>/eula.txt or replace vi with your preferred editor. Once the file is open, replace eula=false with eula=true. Note: Since the volume directory is now owned by a non-root user inside the container, to modify contained files, any command must follow podman unshare to run it in the correct namespace.

  2. Run podman start -l to restart the container. It should now run properly, and you should be able to connect to the server on the host system's IP address on port 25565.

OpenRC Setup

To automate starting and stopping the server, we can use OpenRC. Setup is simple.

  1. Clone this repository:
    git clone https://github.com/theCydonian/ContainerCarpetServer.git

  2. Enter the repository: cd ContainerCarpetServer/

  3. Modify the init script where necessary. Set the volume_path variable to the absolute path to your volume directory and set the command_user variable to be your user. You can edit the file with:
    vi openrc/container-carpet-server

  4. Copy init script to /etc/init.d/ as root. This can be accomplished by running:
    sudo cp openrc/container-carpet-server /etc/init.d/

  5. Start the service.
    sudo rc-service container-carpet-server start

  6. Set this service to start on boot.
    sudo rc-update add container-carpet-server default

Backups

Keeping server backups is usually a good idea in case anything goes wrong. We are going to use cronie to perform daily backups.

For example, after running crontab -e, simply input the following line:

  00 00 *  *  *  /home/minecraft/backup.sh

Alternatively this can be added to /etc/crontab.

At midnight every day this backup script will run as root.

Change the user to the user you run the container under, and change the script location to where you store the backup script. You can also change the frequency of backups. The Useful Links section of this README has information on how to use the /etc/crontab file.

Here is an example backup.sh:

#!/bin/bash
date=$(date +"%Y%m%d%H%M%S%3N")
tar -czf /path/to/backup/dir/${date}.tar.gz \
--directory=/path/to/volume/dir/ .

Useful Tips

  1. You can set an alternative startup command by placing a startup.sh to be run inside the volume directory.
  2. When configuring your server, run commands under podman unshare for the correct permissions.
  3. You can attach to your running server container with podman attach -l.
  4. You can detach from a running container with ctrl+p then ctrl+q.

Useful Links

Projects Used

containercarpetserver's People

Contributors

thecydonian avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.