Tutorial

Neue Updates und Verbesserungen zu Macfleet.

Wichtiger Hinweis

Die in diesen Tutorials bereitgestellten Codebeispiele und Skripte dienen nur zu Bildungszwecken. Macfleet ist nicht verantwortlich für Probleme, Schäden oder Sicherheitslücken, die durch die Verwendung, Änderung oder Implementierung dieser Beispiele entstehen können. Überprüfen und testen Sie Code immer in einer sicheren Umgebung, bevor Sie ihn in Produktionssystemen verwenden.

Managing Spotlight Indexing on macOS Devices

Spotlight is macOS's powerful system-wide search feature that helps users quickly locate files, documents, applications, emails, and more across their system. While Spotlight provides excellent search capabilities, its continuous background indexing can sometimes impact system performance, particularly on older hardware or resource-constrained environments. This comprehensive guide provides methods to manage Spotlight indexing effectively.

Understanding Spotlight and Its Impact

Spotlight uses a sophisticated indexing system that continuously scans and catalogs content on your Mac to provide instant search results. This indexing process involves:

  • File content analysis: Reading and indexing text within documents
  • Metadata extraction: Cataloging file properties, creation dates, and tags
  • Application indexing: Tracking installed applications and their data
  • Email and message indexing: Indexing Mail, Messages, and other communication apps
  • Real-time updates: Monitoring file system changes to keep the index current

Why Manage Spotlight Indexing?

There are several scenarios where managing Spotlight indexing becomes necessary:

  • Performance optimization: Reducing CPU and disk usage on resource-limited systems
  • Privacy concerns: Preventing indexing of sensitive files and directories
  • Storage management: Saving disk space used by index files
  • Troubleshooting: Resolving search issues or corrupted indexes
  • Enterprise deployment: Standardizing search behavior across managed devices
  • Development environments: Preventing indexing of build directories and temporary files

Prerequisites

Before managing Spotlight indexing, ensure you have:

  • Administrative privileges on the Mac
  • Terminal or SSH access
  • Understanding of the impact on search functionality
  • Backup of important data (recommended)

Basic Spotlight Management Commands

Understanding mdutil

The mdutil command is the primary tool for managing Spotlight indexing:

# Check indexing status
mdutil -s /

# Enable indexing for a volume
mdutil -i on /

# Disable indexing for a volume
mdutil -i off /

# Erase and rebuild index
mdutil -E /

# Get help
mdutil -h

Checking Current Indexing Status

Before making changes, check the current indexing status:

#!/bin/bash

# Check Spotlight indexing status for all volumes
echo "Spotlight Indexing Status Report"
echo "==============================="
echo "Date: $(date)"
echo ""

# Get all mounted volumes
volumes=$(df -h | grep "^/dev" | awk '{print $9}')

echo "Volume Indexing Status:"
echo "----------------------"

for volume in $volumes; do
    if [ -d "$volume" ]; then
        status=$(mdutil -s "$volume" 2>/dev/null | grep "Indexing enabled")
        echo "$volume: $status"
    fi
done

echo ""
echo "Active indexing processes:"
ps aux | grep -i mds | grep -v grep

Disabling Spotlight Indexing

Basic Disable Script

Simple script to disable Spotlight indexing on the main volume:

#!/bin/bash

# Disable Spotlight indexing on the root volume
echo "Disabling Spotlight indexing..."

if sudo mdutil -i off /; then
    echo "✓ Spotlight indexing disabled successfully"
    
    # Verify the change
    status=$(mdutil -s / | grep "Indexing enabled")
    echo "Current status: $status"
else
    echo "✗ Failed to disable Spotlight indexing"
    exit 1
fi

echo "Note: Search functionality will be limited until indexing is re-enabled"

Advanced Disable Script with Logging

More comprehensive script with logging and verification:

#!/bin/bash

# Advanced Spotlight disable script with logging
LOG_FILE="/var/log/spotlight_management.log"
TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')

# Function to log messages
log_message() {
    echo "[$TIMESTAMP] $1" | tee -a "$LOG_FILE"
}

