Skip to content

shells-macos

对标 linux 的 systemctl. 通过 plist 维护. 三方守护进程一般放在 Library/LaunchDaemons 里.

/Library/LaunchDaemons/jenkins.plist 配置示例

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
       "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
 <plist version="1.0">
 <dict>
    <key>Label</key>
     <string>jenkins</string>
     <key>ServiceDescription</key>
     <string>jenkins</string>
     <key>ProgramArguments</key>
     <array>
          <string>/opt/homebrew/bin/jenkins</string>
          <string>--webroot=/Users/lmh/.jenkins/war</string>
      </array>
      <key>RunAtLoad</key>
      <false/>
  </dict>
 </plist>

brew 分析

brew 通常会维护自己的 .plist 文件,位于 ·brew info pkgName 下。

启动时,brew 会将此 plist 复制到类似于 /Library/LaunchDaemons/ 下去,还是由 launchctl 接管.

sevice、systemctl、launchctl(mac)开机自启动指令设置

指令 service systemctl Launchctl
编写启动脚本目录 vi /etc/init.d/httpd vi /usr/lib/systemd/system/httpd.service
vi /etc/systemd/system/httpd.service
/Library/LaunchDaemons
脚本赋权 chmod +x /etc/init.d/httpd chmod +x /usr/lib/systemd/system/httpd.service
使某服务自动启动 chkconfig -–level 3 httpd on
chkconfig --add httpd
systemctl enable httpd.service launchctl load -w com.httpd.plist
使某服务不自动启动 chkconfig –-level 3 httpd off
chkconfig —del httpd
systemctl disable httpd.service launchctl unload -w com.httpd.plist
显示所有已启动的服务 chkconfig –-list systemctl list-units --type service launchctl list
启动某服务 service httpd start systemctl start httpd.service launchctl start com.httpd.plist
停止某服务 service httpd stop systemctl stop httpd.service launchctl stop com.httpd.plist
重启某服务 service httpd restart systemctl restart httpd.service launchctl restart com.httpd.plist
重载某服务 systemctl reload httpd.service