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’

你可能感兴趣的:(开发环境搭建)