-
Notifications
You must be signed in to change notification settings - Fork 12
feat: Add Bedrock systemd service file #61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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
There was a problem hiding this 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".
| 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 👍 / 👎.
There was a problem hiding this 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.servicewith 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 |
Copilot
AI
Nov 15, 2025
There was a problem hiding this comment.
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.
| WorkingDirectory=/opt/minecraft-bedrock | |
| WorkingDirectory=/opt/minecraft-bedrock | |
| ExecStartPre=/usr/bin/install -d -m 0775 -o root -g utmp /run/screen |
| ExecStart=/usr/bin/screen -DmS bedrock /bin/bash -lc './start.sh' | ||
| ExecStop=/usr/bin/screen -S bedrock -X quit |
Copilot
AI
Nov 15, 2025
There was a problem hiding this comment.
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:
- Change to
Type=forkingto handle the screen detachment correctly, OR - Remove screen entirely and run the server directly (like
minecraft.servicedoes) withExecStart=/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.
| 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 |
| 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 |
Copilot
AI
Nov 15, 2025
There was a problem hiding this comment.
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.
| 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' |
| Description=Minecraft Bedrock Server | ||
| After=network-online.target | ||
| Wants=network-online.target | ||
| StartLimitIntervalSec=0 |
Copilot
AI
Nov 15, 2025
There was a problem hiding this comment.
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.
| StartLimitIntervalSec=0 |
| ExecStop=/usr/bin/screen -S bedrock -X quit | ||
| Restart=on-failure | ||
| RestartSec=5s | ||
| RestartSec=5 |
Copilot
AI
Nov 15, 2025
There was a problem hiding this comment.
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
| RestartSec=5 | |
| RestartSec=5s |
Summary
Adds
minecraft-bedrock.servicesystemd unit file to the repository.Resolves #47
Changes
minecraft-bedrock.serviceminecraftuser with proper isolationInstallation
sudo cp minecraft-bedrock.service /etc/systemd/system/ sudo systemctl daemon-reload sudo systemctl enable --now minecraft-bedrockTesting
Service file follows the same hardening patterns as
minecraft.service(Java Edition).Checklist
minecraft.servicestructure