macOS Launch Agent PlistをJSONに変換する
launchdのLaunch AgentおよびLaunch Daemon plistファイルをJSONに変換します。Label、ProgramArguments、StartCalendarInterval、その他のlaunchdキーを解説します。
macOS Config
詳細な説明
Launch AgentとDaemon
macOSはlaunchdを使用してバックグラウンドサービスを管理します。設定は~/Library/LaunchAgents/(ユーザーごと)または/Library/LaunchDaemons/(システム全体)のplistファイルに保存されます。これらをJSONに変換すると、Configuration-as-Codeワークフローでの管理が簡素化されます。
Plist構造
<dict>
<key>Label</key>
<string>com.example.backup</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/backup.sh</string>
<string>--verbose</string>
<string>--compress</string>
</array>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>3</integer>
<key>Minute</key>
<integer>0</integer>
</dict>
<key>RunAtLoad</key>
<false/>
<key>KeepAlive</key>
<false/>
</dict>
JSON出力
{
"Label": "com.example.backup",
"ProgramArguments": ["/usr/local/bin/backup.sh", "--verbose", "--compress"],
"StartCalendarInterval": {
"Hour": 3,
"Minute": 0
},
"RunAtLoad": false,
"KeepAlive": false
}
混合型
Launch Agent plistは文字列(Label、パス)、配列(ProgramArguments)、辞書(StartCalendarInterval)、整数(Hour、Minute)、ブーリアン(RunAtLoad、KeepAlive)を混在させています。コンバーターはこれらすべての型を正しく処理し、ツリービューは各値の型バッジを表示します。
スケジューリング vs Cron
StartCalendarIntervalはlaunchdのcron相当機能です。Hour、Minute、Day、Month、Weekdayの整数値はJSON数値に変換され、スケジュールのプログラム的な生成や変更が容易になります。
ユースケース
PuppetやAnsibleなどのツールでmacOSフリート設定を管理するDevOpsチームに役立ちます。plist定義をJSONに変換することで、バージョン管理されたInfrastructure-as-Codeワークフローが可能になります。