2023-12-14
2023-12-14
705 字
2 分钟
launchd is an init and operating system service management daemon created by Apple Inc. as part of macOS to replace its BSD-style init and SystemStarter. There have been efforts to port launchd to FreeBSD and derived systems.
launchd 是 macos 上一套服务管理框架,类似与 linux 的 systemnd
launchtl 配置文件
plist 文件就是 xml 文件,内容格式如下
|
|
常用的 key
key | 类型 | 含意 | 是否必须 |
---|---|---|---|
Label | string | launchctl list 时显示名称 | Y |
ProgramArguments | array | 执行内容一般为绝对路径 | Y |
StartInterval | integer | 定时执行,单位秒 | N |
RunAtLoad | boolean | 导入时运行 | Y |
disabled | boolean | 是否不生效, -w 可以强制忽视 | N |
EnvironmentVariables | dict | 环境变量 | N |
GroupName | string | 用户组 | N |
UserName | string | 使用用户名 在 Daemons | N |
KeepAlive | boolean | 是否设置程序一直存活,退出后自动重启 | N |
ProcessType | string | 进程类型 | N |
StandardErrorPath | string | 执行错误输出日志 | N |
StandardOutPath | string | 执行程序的日志 | N |
StartCalendarInterval | dict | 设置程序具体运行时间,类似 cron 表达式 | N |
launchtl 文件存放位置
目录 | 作用 |
---|---|
/Library/LaunchDaemons | 系统启动后执行,由管理员定义的守护进程任务项 |
/Libray/LaunchAgents | 当用户登录才会执行。由管理员为用户自定义的任务项 |
~/Library/LaunchDaemons | 由用户自定义的任务项 |
/System/Library/LaunchAgents | MacOS 用户定义的任务 |
/System/Library/LaunchDaemons | MacOS 用户定义的收获进程任务项 |
launchtl 常用命令
|
|
常用问题
78 error
Error 78 means that there is no permission to write to the log files you have specified. 错误 78 意味着没有权限写入您指定的日志文件。
配置环境变量
这种方法常用于设置系统环境变量
|
|