Skip to content

Conversation

@TimInTech
Copy link
Owner

Summary

Adds minecraft-bedrock.service systemd unit file to the repository.

Resolves #47

Changes

  • ✨ New file: minecraft-bedrock.service
  • 🔒 Includes systemd hardening options (NoNewPrivileges, ProtectSystem, ProtectHome, etc.)
  • 🔄 Automatic restart on failure with 5s delay
  • 📺 Uses screen for console access compatibility
  • 👤 Runs as minecraft user with proper isolation

Installation

sudo cp minecraft-bedrock.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now minecraft-bedrock

Testing

Service file follows the same hardening patterns as minecraft.service (Java Edition).

Checklist

  • Service file created with hardening options
  • Matches existing minecraft.service structure
  • Documented in README (inline example already exists)
  • Resolves open issue Restore Bedrock systemd example #47

Resolves #47

- Provides minecraft-bedrock.service for systemd auto-start
- Includes hardening options (NoNewPrivileges, ProtectSystem, etc.)
- Uses screen for console access compatibility
- Automatic restart on failure with 5s delay
Copilot AI review requested due to automatic review settings November 15, 2025 12:14
@TimInTech TimInTech merged commit 79e9b91 into main Nov 15, 2025
6 checks passed
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +8 to +13
Type=simple
User=minecraft
Group=minecraft
WorkingDirectory=/opt/minecraft-bedrock
ExecStart=/opt/minecraft-bedrock/start.sh
ExecStart=/usr/bin/screen -DmS bedrock /bin/bash -lc './start.sh'
ExecStop=/usr/bin/screen -S bedrock -X quit

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Detaching with screen prevents systemd from tracking the server

The new ExecStart=/usr/bin/screen -DmS … line starts the Bedrock server inside a detached screen session while the main ExecStart process exits immediately. With the unit still declared as Type=simple (the default), systemd considers the service started and then immediately inactive because the command returns, so the running screen process is no longer managed. In this state Restart=on-failure and the new ExecStop never run, systemctl status shows the unit as dead, and systemctl stop/restart will not terminate the running server. This regression effectively disables systemd supervision and restarts for Bedrock servers started with this unit.

Useful? React with 👍 / 👎.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a systemd service file for Minecraft Bedrock Edition servers, enabling automatic startup, restart on failure, and systemd management capabilities. The service includes hardening options similar to the existing Java Edition service.

  • Adds minecraft-bedrock.service with systemd hardening options
  • Implements screen-based console access for Bedrock servers
  • Configures automatic restart behavior with 5-second delay

Type=simple
User=minecraft
Group=minecraft
WorkingDirectory=/opt/minecraft-bedrock
Copy link

Copilot AI Nov 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ExecStart command uses screen which requires /run/screen to exist with specific permissions (root:utmp, 0775). After a system reboot, this directory may not exist, causing the service to fail. Add an ExecStartPre directive to ensure the directory is created:

ExecStartPre=/usr/bin/install -d -m 0775 -o root -g utmp /run/screen

This matches the setup done in setup_bedrock.sh (lines 67-69) and ensures the service can start reliably after reboots.

Suggested change
WorkingDirectory=/opt/minecraft-bedrock
WorkingDirectory=/opt/minecraft-bedrock
ExecStartPre=/usr/bin/install -d -m 0775 -o root -g utmp /run/screen

Copilot uses AI. Check for mistakes.
Comment on lines +12 to +13
ExecStart=/usr/bin/screen -DmS bedrock /bin/bash -lc './start.sh'
ExecStop=/usr/bin/screen -S bedrock -X quit
Copy link

Copilot AI Nov 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using Type=simple with screen -DmS is problematic because screen with the -D flag detaches immediately, and systemd will incorrectly track the service state. Either:

  1. Change to Type=forking to handle the screen detachment correctly, OR
  2. Remove screen entirely and run the server directly (like minecraft.service does) with ExecStart=/opt/minecraft-bedrock/start.sh

The second option is recommended for consistency with the Java edition service and simpler systemd integration. Console access can still be achieved through journalctl -fu minecraft-bedrock instead of screen.

Suggested change
ExecStart=/usr/bin/screen -DmS bedrock /bin/bash -lc './start.sh'
ExecStop=/usr/bin/screen -S bedrock -X quit
ExecStart=/bin/bash -lc './start.sh'
ExecStop=/bin/kill -TERM $MAINPID

Copilot uses AI. Check for mistakes.
WorkingDirectory=/opt/minecraft-bedrock
ExecStart=/opt/minecraft-bedrock/start.sh
ExecStart=/usr/bin/screen -DmS bedrock /bin/bash -lc './start.sh'
ExecStop=/usr/bin/screen -S bedrock -X quit
Copy link

Copilot AI Nov 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ExecStop command will fail silently if the screen session doesn't exist or has already terminated. Consider adding a more robust stop command that checks if the session exists first:

ExecStop=/bin/bash -c '/usr/bin/screen -ls bedrock >/dev/null 2>&1 && /usr/bin/screen -S bedrock -X quit || true'

Alternatively, if screen is removed (see previous comment), this line can be deleted entirely as systemd will handle process termination.

Suggested change
ExecStop=/usr/bin/screen -S bedrock -X quit
ExecStop=/bin/bash -c '/usr/bin/screen -ls bedrock >/dev/null 2>&1 && /usr/bin/screen -S bedrock -X quit || true'

Copilot uses AI. Check for mistakes.
Description=Minecraft Bedrock Server
After=network-online.target
Wants=network-online.target
StartLimitIntervalSec=0
Copy link

Copilot AI Nov 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The StartLimitIntervalSec=0 setting disables systemd's start rate limiting entirely, which could lead to a rapid restart loop if the service fails repeatedly. This is inconsistent with minecraft.service which doesn't set this option (using systemd's default of 10 seconds / 5 starts).

Consider removing this line or using a more reasonable value like StartLimitIntervalSec=600 (10 minutes) to allow recovery from transient failures while preventing resource exhaustion from infinite restart loops.

Suggested change
StartLimitIntervalSec=0

Copilot uses AI. Check for mistakes.
ExecStop=/usr/bin/screen -S bedrock -X quit
Restart=on-failure
RestartSec=5s
RestartSec=5
Copy link

Copilot AI Nov 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Inconsistency: minecraft.service uses RestartSec=5s (with unit suffix) while this service uses RestartSec=5 (without unit). While both are valid (systemd defaults to seconds), it's better to use consistent formatting across service files. Consider adding the s suffix: RestartSec=5s

Suggested change
RestartSec=5
RestartSec=5s

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Restore Bedrock systemd example

2 participants