# Function to disable indexing for a volume
disable_indexing() {
    local volume=$1
    
    log_message "Attempting to disable indexing for volume: $volume"
    
    # Check if volume exists
    if [ ! -d "$volume" ]; then
        log_message "ERROR: Volume $volume does not exist"
        return 1
    fi
    
    # Check current status
    current_status=$(mdutil -s "$volume" 2>/dev/null)
    log_message "Current status for $volume: $current_status"
    
    # Disable indexing
    if sudo mdutil -i off "$volume"; then
        log_message "SUCCESS: Indexing disabled for $volume"
        
        # Verify the change
        new_status=$(mdutil -s "$volume" 2>/dev/null)
        log_message "New status for $volume: $new_status"
        
        return 0
    else
        log_message "ERROR: Failed to disable indexing for $volume"
        return 1
    fi
}

# Main execution
log_message "Starting Spotlight indexing disable process"

# Disable for root volume
if disable_indexing "/"; then
    log_message "Root volume indexing disabled successfully"
else
    log_message "Failed to disable root volume indexing"
    exit 1
fi

# Optional: Disable for other volumes
# Uncomment the following lines to disable for additional volumes
# disable_indexing "/Volumes/ExternalDrive"
# disable_indexing "/Users"

log_message "Spotlight indexing disable process completed"
echo "Process completed. Check log at: $LOG_FILE"

Batch Disable for Multiple Volumes

Script to disable indexing on multiple volumes:

#!/bin/bash

# Batch disable Spotlight indexing for multiple volumes
VOLUMES=(
    "/"
    "/Users"
    "/Applications"
    # Add more volumes as needed
)

echo "Batch Spotlight Indexing Disable"
echo "================================"
echo "Date: $(date)"
echo ""

successful=0
failed=0

for volume in "${VOLUMES[@]}"; do
    echo "Processing volume: $volume"
    
    if [ -d "$volume" ]; then
        if sudo mdutil -i off "$volume" 2>/dev/null; then
            echo "  ✓ Successfully disabled indexing for $volume"
            ((successful++))
        else
            echo "  ✗ Failed to disable indexing for $volume"
            ((failed++))
        fi
    else
        echo "  ⚠ Volume $volume does not exist, skipping"
    fi
done

echo ""
echo "Summary:"
echo "--------"
echo "Successfully disabled: $successful volumes"
echo "Failed: $failed volumes"

if [ $failed -gt 0 ]; then
    echo "Some operations failed. Check individual volume status manually."
    exit 1
fi

Removing Spotlight Index Files

Basic Cleanup Script

After disabling indexing, remove existing index files to free up space:

#!/bin/bash

# Remove Spotlight index files
echo "Removing Spotlight index files..."

# Remove .Spotlight-V100 directories (modern macOS)
if sudo rm -rf /.Spotlight-V100; then
    echo "✓ Removed .Spotlight-V100 directory"
else
    echo "⚠ No .Spotlight-V100 directory found or removal failed"
fi

# Remove legacy .Spotlight directories
if sudo rm -rf /.Spotlight*; then
    echo "✓ Removed legacy Spotlight directories"
else
    echo "⚠ No legacy Spotlight directories found"
fi

# Calculate space freed
echo "Spotlight index cleanup completed"

Advanced Cleanup with Size Calculation

More detailed cleanup script that shows space savings:

#!/bin/bash

# Advanced Spotlight index cleanup with size reporting
echo "Spotlight Index Cleanup Utility"
echo "==============================="
echo "Date: $(date)"
echo ""

# Function to get directory size
get_size() {
    local dir=$1
    if [ -d "$dir" ]; then
        du -sh "$dir" 2>/dev/null | cut -f1
    else
        echo "0B"
    fi
}

# Function to remove spotlight directories
cleanup_spotlight_dirs() {
    local base_path=$1
    local total_size=0
    
    echo "Cleaning up Spotlight directories in: $base_path"
    
    # Find all Spotlight directories
    spotlight_dirs=$(find "$base_path" -name ".Spotlight*" -type d 2>/dev/null)
    
    if [ -z "$spotlight_dirs" ]; then
        echo "  No Spotlight directories found"
        return 0
    fi
    
    for dir in $spotlight_dirs; do
        size=$(get_size "$dir")
        echo "  Found: $dir ($size)"
        
        if sudo rm -rf "$dir"; then
            echo "    ✓ Removed successfully"
        else
            echo "    ✗ Failed to remove"
        fi
    done
}

