Launchctl介绍

Launchctl介绍LaunchctlLaunchctl:控制OSX系统里的启动进程(launch)2.1执行定时脚本|设置开机启动步骤(1)编写执行脚本通常brew在安装软件时brew为我们自动生成。(2)去对应的目录下建立plist文件(3)加载服务2.2plist指定目录介绍-~/Library/LaunchAgents由用户自己定义的任务项

Launchctl
Launchctl :控制OS X系统里的启动进程(launch)
2.1 执行定时脚本|设置开机启动步骤
(1)编写执行脚本
通常brew在安装软件时brew为我们自动生成。
(2)去对应的目录下建立plist文件
(3)加载服务

2.2 plist指定目录介绍
– ~/Library/LaunchAgents 由用户自己定义的任务项
– /Library/LaunchAgents 由管理员为用户定义的任务项
– /Library/LaunchDaemons 由管理员定义的守护进程任务项
– /System/Library/LaunchAgents 由Mac OS X为用户定义的任务项
说明:Agents文件夹下的plist是需要用户登录后,才会加载的,而Daemons文件夹下得plist是只要开机,可以不用登录就会被加载

2.3 加载/卸载服务
cd 进入指定 plist 文件 目录
launchctl load *.plist #加载
launchctl unload *.plist #取消
launchctl list #查看服务

launchctl load -w   **.pist #设置开机启动并立即启动改服务

launchctl load **.pist #设置开机启动但不立即启动服务
2.4 对服务设置别名方便操作
vim ~/.bash_profile #编辑添加如下脚本
alias nginx.start=’launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist’
alias nginx.stop=’launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist’
alias nginx.restart=’nginx.stop && nginx.start’
alias php-fpm.start=”launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php55.plist”
alias php-fpm.stop=”launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.php55.plist”
alias php-fpm.restart=’php-fpm.stop && php-fpm.start’
alias mysql.start=”launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist”
alias mysql.stop=”launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist”
alias mysql.restart=’mysql.stop && mysql.start’
alias redis.start=”launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.redis.plist”
alias redis.stop=”launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.redis.plist”
alias redis.restart=’redis.stop && redis.start’
alias memcached.start=”launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.memcached.plist”
alias memcached.stop=”launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.memcached.plist”
alias memcached.restart=’memcached.stop && memcached.start’

今天的文章Launchctl介绍分享到此就结束了,感谢您的阅读。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/8471.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注