Launchctl 控制OS X系统里的启动进程(launch) php
在Mac里有一个命令行工具叫作:launchctl,能够用来控制服务的自动启动或者关闭。通常的语法是
sudo launchctl load /path/to/service.plistsudo launchctl unload /path/to/service.plist
通常plist文件放在这j几个地方:mysql
/Library/LaunchDaemons/ 由管理员定义的守护进程任务项
/Library/LaunchAgents/ 由管理员为用户定义的任务项
~/Library/LaunchAgents/ 由用户本身定义的任务项 nginx
/System/Library/LaunchAgents 由Mac OS X为用户定义的任务项redis
你能够写一个plist文件放到~/Library/Launch Agents/下面,文件里描述你的程序路径和启动参数,那么这个用户登陆时就会启动这个程序了,并且是杀不了的哦
被杀了以后会自动从新启动
若是须要把它中止的话,运行一下命令
launchctl unload ~/Library/Launch Agents/com.your company.porduct
若是放到/Library/Launch Agents/下面的话,就是一开机就启动哦~sql
Launchctl :控制OS X系统里的启动进程(launch) 编程
执行定时脚本|设置开机启动步骤
(1)编写执行脚本
一般brew在安装软件时brew为咱们自动生成。
(2)去对应的目录下创建plist文件
(3)加载服务vim
说明:Agents文件夹下的plist是须要用户登陆后,才会加载的,而Daemons文件夹下得plist是只要开机,能够不用登陆就会被加载bash
加载/卸载服务
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’memcached
Plist的全称是Property lists,是一种用来存储串行化后的对象的文件。属性列表文件的文件扩展名为.plist,所以一般被称为plist文件。Plist文件一般用于储存用户设置,也能够用于存储捆绑的信息。
Plist组织数据到命名值和列表值,主要经过几个主要的Core Foundation类型:CFString, CFNumber, CFBoolean, CFDate, CFData, CFArray, 和 CFDictionary。
Plist结构和内容
Property lists从基本的Core Foundation 类型:CFString,CFNumber,CFBoolean,CFDate,CFData构造。要创建一个复杂的数据结构从这些基本类型,你得把它们放在里面CFDictionary或CFArray里面。为了简化对Property lists的编程,任何属性列表类型也能够被引用经过使用类型CFPropertyListRef。
在一个CFDictionary,数据结构是以键-值对的形式,其中每一个键是一个字符串,该键的值能够是一个CFString字符串,一个CFNumber,一个CFBoolean,一个CFDate,一个CFData,一个CFArray,或其余CFDictionary。当使用CFDictionary做为属性列表时,全部的键必须是字符串。
在一个CFArray,数据结构是以一个能够经过索引访问的对象的有序集合。在属性列表中,一个CFArray能够包含任何的基本属性列表类型,以及CFDictionary和其余CFArray的对象。
PROPERTY LIST XML 标签
当属性列表将Core Foundation对象集合转换成一个XML的属性列表,使用文件类型标签<plist>来包含全部的属性列表。下表中列出Core Foundation数据类型经常使用的其余标记:
Core Foundation数据类型等同的XML
Core Foundation类型 |
XML标签 |
CFString |
<string> |
CFNumber |
<real> 或者 <integer> |
CFBoolean |
<true /> 或者<false /> |
CFDate |
<date> |
CFData |
<data> |
CFArray |
<array> |
CFDictionary |
<dict> |