launchd no longer uses Unix domain sockets forcommunication, so the LAUNCHD_SOCKET environment variable is no longer relevant andis not set.
launchd no longer loads configurationfiles from the network
FILES ~/Library/LaunchAgents Per-useragents provided by the user. /Library/LaunchAgents Per-user agents provided by theadministrator. /Library/LaunchDaemons Systemwide daemons provided by the administrator. /System/Library/LaunchAgents OS X Per-user agents. /System/Library/LaunchDaemonsOS X System wide daemons.
插曲--MacPro无法启动
本来想禁止apache开机自启动
launchctl unload -w/System/Library/LaunchDaemons/org.apache.httpd.plist结果太大意,没想到手快了一步,命令敲成了launchctl unload -w/System/Library/LaunchDaemons/
我的个乖乖,突然触摸板,键盘全部失灵,有点慌了,怎么回事儿,还好有点linux基础,看了下命令,把系统的很多Daemons直接停掉并去除了开机启动了,重启后直接卡死在苹果LOGO下,进度好容易走完了,却看不能美美的桌面,完了。真的是没法加载相关Daemon从而加载硬件驱动,系统无法正常启动。
问了下度娘,有说重新加载SMC的,详风苹果官方文档https://support.apple.com/zh-cn/HT201295
试了下,没效果不说,反而风扇狂转不止,更加担心了,难道要重装,oh, mygod
又百度了下,看了下无法启动的基本排查思路和顺序,理了理头绪,既然是不小心去掉了开机启动项,还原回去就可以了,于是
A方案(失败)
进Recovery模式,将unload掉的全部加入到开机启动项后重启
chroot /Volumes/Macintosh HD
cp -a System/Library/LaunchDaemons/*Library/StartupItems/
cp -aSystem/Library/LaunchDaemons/*System/Library/StartupItems/launchctl rebootB方案(成功)如何以单用户模式或详细模式启动Mac注意:进入单用户模式权限太大,太危险,可以为单用户模式加道锁,可选的组合方案如下1.启用FileVault,进入单用户模式时会要求输入密码确认(性能比没做磁盘加密肯定会低些)2.设置固件密码,阻止光盘,U盘等其它第三方介质启动,只有关闭固件密码后才能进入单用户模式Command+S进入单用户模式说明:OSX也有单用户模式,和linux很像,字符界面以读写模式挂载根mount -uwlaunchctl load -w/System/Library/LaunchDaemons/只看到一大堆提示加载什么成功,之后便进入到了美美的图形界面,这时心里就有底了可是问题来了再次重启,还是无法正常进入图形想想,只是在单用户模式下临时加载了daemon而启动到了多用户图形模式,而该模式(正常的图形模式)并没有将unload的daemon加入到开机启动项,所以仍然无法正常启动。于是,重复上述动作进入图形后,再次执行launchctlload -wF/System/Library/LaunchDaemons/,让图形模式的开机启动项中也有被unload掉的daemon终于,再次重启就一切回归正常了,感谢万能的度娘launchctl中有这么一小段,更加说明了此次无法正常启动的缘由简单点讲,就是放在/System/Library/LaunchDaemons某个第三方daemon可能导致系统无法正常启动,而我的情况是/System/Library/LaunchDaemons下的所以daemon都被unload掉了,系统当然无法正常启动Note that allowingnon-root write access to the /System/Library/LaunchDaemons directory WILL render yoursystem unbootable.-w Overridesthe Disabled key and sets it to false or true for the load and unload subcommands respectively. Inprevious versions, this option would modify the configuration file.Now the state of the Disabled key is stored elsewhere on- disk ina location that may not be directly manipulated by any processother than launchd.
常用的几个launchctl命令launchctl start|stop|list|remove labellaunchctl load|unload pathslaunchctlprint|kickstart|kill|enable|disableservice-target以apache为例/System/Library/LaunchDaemons/org.apache.httpd.plist #就是pathorg.apache.httpd#就是label1.daemon stopjlive@MacBook-Pro:~-Password:MacBook-Pro:~ root#ls /System/Library/LaunchDaemons/org.apache.httpd.plist/System/Library/LaunchDaemons/org.apache.httpd.plistMacBook-Pro:~ root#ps -ef|grep httpd 0 87 1 011:18PM ?? 0:01.56 /usr/sbin/httpd -D FOREGROUND70 246 87 0 11:18PM ?? 0:00.03/usr/sbin/httpd -D FOREGROUND 0 3971 3964 0 3:20PMttys000 0:00.00 grephttpdMacBook-Pro:~ root#launchctl stoporg.apache.httpdMacBook-Pro:~ root#ps -ef|grep httpd 0 3988 3964 0 3:20PMttys000 0:00.00 grephttpd2.daemonstartMacBook-Pro:~ root#launchctl startorg.apache.httpdMacBook-Pro:~ root#ps -ef|grep httpd 0 4000 1 0 3:23PM?? 0:00.15 /usr/sbin/httpd -D FOREGROUND70 4001 4000 0 3:23PM ?? 0:00.00 /usr/sbin/httpd -DFOREGROUND3.daemonlistMacBook-Pro:~ root#launchctl list|grepapache4035 0org.apache.httpd 0 4003 3964 0 3:23PMttys000 0:00.00 grephttpd说明:load|unload并不一定会start|stop相关服务,它只是在start或stop前载入相关配置环境4.unloadplistMacBook-Pro:~ root#launchctl unload/System/Library/LaunchDaemons/org.apache.httpd.plistMacBook-Pro:~ root#ps -ef|grep httpd 0 4237 4221 0 4:01PMttys001 0:00.00 grephttpd4.loadplistMacBook-Pro:~ root#launchctl load/System/Library/LaunchDaemons/org.apache.httpd.plistMacBook-Pro:~ root#ps -ef|grep httpd 0 4241 1 0 4:01PM?? 0:00.16 /usr/sbin/httpd -D FOREGROUND70 4243 4241 0 4:01PM ?? 0:00.00 /usr/sbin/httpd -DFOREGROUND 0 4245 4221 0 4:01PMttys001 0:00.00 grephttpd5.printservice-targetMacBook-Pro:~ root#launchctl printsystem/org.apache.httpd|headorg.apache.httpd ={activecount = 1path =/System/Library/LaunchDaemons/org.apache.httpd.pliststate =running
program =/usr/sbin/httpd-wrapperarguments= {/usr/sbin/httpd-wrapper-DFOREGROUND6.killservice-targetMacBook-Pro:~ root#ps -ef|grep httpd 0 4417 1 0 4:21PM ?? 0:00.16/usr/sbin/httpd -D FOREGROUND70 4423 4417 0 4:21PM ?? 0:00.00 /usr/sbin/httpd -DFOREGROUND 0 4429 4221 0 4:21PMttys001 0:00.00 grephttpdMacBook-Pro:~ root#launchctl kill SIGKILLsystem/org.apache.httpdMacBook-Pro:~ root#ps -ef|grep httpd 0 4431 1 0 4:21PM ?? 0:00.15/usr/sbin/httpd -D FOREGROUND70 4432 4431 0 4:21PM ?? 0:00.00 /usr/sbin/httpd -DFOREGROUND 0 4434 4221 0 4:21PMttys001 0:00.00 grephttpd7.disableservice-targetMacBook-Pro:~ root#launchctl disablesystem/org.apache.httpdMacBook-Pro:~ root#ps -ef|grep httpd 0 4451 4221 0 4:24PMttys001 0:00.00 grephttpdMacBook-Pro:~ root#launchctl load/System/Library/LaunchDaemons/org.apache.httpd.plist/System/Library/LaunchDaemons/org.apache.httpd.plist:Service is disabled8.enableservice-targetMacBook-Pro:~ root#launchctl enablesystem/org.apache.httpdMacBook-Pro:~ root#launchctl load/System/Library/LaunchDaemons/org.apache.httpd.plistMacBook-Pro:~ root#ps -ef|grep httpd 0 4458 1 0 4:25PM?? 0:00.16 /usr/sbin/httpd -D FOREGROUND70 4459 4458 0 4:25PM ?? 0:00.00 /usr/sbin/httpd -DFOREGROUND 0 4461 4221 0 4:25PMttys001 0:00.00 grephttpd