免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 5578 | 回复: 0
打印 上一主题 下一主题

苹果系统启动脚本的编写规则 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-06-05 13:27 |只看该作者 |倒序浏览
苹果系统启动脚本的编写规则,以下是相关的资料供参考。


http://developer.apple.com/documentation/MacOSX/Conceptual/BPSystemStartup/Tasks/CreatingStartupItems.html


Creating a Startup Item

You can add specialized behavior to the booting sequence by creating new startup items. A startup item, as described in “Startup Items”, is a program or shell script that provides a basic service, such as deleting old files or performing other maintenance tasks prior to the first login session.

Important:   The use of startup items to launch daemons is deprecated. To launch daemons, you should register the daemon with the bootstrap environment as described in “Bootstrap Daemons”.

Contents:
About Startup Items
Creating the Startup Item Executable
Specifying the Startup Item Properties




About Startup Items

Startup items are run (through the SystemStarter program) as the final phase of the booting sequence. At that time, SystemStarter looks for startup items in the /System/Library/StartupItems and /Library/StartupItems directories. It gathers information from the property list of each startup item and uses that information to determine the execution order for the items. It then executes the startup items in groups based on the inter-dependencies among the items.

The /System/Library/StartupItems directory is reserved for startup items that ship with Mac OS X. All other startup items should be placed in the /Library/StartupItems directory. Note that this directory does not exist by default and may need to be created during installation of the startup item.

To create a new startup item, you must create a program or script to execute your code, and you must create a property list file to contain information about your startup item. The following sections describe these techniques in more detail.

Creating the Startup Item Executable

The startup item executable contains your startup item’s code and can be implemented as a command-line executable or shell script. Normally, your executable is called only at system startup time. However, SystemStarter does support the ability to call your executable at a later time (see “Managing Startup Items”).

To create a startup item:
        1.         
Create a directory for your startup item. The directory name should correspond to the behavior you’re providing.

Example: MyDBServer
        2.         
Add your executable to the directory. The name of your executable should be exactly the same as the directory name.

Example: MyDBServer/MyDBServer
        3.         
Create a property list with the name StartupParameters.plist and add it to the directory. See “Specifying the Startup Item Properties”.

Example: MyDBServer/StartupParameters.plist
        4.         
Create an installer to place your startup item in the /Library/StartupItems directory of the target system. (Your installer may need to create this directory first.)

If you are implementing your startup-item executable as a shell script, Mac OS X provides some code to simplify the process of creating your script. The file /etc/rc.common defines routines for processing command-line arguments and for gathering system settings. In your shell script, source the rc.common file and call the RunService routine, passing it the first command-line argument, as shown in the following example:

#!/bin/sh

. /etc/rc.common

#

# Your startup item code

#

RunService "$1"



The RunService routine looks for StartService, StopService, and RestartService routines in your shell script and calls them to start, stop, or restart your services as needed. You must provide implementations for all three routines, although the implementations can be empty for routines whose commands your service does not support.

If your startup-item executable contains code that might take a while to complete, you should consider running that code as a daemon or a background process. Executing lengthy startup tasks directly from your scripts delays system startup. Your startup item script should execute as quickly as possible and then exit.

Specifying the Startup Item Properties

In addition to the startup item executable, every startup item must have a property list with the name StartupParameters.plist in the startup item directory. This property list contains information about the startup item as well as any dependencies this item has on other startup items. Prior to launching any startup items, the SystemStarter program reads the property list of each startup item and uses the dependency information to determine a launch order.

Table 1 lists the key-value pairs to include in the StartupParameters.plist file of your startup item. All arrays and dictionaries contain string values. You can use the Property List Editor application in /Developer/Applications to create this property list.


Table 1 :  StartupParameters.plist key-value pairs

Key

Type

Value

Description

String

A short description of the startup item, used by administrative tools.

Provides

Array

The services provided by this startup item. Although a startup item can potentially provide multiple services, you should limit your startup items to only one.

Requires

Array

The services provided by other startup items that must be run before this startup item can be started. If the required services are not available, this startup item is not run.

Uses

Array

The services provided by other startup items that should be started before this startup item, but which are not mandatory. The startup item should be able to start without the availability of these services.

OrderPreference

String

For those startup items with the same execution order (as determined by the Requires and Uses values), the relative order in which they should be started. There are five order-preference values: First, Early, None, Late, and Last. The default is None. The order preference is an advisory value and might be ignored.



The values you specify for the Requires and Uses properties correspond to the service name on which your startup item is dependent. Service names may not always correspond directly to the name of the startup item that provides that service. The Provides property specifies the names of the services provided by a startup item, and while this name usually matches the name of the startup item, it is not required to do so. In particular, startup items that launch multiple services can have at most one service whose name matches the name of the startup item.

If two startup items provide a service with the same name, SystemStarter runs only the first startup item it finds with that name. For this reason, it is recommended that your startup items do not provide multiple services unless absolutely required by codependencies in your startup code.

The values of the Requires, Uses, and OrderPreference keys do not guarantee a particular launch order.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP