diff --git a/MINECRAFT.md b/MINECRAFT.md index 3a4a080..3465039 100644 --- a/MINECRAFT.md +++ b/MINECRAFT.md @@ -455,6 +455,58 @@ ssh docker-host2 'tail -f ~/crafty/data/servers/hutworld/logs/latest.log' ## Troubleshooting +### Plugin Permission Issues (IMPORTANT) + +**Root Cause**: Crafty Docker container requires all files to be owned by `:root` (not `:`) for permissions to work correctly. + +**Permanent Fix**: +```bash +# Fix all permissions immediately +ssh docker-host2 'sudo chown -R hutson:root ~/crafty/data/servers/ && \ + sudo find ~/crafty/data/servers/ -type d -exec chmod 2775 {} \; && \ + sudo find ~/crafty/data/servers/ -type f -exec chmod 664 {} \;' +``` + +**Prevention**: +1. **Always upload plugins through Crafty web UI** - this ensures correct permissions +2. **Or use the import directory**: Copy to `~/crafty/data/import/` then restart container +3. **Never directly copy files** to the servers directory + +**Check for permission issues**: +```bash +# Use the permission check script (recommended) +ssh docker-host2 '~/check-crafty-permissions.sh' + +# Or manually check for wrong group ownership +ssh docker-host2 'find ~/crafty/data/servers -type f ! -group root -ls' +ssh docker-host2 'find ~/crafty/data/servers -type d ! -group root -ls' +``` + +**Permission Check Script**: Located at `~/check-crafty-permissions.sh` on docker-host2 +- Automatically detects permission issues +- Offers to fix them with one command +- Ignores temporary files that are expected to have different permissions + +### Crafty Shows Server Offline or "Another Instance Running" + +**Cause**: This happens when the server was started manually (not through Crafty) or when Crafty loses track of the server process. + +**Fix**: +```bash +# 1. Kill any orphaned server processes +ssh docker-host2 'docker exec crafty pkill -f "paper.jar"' + +# 2. Restart Crafty container to clear state +ssh docker-host2 'cd ~/crafty && docker compose restart' + +# 3. Wait 30-60 seconds - Crafty will auto-start the server +``` + +**Prevention**: +- Always use Crafty web UI to start/stop servers +- Never manually start the server with java command +- If you must restart, use the container restart method above + ### Server won't start ```bash diff --git a/scripts/check-crafty-permissions.sh b/scripts/check-crafty-permissions.sh new file mode 100644 index 0000000..1d25c50 --- /dev/null +++ b/scripts/check-crafty-permissions.sh @@ -0,0 +1,114 @@ +#!/bin/bash +# Crafty Permission Checker Script +# Checks for permission issues that could break plugin functionality + +echo "Crafty Permission Check - $(date)" +echo "================================" + +# Base directory +CRAFTY_DIR="/home/hutson/crafty/data/servers" + +# Check if running on docker-host2 +if [ "$(hostname)" != "docker-host2" ]; then + echo "āš ļø This script should be run on docker-host2" + echo " Use: ssh docker-host2 '~/check-crafty-permissions.sh'" + exit 1 +fi + +# Function to check permissions +check_permissions() { + local issues_found=0 + + # Check for files not owned by root group + echo -e "\nšŸ“ Checking file ownership..." + wrong_group=$(find "$CRAFTY_DIR" -type f ! -group root 2>/dev/null) + if [ ! -z "$wrong_group" ]; then + echo "āŒ Files with incorrect group (should be 'root'):" + echo "$wrong_group" | head -10 + issues_found=$((issues_found + 1)) + else + echo "āœ… All files have correct group ownership (root)" + fi + + # Check for directories not owned by root group + echo -e "\nšŸ“ Checking directory ownership..." + wrong_dir_group=$(find "$CRAFTY_DIR" -type d ! -group root 2>/dev/null) + if [ ! -z "$wrong_dir_group" ]; then + echo "āŒ Directories with incorrect group (should be 'root'):" + echo "$wrong_dir_group" | head -10 + issues_found=$((issues_found + 1)) + else + echo "āœ… All directories have correct group ownership (root)" + fi + + # Check for directories without setgid bit + echo -e "\nšŸ”’ Checking setgid bit on directories..." + no_setgid=$(find "$CRAFTY_DIR" -type d ! -perm -g+s 2>/dev/null) + if [ ! -z "$no_setgid" ]; then + echo "āš ļø Directories without setgid bit (may cause future issues):" + echo "$no_setgid" | head -10 + issues_found=$((issues_found + 1)) + else + echo "āœ… All directories have setgid bit set" + fi + + # Check for files that crafty user can't read (excluding temp files) + echo -e "\nšŸ“– Checking read permissions..." + unreadable=$(find "$CRAFTY_DIR" -type f ! -perm -g+r ! -name "*.tmp" 2>/dev/null) + if [ ! -z "$unreadable" ]; then + echo "āŒ Files that crafty user can't read:" + echo "$unreadable" | head -10 + issues_found=$((issues_found + 1)) + else + echo "āœ… All files are readable by crafty user" + fi + + return $issues_found +} + +# Function to fix permissions +fix_permissions() { + echo -e "\nšŸ”§ Fixing permissions..." + + # Fix ownership + sudo chown -R hutson:root "$CRAFTY_DIR" + + # Fix directory permissions (2775 = rwxrwsr-x) + sudo find "$CRAFTY_DIR" -type d -exec chmod 2775 {} \; + + # Fix file permissions (664 = rw-rw-r--) + sudo find "$CRAFTY_DIR" -type f -exec chmod 664 {} \; + + echo "āœ… Permissions fixed!" +} + +# Main execution +echo "Checking Crafty server permissions..." +check_permissions +result=$? + +if [ $result -gt 0 ]; then + echo -e "\nāš ļø Found $result permission issue(s)!" + echo -n "Would you like to fix them automatically? (y/n): " + read -r response + if [[ "$response" =~ ^[Yy]$ ]]; then + fix_permissions + echo -e "\nšŸ”„ Re-checking permissions..." + check_permissions + if [ $? -eq 0 ]; then + echo -e "\nāœ… All permission issues resolved!" + else + echo -e "\nāŒ Some issues remain. You may need to restart the Crafty container." + fi + else + echo -e "\nTo fix manually, run:" + echo "sudo chown -R hutson:root $CRAFTY_DIR" + echo "sudo find $CRAFTY_DIR -type d -exec chmod 2775 {} \;" + echo "sudo find $CRAFTY_DIR -type f -exec chmod 664 {} \;" + fi +else + echo -e "\nāœ… No permission issues found!" +fi + +echo -e "\n================================" +echo "Check complete - $(date)" \ No newline at end of file