๐งพ Summary
This document provides a comprehensive guide to macOS launchd, the unified service management framework that replaces traditional Unix init systems, cron, and inetd. Understanding launchd is essential for managing services and automating tasks on macOS.
๐ฏ Key Concepts
Launchd serves as the single point of truth for all service management on macOS, handling: - System daemons (LaunchDaemons) - User agents (LaunchAgents) - Scheduled jobs (cron replacement) - On-demand services (inetd replacement) - Event-triggered tasks
๐ง Core Components
Property List (plist) Files
Services are defined using XML property lists with standardized keys:
- Label: Unique service identifier
- ProgramArguments: Command and arguments to execute
- RunAtLoad: Start service at load time
- KeepAlive: Restart if service exits
Service Types
- Agents: Run in user context (
~/Library/LaunchAgents/) - Daemons: Run in system context (
/Library/LaunchDaemons/,/System/Library/LaunchDaemons/)
๐ Essential Commands
1 2 3 4 5 6 7 8 | |
๐ ๏ธ Common Use Cases
- Scheduled Tasks: Replace cron with
StartCalendarInterval - File Monitoring: Use
WatchPathsfor filesystem events - Network Services: Define sockets for on-demand services
- Resource Management: Set limits with
SoftResourceLimits
๐ Troubleshooting Tips
- Validate plist syntax with
plutil -lint - Check service logs in
~/Library/Logs/ - Monitor launchd activity with
log stream - Use
launchctl printfor detailed service information