Android initialization Language
The init. rc file is not a common configuration file, but a file written by a script called "Android Init Language" (AIL.
AIL consists of the following four parts:
1. Actions)
2. Command (Commands)
3. Services)
4. Options)
These four parts are line-oriented code, that is, the line breaks are used as the separator for each statement. Each line of code is represented by multiple symbols (Tokens. You can use the backslash escape character to insert spaces in the Token. Double quotation marks can combine multiple Tokens separated by spaces into one Tokens. If a row cannot be written, you can add a backslash at the end of the row to connect to the next row. That is to say, you can use a backslash to connect multiple lines of code into one line of code.
AIL comments and a line of many Shell scripts, starting.
AIL needs to be divided into multiple sections during writing, and Actions or Services must be specified at the beginning of each part. That is to say, each Actions or Services determines a Section. All Commands and Options can only belong to the recently defined Section. If Commands and Options are defined before the first Section, they are ignored.
The names of Actions and Services must be unique. If two or more actions or services have the same name, init will throw an error when executing them and ignore these actions and services.
Next let's take a look at how to set Actions, Services, Commands, and Options.
The syntax format of Actions is as follows:
On
That is to say, Actions starts with the keyword on, followed by a trigger, followed by several commands. For example, the following is a standard Action.
On boot
Ifup lo
Hostname localhost
Domainname localdomain
Among them, boot is the trigger, and the following three lines are command
So what triggers does init. rc support? Currently, init. rc supports the following five types of triggers.
1. boot
This is the first Trigger triggered after init is executed, that is, the Trigger is executed after/init. rc is loaded.
2. =
When the attribute Set Is triggered. For example,
On property: vold. decrypt = trigger_reset_main
Class_reset main
3. device-added-
Triggered when a device node is added
4. device-removed-
Added when the device node is removed
5. service-exited-
Will be triggered when a specific service exits
After Actions, several commands are required. These commands are as follows:
1. exec [] *
Create and execute a program ( ). Before the program is fully executed, init will be blocked. Because it is not a built-in command, try to avoid using exec, which may cause init execution timeout.
2. export
In the global environment Set the variable value . (This will be inherited by all processes running after this command)
3. ifup
Start Network Interface
4. import
Specify other configuration files to be parsed. It is often used for expansion of the current configuration file.
5. hostname
Set Host Name
6. chdir
Change working directory
7. chmod
Change File Access Permissions
8. chown
Change the file owner and group
9. chroot
Change the processing root directory
10. class_start
Start all services not running under the specified service class.
11 class_stop
Stop all running services under the specified service class.
12. domainname
Set Domain Name
13. insmod
Load Specified Driver Module
14. mkdir [Mode] [owner] [group]
Create a directory You can select mode, owner, and group. If not specified, the default permission is 755 and belongs to the root user and root group.
15. mount
[ ] *
Try
Mount the specified device. You can specify an mtd block device in the form of mtd @ name. Including ro, rw, and re
16. setkey
Reserved, unavailable for the moment
17. setprop
Set System Properties Is set .
18. setrlimit
Set (Resource restrictions)
19. start
Start the specified service (if the service is not running ).
20. stop
Stop the specified service (if the service is running ).
21. symlink
Create a point Soft connection .
22. sysclktz
Set the system clock benchmark (0 indicates that the clock tick is based on the Greenwich Mean Time (GMT)
23. trigger
Trigger an event. Used for Action queuing
24. wait [ ]
Wait for a file to exist. If the file exists, return immediately or Returned after the specified timeout. The default timeout value is 5 seconds.
25. write [ ] *
Direction The specified file is written into one or more strings.
A service is a program that is started during initialization and restarted upon exit (optional ). Services are as follows:
Service [] *
For example, the following is a standard Service usage
Service servicemanager/system/bin/servicemanager
Class core
User system
Group system
Critical
Onrestart restartzygote
Onrestart restartmedia
Onrestart restartsurfaceflinger
Onrestart restartdrm
The Service option is the modifier of the service, which can affect how and how the service runs. The Service supports the following options:
1. critical
This indicates that this is a very important service. If the service exits more than 4 times in four minutes, the system restarts and enters the Recovery (Recovery) mode.
2. disabled
This indicates that the service cannot be automatically started with the trigger. The service must be explicitly started by name.
3. setenv
When the process starts, set the environment variable Set .
4. socket [ [ ]
Create a unix domainsocketnamed/dev/socket/ And pass
Its fd to thelaunchedprocess. Must bedgram, stream or seqpacket.
User and group default to0.0.
Create a unix domain named/dev/socket/ And pass its file descriptor to the started process. It must be dgram, stream, or seqpacket. The default value of user and group is 0.
5. user
Change the User Name of the service before starting the service. The default value is root.
6. group [ ] *
Change the group name of the service before starting the service. Except (required) The first group name, the attached group name is usually used to set the supplemental group of the process (through the setgroups function), and the file is root by default.
7. oneshot
Do not restart when the service exits.
8. class
Specify a service class. All services of the same category can be started and stopped at the same time. If a class is not specified through the class option, the default class service is used by default.
9. onrestart
When the service is restarted