1
0
Signed-off-by: Peter Siegmund <developer@mars3142.org>
This commit is contained in:
2026-01-17 15:37:34 +01:00
commit 2295825b35
5 changed files with 181 additions and 0 deletions

67
README.md Normal file
View File

@@ -0,0 +1,67 @@
# Hytale Server Systemd Setup
## Files
| File | Description | Target on Server |
|------|-------------|------------------|
| `hytale.service` | Main service for the server | `/etc/systemd/system/` |
| `hytale-update.sh` | Update script | `/opt/hytale/` |
| `hytale-update.service` | Service for updates | `/etc/systemd/system/` |
| `hytale-update.timer` | Timer for daily updates at 4 AM | `/etc/systemd/system/` |
## Installation on the Server
```bash
# 1. Copy files
sudo cp hytale.service /etc/systemd/system/
sudo cp hytale-update.service /etc/systemd/system/
sudo cp hytale-update.timer /etc/systemd/system/
cp hytale-update.sh /opt/hytale/
chmod +x /opt/hytale/hytale-update.sh
# 2. Create log file
sudo touch /var/log/hytale-update.log
sudo chown mars3142:mars3142 /var/log/hytale-update.log
# 3. Reload systemd
sudo systemctl daemon-reload
# 4. Enable and start server service
sudo systemctl enable hytale.service
sudo systemctl start hytale.service
# 5. Enable update timer
sudo systemctl enable hytale-update.timer
sudo systemctl start hytale-update.timer
```
## Useful Commands
```bash
# Server status
sudo systemctl status hytale.service
# Show server logs
sudo journalctl -u hytale.service -f
# Manually stop/start server
sudo systemctl stop hytale.service
sudo systemctl start hytale.service
sudo systemctl restart hytale.service
# Run update manually
sudo /opt/hytale/hytale-update.sh
# Check timer status
sudo systemctl list-timers | grep hytale
# Show update logs
cat /var/log/hytale-update.log
```
## Notes
- The server starts automatically after a reboot
- Updates are checked daily at 4:00 AM
- Already applied updates are stored in `/opt/hytale/.applied_updates`
- When an update is found, the server is automatically stopped, updated, and restarted

12
hytale-update.service Normal file
View File

@@ -0,0 +1,12 @@
[Unit]
Description=Hytale Server Update Service
After=network.target
[Service]
Type=oneshot
ExecStart=/opt/hytale/hytale-update.sh
User=root
Group=root
[Install]
WantedBy=multi-user.target

66
hytale-update.sh Normal file
View File

@@ -0,0 +1,66 @@
#!/bin/bash
#
# Hytale Server Update Script
# Runs the updater, extracts new files, and restarts the server
#
set -e
HYTALE_DIR="/opt/hytale"
LOG_FILE="/var/log/hytale-update.log"
log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" | tee -a "$LOG_FILE"
}
cd "$HYTALE_DIR"
log "Starting update check..."
# Run the updater to check for and download updates
# The updater downloads files like "2026-01-17-abcdef.zip"
./updater 2>&1 | tee -a "$LOG_FILE"
# Find the newest zip file (pattern: YYYY-MM-DD-*.zip)
NEWEST_ZIP=$(ls -t [0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]-*.zip 2>/dev/null | head -n1)
if [ -z "$NEWEST_ZIP" ]; then
log "No update zip found. Nothing to do."
exit 0
fi
# Check if this update was already applied
APPLIED_MARKER=".applied_updates"
if grep -Fxq "$NEWEST_ZIP" "$APPLIED_MARKER" 2>/dev/null; then
log "Update $NEWEST_ZIP was already applied. Skipping."
exit 0
fi
log "New update found: $NEWEST_ZIP"
# Stop the server
log "Stopping Hytale server..."
systemctl stop hytale.service || true
# Wait for server to fully stop
sleep 5
# Extract the update directly to /opt/hytale
log "Extracting $NEWEST_ZIP to $HYTALE_DIR..."
unzip -o "$NEWEST_ZIP" -d "$HYTALE_DIR"
# Fix file ownership (since this script runs as root)
chown -R mars3142:mars3142 "$HYTALE_DIR"
# Mark this update as applied
echo "$NEWEST_ZIP" >> "$APPLIED_MARKER"
# Start the server again
log "Starting Hytale server..."
systemctl start hytale.service
# Cleanup: keep only the 3 newest zip files
log "Cleaning up old zip files..."
ls -t [0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]-*.zip 2>/dev/null | tail -n +4 | xargs -r rm -f
log "Update complete!"

9
hytale-update.timer Normal file
View File

@@ -0,0 +1,9 @@
[Unit]
Description=Daily Hytale Server Update Check at 4:00 AM
[Timer]
OnCalendar=*-*-* 04:00:00
Persistent=true
[Install]
WantedBy=timers.target

27
hytale.service Normal file
View File

@@ -0,0 +1,27 @@
[Unit]
Description=Hytale Game Server
After=network.target
[Service]
Type=simple
User=mars3142
Group=mars3142
WorkingDirectory=/opt/hytale/Server
# SDKMAN Java path for user mars3142
Environment="JAVA_HOME=/home/mars3142/.sdkman/candidates/java/current"
Environment="PATH=/home/mars3142/.sdkman/candidates/java/current/bin:/usr/local/bin:/usr/bin:/bin"
ExecStart=/home/mars3142/.sdkman/candidates/java/current/bin/java -jar HytaleServer.jar --assets ../Assets.zip
Restart=on-failure
RestartSec=10
# Security hardening
NoNewPrivileges=true
ProtectSystem=strict
ReadWritePaths=/opt/hytale
ProtectHome=read-only
[Install]
WantedBy=multi-user.target