Android init. RC File Syntax

Source: Internet
Author: User

Android init. RC File Syntax

The android initialization script language contains four types of statements:

* Actions)
* Command (commands)
* Services)
* Option (options)
The syntax of this language includes the following conventions:
* All types of statements are based on line-oriented. A statement contains several tokens, which are separated by space characters. if a token needs to contain space characters, it needs to be escaped by a backslash ('/') in the C language style, or the entire token is caused by double quotation marks. The backslash can also appear at the end of a row, indicating that the content of the next row still belongs to the current statement.
* The line starting with '#' is a comment line.
* The actions and services statements implicitly indicate the beginning of a new section. All commands (commands) and options belong to the most recent section above. The commands (commands) and options before the first paragraph are invalid.
* Actions and services have unique names. If duplicate names occur, the subsequent definitions are ignored as errors.

Actions)
An action is a commands sequence with a name. Each action defines a trigger to indicate when the action will be executed. When an event matches an action trigger, the action is added to the end of the queue to be executed (unless it is already in the queue ).
Each action in the queue is retrieved and executed in sequence, and each instruction in the action is also executed in sequence. The initialization program (init) also needs to process other operations (such as device creation/destruction, Property setting, and process restart) during the execution of commands for an action ).
An action is defined as follows:

On <trigger>
<Command>
<Command>
<Command>

Services)
Services are some programs that need to be started for initialization. Initialization programs may restart them after they exit. Services take a Service as follows:
Service <Name> <pathname> [<argument>] *
<Option>
<Option>
...

Options)
This option will affect the time and method of controlling the initialization program to run the service. Possible options are as follows.
Option description
Disabled this service will not automatically start with its class. It must be explicitly started by name.
Socket <Name> <type> <perm> [<user> [<group>] Create a Unix domain socket named/dev/socket/<Name> and pass its FD to launched process. valid <type> values include dgram and stream. user and group default to 0.
User <username> change to username before exec 'ing this service. Currently defaults to root.
Group <groupname> [<groupname>] * change to groupname before exec 'ing this service. additional groupnames beyond the first, which is required, are used to set additional groups of the process (with setgroups ()). currently defaults to root.
Capability [<capability>] + set Linux capability before exec 'ing this service
Oneshot do not restart the service when it exits.
Class <Name> specify a class name for the service. all services in a named class must start and stop together. A service is considered of Class "default" if one is not specified via the class option.

Triggers)
A trigger is a string used to match a specific event. These events trigger the execution of the action of the trigger.
Trigger description
Boot this is the first trigger that occurs when init starts (after/init. conf is loaded ).
<Name >=< value> triggers of this form occur when the property <Name> is set to the specific value <value>.
Device-added-<path>
Device-removed-<path> triggers of these forms occur when a device node is added or removed.
Service-Exited-<Name> triggers of this form occur when the specified service exits.

Command (commands)
Command description
Exec <path> [<argument>] * fork and execute a program (<path> ). this will block until the program completes execution. try to avoid exec. unlike the builtin commands, it runs the risk of getting init "stuck ".
Export <Name> <value> set the environment variable <Name> equal to <value> In the Global Environment (which will be inherited by all processes started after this command is executed ).
IFUP <interface> bring the network interface <interface> online.
Import <FILENAME> parse an init config file, extending the current configuration.
Hostname <Name> set the host name.
Class_start <serviceclass> Start all services of the specified class if they are not already running.
Class_stop <serviceclass> stop all services of the specified class if they are currently running.
Domainname <Name> set the domain name.
Insmod <path> install the module at <path>.
Mkdir <path> make a directory at <path>.
Mount <type> <device> <dir> [<mountoption>] * attempt to mount the named device at the directory <dir> <device>. this may be of the form MTD @ name to specify a MTD block device by name.
Setkey-currenlty undefined-
Setprop <Name> <value> set system property <Name> to <value>.
Setrlimit <resource> <cur> <max> set the rlimit for a resource.
Start <service> Start a service running if it is not already running.
Stop <service> stop a service from running if it is currently running.
Symlink <target> <path> Create a symbolic link at <path> with the value <target>.
Write <path> <string> [<string>] * open the file at <path> and write one or more strings to it with write (2 ).

Properties)
The initialization program (init) can modify system attributes as needed.
Attribute description
Init. Action equal to the name of the action currently being executed or "" If none.
Init. command equal to the command being executed or "" If none.
Init. SVC. <Name> state of a named Service ("STOPPED", "running", or "Restarting ").

Init. RC file example
On Boot
Export path/sbin:/system/bin
Export LD_LIBRARY_PATH/system/lib
Mkdir/dev
Mkdir/proc
Mkdir/sys
Mount tmpfs/dev
Mkdir/dev/PTS
Mkdir/dev/socket
Mount devpts/dev/PTS
Mount proc/proc
Mount sysfs/sys
Write/proc/CPU/alignment 4
IFUP Lo
Hostname localhost
Domainname localhost
Mount yaffs2 MTD @ system/System
Mount yaffs2 MTD @ userdata/Data
Import/system/etc/init. conf
Class_start default
Service adbd/sbin/adbd
User ADB
Group ADB
Service usbd/system/bin/usbd-R
User usbd
Group usbd
Socket usbd 666
Service zygote/system/bin/app_process-xzygote/system/bin -- zygote
Socket zygot 666
Service runtime/system/bin/Runtime
User System
GROUP SYSTEM
On device-added-/dev/compass
Start akmd
On device-removed-/dev/compass
Stop akmd
Service akmd/sbin/akmd
Disabled
User akmd
Group akmd

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.