Launchctl介绍

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’

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值