# Clean up common locations
cleanup_spotlight_dirs "/"
cleanup_spotlight_dirs "/Users"

# Clean up on external volumes if any
for volume in /Volumes/*; do
    if [ -d "$volume" ]; then
        echo ""
        cleanup_spotlight_dirs "$volume"
    fi
done

echo ""
echo "Spotlight index cleanup completed"
echo "Run 'df -h' to see updated disk usage"

Enabling Spotlight Indexing

Basic Enable Script

Simple script to re-enable Spotlight indexing:

#!/bin/bash

# Enable Spotlight indexing on the root volume
echo "Enabling Spotlight indexing..."

if sudo mdutil -i on /; then
    echo "✓ Spotlight indexing enabled successfully"
    
    # Verify the change
    status=$(mdutil -s / | grep "Indexing enabled")
    echo "Current status: $status"
    
    echo ""
    echo "Note: Indexing will begin automatically and may take some time to complete"
    echo "You can monitor progress using Spotlight search"
else
    echo "✗ Failed to enable Spotlight indexing"
    exit 1
fi

Advanced Enable with Progress Monitoring

Script that enables indexing and provides progress monitoring:

#!/bin/bash

# Advanced Spotlight enable script with progress monitoring
LOG_FILE="/var/log/spotlight_management.log"
TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')

# Function to log messages
log_message() {
    echo "[$TIMESTAMP] $1" | tee -a "$LOG_FILE"
}

# Function to monitor indexing progress
monitor_indexing() {
    local volume=$1
    local timeout=60  # Monitor for 60 seconds
    local elapsed=0
    
    echo "Monitoring indexing progress for $volume..."
    
    while [ $elapsed -lt $timeout ]; do
        # Check if indexing is in progress
        if ps aux | grep -v grep | grep -q "mds_stores\|mdworker"; then
            echo "  Indexing in progress... (${elapsed}s elapsed)"
        else
            echo "  Indexing may have completed or paused"
            break
        fi
        
        sleep 5
        elapsed=$((elapsed + 5))
    done
    
    if [ $elapsed -ge $timeout ]; then
        echo "  Monitoring timeout reached. Indexing may still be in progress."
    fi
}

# Function to enable indexing for a volume
enable_indexing() {
    local volume=$1
    
    log_message "Attempting to enable indexing for volume: $volume"
    
    # Check if volume exists
    if [ ! -d "$volume" ]; then
        log_message "ERROR: Volume $volume does not exist"
        return 1
    fi
    
    # Check current status
    current_status=$(mdutil -s "$volume" 2>/dev/null)
    log_message "Current status for $volume: $current_status"
    
    # Enable indexing
    if sudo mdutil -i on "$volume"; then
        log_message "SUCCESS: Indexing enabled for $volume"
        
        # Verify the change
        new_status=$(mdutil -s "$volume" 2>/dev/null)
        log_message "New status for $volume: $new_status"
        
        # Monitor initial progress
        monitor_indexing "$volume"
        
        return 0
    else
        log_message "ERROR: Failed to enable indexing for $volume"
        return 1
    fi
}

# Main execution
log_message "Starting Spotlight indexing enable process"

# Enable for root volume
if enable_indexing "/"; then
    log_message "Root volume indexing enabled successfully"
else
    log_message "Failed to enable root volume indexing"
    exit 1
fi

log_message "Spotlight indexing enable process completed"
echo "Process completed. Check log at: $LOG_FILE"

Rebuilding Spotlight Index

Basic Rebuild Script

Script to completely rebuild the Spotlight index:

#!/bin/bash

# Rebuild Spotlight index
echo "Rebuilding Spotlight index..."
echo "Warning: This will erase the current index and rebuild from scratch"
echo ""

read -p "Continue? (y/N): " confirm
if [[ ! $confirm =~ ^[Yy]$ ]]; then
    echo "Operation cancelled"
    exit 0
fi

echo "Starting index rebuild..."

if sudo mdutil -E /; then
    echo "✓ Index rebuild initiated successfully"
    
    # Show status
    status=$(mdutil -s /)
    echo "Current status: $status"
    
    echo ""
    echo "The index rebuild process has started and will continue in the background"
    echo "This may take several hours depending on the amount of data"
    echo "You can monitor progress using Activity Monitor (look for mds_stores and mdworker processes)"
else
    echo "✗ Failed to initiate index rebuild"
    exit 1
fi

Advanced Rebuild with Selective Volumes

Script to rebuild indexes for specific volumes:

#!/bin/bash

# Advanced Spotlight index rebuild script
VOLUMES=(
    "/"
    "/Users"
    # Add specific volumes or use discovery
)

AUTO_DISCOVER=${1:-false}

echo "Spotlight Index Rebuild Utility"
echo "==============================="
echo "Date: $(date)"
echo ""

# Function to discover mounted volumes
discover_volumes() {
    echo "Discovering mounted volumes..."
    
    # Get all mounted HFS+/APFS volumes
    local discovered_volumes=()
    while IFS= read -r line; do
        volume=$(echo "$line" | awk '{print $9}')
        if [ -d "$volume" ] && [ "$volume" != "/dev" ]; then
            discovered_volumes+=("$volume")
        fi
    done < <(df -h | grep "^/dev")
    
    echo "Discovered volumes:"
    for vol in "${discovered_volumes[@]}"; do
        echo "  - $vol"
    done
    
    VOLUMES=("${discovered_volumes[@]}")
}

# Function to rebuild index for a volume
rebuild_index() {
    local volume=$1
    
    echo "Rebuilding index for: $volume"
    
    # Check if volume exists and is mounted
    if [ ! -d "$volume" ]; then
        echo "  ✗ Volume $volume does not exist or is not mounted"
        return 1
    fi
    
    # Show current status
    current_status=$(mdutil -s "$volume" 2>/dev/null)
    echo "  Current status: $current_status"
    
    # Rebuild index
    if sudo mdutil -E "$volume"; then
        echo "  ✓ Index rebuild initiated for $volume"
        
        # Show new status
        new_status=$(mdutil -s "$volume" 2>/dev/null)
        echo "  New status: $new_status"
        
        return 0
    else
        echo "  ✗ Failed to rebuild index for $volume"
        return 1
    fi
}

# Auto-discover volumes if requested
if [ "$AUTO_DISCOVER" = "true" ]; then
    discover_volumes
fi

echo "Volumes to rebuild:"
for volume in "${VOLUMES[@]}"; do
    echo "  - $volume"
done

echo ""
read -p "Proceed with rebuilding indexes? (y/N): " confirm
if [[ ! $confirm =~ ^[Yy]$ ]]; then
    echo "Operation cancelled"
    exit 0
fi

echo ""
echo "Starting index rebuild process..."
echo ""

successful=0
failed=0

for volume in "${VOLUMES[@]}"; do
    if rebuild_index "$volume"; then
        ((successful++))
    else
        ((failed++))
    fi
    echo ""
done

echo "Rebuild Summary:"
echo "---------------"
echo "Successfully initiated: $successful volumes"
echo "Failed: $failed volumes"
echo ""
echo "Note: Index rebuilding will continue in the background"
echo "Monitor progress with: ps aux | grep mds"

Advanced Spotlight Management

Selective Directory Exclusion

Script to exclude specific directories from indexing:

#!/bin/bash

# Exclude specific directories from Spotlight indexing
EXCLUDE_DIRS=(
    "/tmp"
    "/var/tmp"
    "/private/tmp"
    "/Users/Shared/Build"
    # Add more directories as needed
)

echo "Spotlight Directory Exclusion Manager"
echo "===================================="
echo ""

# Function to add directory to exclusion list
exclude_directory() {
    local dir_path=$1
    
    echo "Excluding directory: $dir_path"
    
    # Check if directory exists
    if [ ! -d "$dir_path" ]; then
        echo "  ⚠ Directory does not exist: $dir_path"
        return 1
    fi
    
    # Add to Spotlight privacy list using defaults
    if sudo defaults write /System/Library/CoreServices/Search.bundle/Contents/Resources/SpotlightExclusions.plist Exclusions -array-add "$dir_path"; then
        echo "  ✓ Added to exclusion list"
        return 0
    else
        echo "  ✗ Failed to add to exclusion list"
        return 1
    fi
}

# Function to show current exclusions
show_exclusions() {
    echo "Current Spotlight exclusions:"
    echo "----------------------------"
    
    # Read from system preferences
    if defaults read /System/Library/CoreServices/Search.bundle/Contents/Resources/SpotlightExclusions.plist Exclusions 2>/dev/null; then
        echo ""
    else
        echo "No exclusions found or unable to read exclusions list"
    fi
}

# Show current exclusions
show_exclusions

echo ""
echo "Adding new exclusions..."

for dir in "${EXCLUDE_DIRS[@]}"; do
    exclude_directory "$dir"
done

echo ""
echo "Exclusion process completed"
echo "Restart Spotlight for changes to take effect:"
echo "sudo killall mds && sudo mdutil -E /"

Performance Monitoring Script

Script to monitor Spotlight's impact on system performance:

#!/bin/bash

# Spotlight Performance Monitor
DURATION=${1:-60}  # Monitor for 60 seconds by default
INTERVAL=5

echo "Spotlight Performance Monitor"
echo "============================"
echo "Monitoring duration: ${DURATION} seconds"
echo "Sample interval: ${INTERVAL} seconds"
echo ""

# Function to get Spotlight process stats
get_spotlight_stats() {
    local timestamp=$(date '+%H:%M:%S')
    
    # Get mds processes
    mds_stats=$(ps aux | grep -E "mds|mdworker" | grep -v grep | awk '{
        cpu += $3; 
        mem += $4; 
        count++
    } END {
        printf "Processes: %d, CPU: %.1f%%, Memory: %.1f%%", count, cpu, mem
    }')
    
    # Get disk activity (if available)
    disk_activity=$(iostat -c 1 2>/dev/null | tail -1 | awk '{print "Disk: " $4 "% utilization"}' || echo "Disk: N/A")
    
    echo "[$timestamp] $mds_stats, $disk_activity"
}

# Header
echo "Time     | Spotlight Stats"
echo "---------|------------------------------------------------"

# Monitor loop
elapsed=0
while [ $elapsed -lt $DURATION ]; do
    get_spotlight_stats
    sleep $INTERVAL
    elapsed=$((elapsed + INTERVAL))
done

echo ""
echo "Monitoring completed"

# Show summary
echo ""
echo "Final Process Summary:"
echo "---------------------"
ps aux | grep -E "mds|mdworker" | grep -v grep | head -10

Automation and Scheduling

Automated Maintenance Script

Script for scheduled Spotlight maintenance:

#!/bin/bash

# Automated Spotlight maintenance script
# Can be run via cron or launchd

CONFIG_FILE="/etc/spotlight_maintenance.conf"
LOG_FILE="/var/log/spotlight_maintenance.log"

# Default configuration
REBUILD_INTERVAL=30  # days
CLEANUP_TEMP=true
MONITOR_PERFORMANCE=true

# Function to log with timestamp
log_message() {
    echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" | tee -a "$LOG_FILE"
}

# Load configuration if exists
if [ -f "$CONFIG_FILE" ]; then
    source "$CONFIG_FILE"
    log_message "Configuration loaded from $CONFIG_FILE"
fi

# Function to check if rebuild is needed
needs_rebuild() {
    local index_age_file="/var/db/.spotlight_last_rebuild"
    
    if [ ! -f "$index_age_file" ]; then
        return 0  # No record, assume rebuild needed
    fi
    
    local last_rebuild=$(cat "$index_age_file")
    local current_time=$(date +%s)
    local age_days=$(( (current_time - last_rebuild) / 86400 ))
    
    if [ $age_days -gt $REBUILD_INTERVAL ]; then
        log_message "Index age: $age_days days, rebuild needed"
        return 0
    else
        log_message "Index age: $age_days days, rebuild not needed"
        return 1
    fi
}

# Function to perform rebuild
perform_rebuild() {
    log_message "Starting scheduled index rebuild"
    
    if sudo mdutil -E /; then
        log_message "Index rebuild initiated successfully"
        echo "$(date +%s)" | sudo tee /var/db/.spotlight_last_rebuild > /dev/null
        return 0
    else
        log_message "Index rebuild failed"
        return 1
    fi
}

# Function to cleanup temporary files
cleanup_temp_files() {
    if [ "$CLEANUP_TEMP" = true ]; then
        log_message "Cleaning up temporary Spotlight files"
        
        # Remove temporary index files
        sudo find /tmp -name ".Spotlight*" -exec rm -rf {} \; 2>/dev/null
        sudo find /var/tmp -name ".Spotlight*" -exec rm -rf {} \; 2>/dev/null
        
        log_message "Temporary file cleanup completed"
    fi
}

# Function to check performance
check_performance() {
    if [ "$MONITOR_PERFORMANCE" = true ]; then
        local mds_cpu=$(ps aux | grep mds | grep -v grep | awk '{sum += $3} END {print sum}')
        
        if [ -n "$mds_cpu" ] && [ "$mds_cpu" -gt 50 ]; then
            log_message "WARNING: High Spotlight CPU usage detected: ${mds_cpu}%"
        else
            log_message "Spotlight performance normal: ${mds_cpu:-0}% CPU"
        fi
    fi
}

# Main maintenance routine
log_message "Starting automated Spotlight maintenance"

check_performance
cleanup_temp_files

if needs_rebuild; then
    perform_rebuild
fi

log_message "Automated Spotlight maintenance completed"

Best Practices and Recommendations

1. Performance Considerations

  • Monitor system resources before disabling indexing
  • Consider partial exclusions instead of complete disable
  • Schedule maintenance during off-hours
  • Test changes on non-production systems first

2. Security and Privacy

  • Exclude sensitive directories from indexing
  • Regularly review and update exclusion lists
  • Consider the security implications of search functionality
  • Document all changes for compliance purposes

3. Enterprise Management

  • Standardize Spotlight policies across devices
  • Use configuration management tools for deployment
  • Implement monitoring and alerting for index issues
  • Maintain documentation of all customizations

4. Troubleshooting Guidelines

  • Always check system logs when issues occur
  • Test individual commands before running complex scripts
  • Keep backups of important data before major changes
  • Document the steps taken for future reference

Troubleshooting Common Issues

Index Corruption

#!/bin/bash

# Fix corrupted Spotlight index
echo "Fixing corrupted Spotlight index..."

# Stop indexing
sudo mdutil -i off /

# Remove corrupted index
sudo rm -rf /.Spotlight-V100

# Re-enable and rebuild
sudo mdutil -i on /
sudo mdutil -E /

echo "Index repair initiated"

High CPU Usage

#!/bin/bash

# Address high Spotlight CPU usage
echo "Addressing high Spotlight CPU usage..."

# Check current processes
echo "Current Spotlight processes:"
ps aux | grep -E "mds|mdworker" | grep -v grep

# Temporarily throttle indexing
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist
sleep 5
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist

echo "Spotlight services restarted"

Conclusion

Effective Spotlight management is crucial for maintaining optimal macOS performance while preserving search functionality where needed. The scripts and techniques provided in this guide offer comprehensive solutions for various Spotlight management scenarios.

Key takeaways:

  • Understand the impact of indexing on system performance
  • Use appropriate scripts for your specific use case
  • Implement proper monitoring and maintenance procedures
  • Always test changes in a controlled environment
  • Document all modifications for future reference

Remember that disabling Spotlight indexing will significantly impact search functionality, so carefully consider the trade-offs before implementing these changes across your Mac fleet.

Tutorial

Neue Updates und Verbesserungen zu Macfleet.

Konfiguration eines GitHub Actions Runners auf einem Mac Mini (Apple Silicon)

GitHub Actions Runner

GitHub Actions ist eine leistungsstarke CI/CD-Plattform, die es Ihnen ermöglicht, Ihre Software-Entwicklungsworkflows zu automatisieren. Während GitHub gehostete Runner anbietet, bieten selbst-gehostete Runner erhöhte Kontrolle und Anpassung für Ihr CI/CD-Setup. Dieses Tutorial führt Sie durch die Einrichtung, Konfiguration und Verbindung eines selbst-gehosteten Runners auf einem Mac mini zur Ausführung von macOS-Pipelines.

Voraussetzungen

Bevor Sie beginnen, stellen Sie sicher, dass Sie haben:

  • Einen Mac mini (registrieren Sie sich bei Macfleet)
  • Ein GitHub-Repository mit Administratorrechten
  • Einen installierten Paketmanager (vorzugsweise Homebrew)
  • Git auf Ihrem System installiert

Schritt 1: Ein dediziertes Benutzerkonto erstellen

Erstellen Sie zunächst ein dediziertes Benutzerkonto für den GitHub Actions Runner:

# Das 'gh-runner' Benutzerkonto erstellen
sudo dscl . -create /Users/gh-runner
sudo dscl . -create /Users/gh-runner UserShell /bin/bash
sudo dscl . -create /Users/gh-runner RealName "GitHub runner"
sudo dscl . -create /Users/gh-runner UniqueID "1001"
sudo dscl . -create /Users/gh-runner PrimaryGroupID 20
sudo dscl . -create /Users/gh-runner NFSHomeDirectory /Users/gh-runner

# Das Passwort für den Benutzer setzen
sudo dscl . -passwd /Users/gh-runner ihr_passwort

# 'gh-runner' zur 'admin'-Gruppe hinzufügen
sudo dscl . -append /Groups/admin GroupMembership gh-runner

Wechseln Sie zum neuen Benutzerkonto:

su gh-runner

Schritt 2: Erforderliche Software installieren

Installieren Sie Git und Rosetta 2 (wenn Sie Apple Silicon verwenden):

# Git installieren, falls noch nicht installiert
brew install git

# Rosetta 2 für Apple Silicon Macs installieren
softwareupdate --install-rosetta

Schritt 3: Den GitHub Actions Runner konfigurieren

  1. Gehen Sie zu Ihrem GitHub-Repository
  2. Navigieren Sie zu Einstellungen > Actions > Runners

GitHub Actions Runner

  1. Klicken Sie auf "New self-hosted runner" (https://github.com/<username>/<repository>/settings/actions/runners/new)
  2. Wählen Sie macOS als Runner-Image und ARM64 als Architektur
  3. Folgen Sie den bereitgestellten Befehlen, um den Runner herunterzuladen und zu konfigurieren

GitHub Actions Runner

Erstellen Sie eine .env-Datei im _work-Verzeichnis des Runners:

# _work/.env Datei
ImageOS=macos15
XCODE_15_DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer
  1. Führen Sie das run.sh-Skript in Ihrem Runner-Verzeichnis aus, um die Einrichtung abzuschließen.
  2. Überprüfen Sie, dass der Runner aktiv ist und auf Jobs im Terminal wartet, und überprüfen Sie die GitHub-Repository-Einstellungen für die Runner-Zuordnung und den Idle-Status.

GitHub Actions Runner

Schritt 4: Sudoers konfigurieren (Optional)

Wenn Ihre Actions Root-Privilegien benötigen, konfigurieren Sie die sudoers-Datei:

sudo visudo

Fügen Sie die folgende Zeile hinzu:

gh-runner ALL=(ALL) NOPASSWD: ALL

Schritt 5: Den Runner in Workflows verwenden

Konfigurieren Sie Ihren GitHub Actions Workflow, um den selbst-gehosteten Runner zu verwenden:

name: Beispiel-Workflow

on:
  workflow_dispatch:

jobs:
  build:
    runs-on: [self-hosted, macOS, ARM64]
    steps:
      - name: NodeJS installieren
        run: brew install node

Der Runner ist bei Ihrem Repository authentifiziert und mit self-hosted, macOS und ARM64 markiert. Verwenden Sie ihn in Ihren Workflows, indem Sie diese Labels im runs-on-Feld angeben:

runs-on: [self-hosted, macOS, ARM64]

Best Practices

  • Halten Sie Ihre Runner-Software auf dem neuesten Stand
  • Überwachen Sie regelmäßig Runner-Logs auf Probleme
  • Verwenden Sie spezifische Labels für verschiedene Runner-Typen
  • Implementieren Sie angemessene Sicherheitsmaßnahmen
  • Erwägen Sie die Verwendung mehrerer Runner für Lastverteilung

Fehlerbehebung

Häufige Probleme und Lösungen:

  1. Runner verbindet sich nicht:

    • Überprüfen Sie die Netzwerkverbindung
    • Überprüfen Sie die Gültigkeit des GitHub-Tokens
    • Stellen Sie angemessene Berechtigungen sicher
  2. Build-Fehler:

    • Überprüfen Sie die Xcode-Installation
    • Überprüfen Sie erforderliche Abhängigkeiten
    • Überprüfen Sie Workflow-Logs
  3. Berechtigungsprobleme:

    • Überprüfen Sie Benutzerberechtigungen
    • Überprüfen Sie sudoers-Konfiguration
    • Überprüfen Sie Dateisystem-Berechtigungen

Fazit

Sie haben jetzt einen selbst-gehosteten GitHub Actions Runner auf Ihrem Mac mini konfiguriert. Diese Einrichtung bietet Ihnen mehr Kontrolle über Ihre CI/CD-Umgebung und ermöglicht es Ihnen, macOS-spezifische Workflows effizient auszuführen.

Denken Sie daran, Ihren Runner regelmäßig zu warten und ihn mit den neuesten Sicherheitspatches und Software-Versionen auf dem neuesten Stand zu halten.

Native App

Macfleet native App

Macfleet Installationsanleitung

Macfleet ist eine leistungsstarke Flottenmanagement-Lösung, die speziell für Cloud-gehostete Mac Mini-Umgebungen entwickelt wurde. Als Mac Mini Cloud-Hosting-Anbieter können Sie Macfleet verwenden, um Ihre gesamte Flotte virtualisierter Mac-Instanzen zu überwachen, zu verwalten und zu optimieren.

Diese Installationsanleitung führt Sie durch die Einrichtung der Macfleet-Überwachung auf macOS-, Windows- und Linux-Systemen, um eine umfassende Übersicht über Ihre Cloud-Infrastruktur zu gewährleisten.

🍎 macOS

  • Laden Sie die .dmg-Datei für Mac hier herunter
  • Doppelklicken Sie auf die heruntergeladene .dmg-Datei
  • Ziehen Sie die Macfleet-App in den Anwendungsordner
  • Werfen Sie die .dmg-Datei aus
  • Öffnen Sie Systemeinstellungen > Sicherheit & Datenschutz
    • Datenschutz-Tab > Bedienungshilfen
    • Aktivieren Sie Macfleet, um Überwachung zu erlauben
  • Starten Sie Macfleet aus den Anwendungen
  • Die Verfolgung startet automatisch

🪟 Windows

  • Laden Sie die .exe-Datei für Windows hier herunter
  • Rechtsklick auf die .exe-Datei > "Als Administrator ausführen"
  • Folgen Sie dem Installationsassistenten
  • Akzeptieren Sie die Allgemeinen Geschäftsbedingungen
  • Erlauben Sie in Windows Defender, wenn aufgefordert
  • Gewähren Sie Anwendungsüberwachungsberechtigungen
  • Starten Sie Macfleet aus dem Startmenü
  • Die Anwendung beginnt automatisch mit der Verfolgung

🐧 Linux

  • Laden Sie das .deb-Paket (Ubuntu/Debian) oder .rpm (CentOS/RHEL) hier herunter
  • Installieren Sie mit Ihrem Paketmanager
    • Ubuntu/Debian: sudo dpkg -i Macfleet-linux.deb
    • CentOS/RHEL: sudo rpm -ivh Macfleet-linux.rpm
  • Erlauben Sie X11-Zugriffsberechtigungen, wenn aufgefordert
  • Fügen Sie den Benutzer zu entsprechenden Gruppen hinzu, falls erforderlich
  • Starten Sie Macfleet aus dem Anwendungsmenü
  • Die Anwendung beginnt automatisch mit der Verfolgung

Hinweis: Nach der Installation auf allen Systemen melden Sie sich mit Ihren Macfleet-Anmeldedaten an, um Daten mit Ihrem Dashboard zu synchronisieren.