Android initialization language (init. rc syntax), androidinit. rc

Source: Internet
Author: User

Android initialization language (init. rc syntax), androidinit. rc

This article is the translation of ANDROID_SOURCE/system/core/init/readme.txt.


Android initialization Language

The android initialization language contains four types of statements:

  • Action
  • Command
  • Service
  • Option

All statements are row-oriented and separate several tokens contained in each line by spaces. The C-style backslash can be used to insert spaces into the token. Double quotation marks can also avoid spaces that divide the text into multiple tokens. When the backslash is the last character of a line, it is used to continue the line (PS: The next line also belongs to this sentence ).

A line starting with # (with spaces in front) is a comment.

Action and Service implicitly define a new section. All commands or options belong to the recently defined section. The Command or Option before the first section will be ignored.

Action and Service have a unique name. If a second Action or Service is defined as the same name as an existing Action or Service, it will be ignored as an error.


Action

Action is a series of commands with names. An Action has a tirgger (trigger) used to determine when the Action should be executed. When an event matches the trigger of an Action, the corresponding Action will be added to the forthcoming execution (to-be-executed) the end of the queue (unless she is already in the queue ).

Each action is ordered in the queue, and the command in each action is executed sequentially. During command execution, init also executes other activities (device node creation/destruction, Property setting, and process restart ).

Action has the following format:

on <trigger>   <command>   <command>   <command>

Service

The Service is an init loaded program and an optional program that exits and restarts. The Service format is as follows:

service <name> <pathname> [ <argument> ]*   <option>   <option>   ...

Option

Option is the modifier of the Service. They affect how and when init runs the Service. Available options include:

Critical
This is a critical service. If it exceeds four times in four minutes, the phone restarts and enters the recovery mode.

Disabled
This type of service does not start automatically. It must be explicitly started by name.

Setenv <name> <value>
Set the environment variable <name >=< value> In the loaded process.

Socket <name> <type> <perm> [<user> [<group> [<context>]
Create a UNIX socket named/dev/socket/<name> and pass fd to the loading process.
<Type> it must be "dgram", "stream", or "seqpacket.
<User> and <group> are 0 by default.
<Context> it is the security context of SELinux socket. The default value is the service security level. You can specify it as seclabel or calculate it based on the security level of the executable files of the service.

User <username>
Change the user name before executing the service. The default value is root. If your process requests special Linux capabilities, do not use this command. You need to replace this method by entering the process as root> request privilege> switch to your desired uid.

Group <groupname> [<groupname>] *
Change the group name before executing the service. The first and later additional group names are used to set the additional group of processes (via setgroups ()). The default value is root.

Seclabel <securitycontext>
Change the security level before executing the service. It is mainly used to execute services from rootfs, such as ueventd and adbd. on the system partition, you can use the transition defined based on the file security level policy. If no transition is specified and no policy is defined, the default value is the init context.
Change to securitycontext before exec 'ing this service.
Primarily for use by services run from the rootfs, e.g. ueventd, adbd.
Services on the system partition can instead use policy-defined transitions
Based on their file security context.
If not specified and no transition is defined in policy, defaults to the init context.

Oneshot
Exit and do not restart the Service (a real name, one time ).

Class <name>
Specify a class name for a service. All services with the same class name can be started or stopped together. If the class name is not specified with the class option, the service belongs to "default ".

Onrestart
Run the command when the service is restarted.


Trigger

A trigger is a string that can be used to match some types of events and to trigger a behavior.

Boot
This is the first trigger triggered after init is started (after Init. conf is loaded ).

<Name >=< value>
This trigger is triggered when the trigger attribute <name> is set to <value>.

Device-added-<path>
Device-removed-<path>
Triggers is triggered when the <path> device node is added or removed.

Service-exited-<name>
Triggers in this form will be triggered when the specified service exits.


Command

Exec <path> [<argument>] *
Create and execute the program (<path>). This will block init until the program execution is complete. Because it is not a built-in command, try to avoid using exec, which may cause init to become stuck.

Export <name> <value>
In the global environment variable, set the environment variable <name> to <value>. (This will be inherited by all processes running after this command)

Ifup <interface>
Start Network interface <interface>

Import <filename>
Parse an init configuration file to extend the current configuration.

Hostname <name>
Set the host name.

Chdir <directory>
Change the working directory.

Chmod <octal-mode> <path>
Change the file access permission.

Chown <owner> <group> <path>
Change the file owner and group.

Chroot <directory>
Change the root directory of a process.

Class_start <serviceclass>
Start all services that are not running.

Class_stop <serviceclass>
Stop all running services of this class.

Domainname <name>
Set the domain name.

Enable <servicename>
Change a disable service to enabled, as if they were not explicitly disabled. If the service is already running, it will be started immediately. A typical usage is that when bootloader sets a variable to indicate a specific variable, the service should be started. For example:

     on property:ro.boot.myfancyhardware=1        enable my_fancy_service_for_my_fancy_hardware

Insmod <path>
Install the <path> module (PS: Driver ).

Mkdir <path> [mode] [owner] [group]
Create a directory in <path>. (optional) use the given mode and the owner group. If the directory is not provided, the 755 permission will be applied to the directory. The owner is the root user and the group is the root user.

Mount <type> <device> <dir> [<mountoption>] *
Try to mount <device> to <dir>. <device> The mtd block device with the specified name may be in the form of mtd @ name.
<Mountoption> including "ro", "rw", "remount", "noatime ",...

Restorecon <path> [<path>] *
Restore the security level configured in file_contexts for a file named <path>. The directory is automatically marked correctly by init and does not need to be created by init. rc.
Restorecon_recursive <path> [<path>] *

Recursive recovery <path> indicates the security level specified by the file_contexts configuration in the directory tree. Do not use shell or app-writable directories, such as/data/Locia/temp,/data, or directories with a prefix ).


Setcon <securitycontext>
Set the security context of the current process to a specific string. This is typically used only for setting the init context in early-init before all processes start.

Setenforce 0 | 1
Sets the enfoucing status of the SELinux system range. 0 is permissive (I. e. log but do not deny), 1 is enforcing.

Setkey
TBD

Setprop <name> <value>
Set system attribute <name> to <value>.

Setrlimit <resource> <cur> <max>
Set rlimit for a specific resource.

Setsebool <name> <value>
Set the bool type <name> of SELinux to <value>. <Value> may be 1 | true | on or 0 | false | off

Start <service>
Start a service (if the service has not been started ).

Stop <service>
Stop the Service (if running ).

Symlink <target> <path>
Create a symbolic connection, at <path> with the value <target>.

Sysclktz <mins_west_of_gmt>
Set the system clock base (0 if system clock ticks in GMT)

Trigger <event>
Trigger an event. One action queues another action.

Wait <path> [<timeout>]
Poll specific <path>, returned after it appears, or timeout arrives. If timeout is not specified, the default value is 5 seconds.

Write <path> <string>
Open a file in <path> and write (not append) the string <string>.


The Propertiesinit process updates some system attributes. The following are some specific attributes:

Init. action
It is equal to the action being executed, or "if not.

Init. command
It is equal to the command currently being executed, or "" if not.

Init. svc. <name>
Status of a famous service ("stopped", "running", "restarting ")

Example init. conf -----------------

# Not complete -- just providing some examples of usage
#
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

Debugging notes ---------------
By default, programs executed by init will drop stdout and stderr
/Dev/null. To help with debugging, you can execute your program via
Andoird program logwrapper. This will redirect stdout/stderr into
Android logging system (accessed via logcat ).

For example
Service akmd/system/bin/logwrapper/sbin/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.