Mac OS 系统原生应用程序的自自启动项

发布于 2022-04-12 13:19:57 字数 4148 浏览 1002 评论 0

自启动脚本目录

/Library/StartupItems
/System/Library/StartupItems

通过 MacPorts 安装的软件的自启动项

A StartupItem is a MacPorts facility to run "daemons," a Unix term for programs that run continuously in the background, rather than under the direct control of a user; for example, mail servers, network listeners, etc. Ports that use StartupItem keywords create Mac OS X scripts for launchd, which is the Apple facility introduced with Mac OS X 10.4 to replace xinetd for starting and managing daemons. To support launchd, a program named daemondo is provided by MacPorts base that serves as an adapter between Mac OS X's launchd and daemons (“executable” StartupItems) or traditional Unix startup scripts that start daemons (“script” StartupItems).

There are three categories of StartupItem keywords. Those that trigger StartupItem creation and logging, those that specify attributes of “executable” StartupItems, and those that specify attributes of “script” StartupItems.

Note

The variable startupitem_type in ${prefix}/etc/macports/macports.conf \
may be set to none to globally override all StartupItem keywords found in Portfiles; \
this prevents StartupItems from being created.

其中 ${prefix} 值默认为 /opt/local,在 ${prefix}/etc/macports/macports.conf 中有定义。

launchctl 机制

man launchctl

启动项属性

本节关键词是“可执行程序”或“脚本”可启动项。

可执行程序启动项

启动项属性名称默认值实例说明
startupitem.createnostartupitem.create yes是否创建启动项
startupitem.name${name}startupitem.name dhcpd设置启动项名称,默认为port名称

脚本启动项

从 launchd 加载/卸载可启动项

A port with a StartupItem places a link to a .plist file for the port's daemon within /Library/LaunchDaemons/. A .plist file is an XML file; MacPorts installs .plist files tagged as “disabled” for the sake of security. You may enable a startup script (tag the.plist file as “enabled”) and load it into launchd with a single command as shown.

sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist

You may stop a running startup script, disable it (tag the.plist file as “disabled”), and unload it from launchd with a single command as shown.

sudo launchctl unload -w /Library/LaunchDaemons/org.macports.mysql5.plist

启动项内部细节

During port installation a MacPorts StartupItem creates a .plist file in ${prefix}/etc/LaunchDaemons/, and places a symbolic link to the .plist file within /Library/LaunchDaemons/.

For example, the StartupItem for the mysql5 port is org.macports.mysql5.plist, and it is linked as shown.

$ ls -l /Library/LaunchDaemons
org.macports.mysql5.plist ->
     /opt/local/etc/LaunchDaemons/org.macports.mysql5/org.macports.mysql5.plist

For “script” StartupItems, in addition to a .plist file, a wrapper is also created.

$ ls -l /opt/local/etc/LaunchDaemons/org.macports.mysql5/
-rwxr-xr-x   2 root  wheel  475 Aug  2 14:16 mysql5.wrapper
-rw-r--r--   2 root  wheel  975 Aug  2 14:16 org.macports.mysql5.plist

The wrapper manipulates the script as specified in the startupitem.start and startupitem.stop keywords. An example wrapper script snippet is shown below.

#!/bin/sh

# MacPorts generated daemondo support script

# Start
Start(){
    /opt/local/share/mysql5/mysql/mysql.server start
}

# Stop
Stop(){
    /opt/local/share/mysql5/mysql/mysql.server stop
}
#
    [... trimmed ...]

参考资料

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

关于作者

JSmiles

生命进入颠沛而奔忙的本质状态,并将以不断告别和相遇的陈旧方式继续下去。

0 文章
0 评论
84961 人气
更多

推荐作者

醉城メ夜风

文章 0 评论 0

远昼

文章 0 评论 0

平生欢

文章 0 评论 0

微凉

文章 0 评论 0

Honwey

文章 0 评论 0

qq_ikhFfg

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文