Android Init language

Source: Internet
Author: User

The init.rc file is not a normal profile, but rather a file written by a script known as the "Android Init language" (Android initialization Language, which is referred to as ail here).

The AIL consists of the following 4 parts:

1. Actions (Actions)

2. Command (Commands)

3. Service (services)

4. Option (Options)

These 4 parts are line-oriented code, that is, a carriage return newline character as the delimiter for each statement. The code for each line is represented by multiple symbols (Tokens). You can use the backslash escape character to insert spaces in tokens. Double quotation marks can synthesize multiple tokens of a space-delimited tokens. If a line doesn't fit, you can concatenate the next line by adding a backslash at the end of the row. That is, you can concatenate multiple lines of code into a single line of code with a back slash.

Ail comments with a lot of shell script lines, beginning with #.

The AIL needs to be divided into multiple sections (section) at the time of writing, and an actions or services must be specified at the beginning of each section. That is, each of the actions or services determines a section. All commands and options can only be part of the recently defined section. If the commands and options are defined before the first section, they are ignored.

The names of the actions and services must be unique. If two or more actions or service have the same name, Init throws an error when executing them and ignores the action and service.

Let's look at how actions, Services, commands, and options should be set separately.

The syntax format for actions is as follows:

On <trigger>

<command>

<command>

<command>

That is, the actions start with the keyword, followed by a trigger, followed by a number of commands. For example, here is a standard action.

On boot

Ifup Lo

hostname localhost

DomainName Localdomain

Where boot is a trigger, the following three lines are command

So what triggers does init.rc support exactly? Currently INIT.RC supports the following 5 types of triggers.

1. Boot

This is the first triggered trigger after Init execution, which is the execution of the trigger after/init.rc is loaded

2. <name>=<value>

Triggered when property <name> is set to <value>. For example

On Property:vold.decrypt=trigger_reset_main

Class_reset Main

3. device-added-<path>

triggered when a device node is added

4. device-removed-<path>

Added when device node is removed

5. service-exited-<name>

Triggers when a particular service exits

After actions, you need to follow a number of commands, such as the following:

1. exec <path>[<argument>]*

Create and execute a program (<path>). INIT will block until the program is fully executed. Because it is not a built-in command, you should try to avoid using exec, which may cause init execution to time out.

2. Export <name> <value>

Set the value of the <name> variable to <value> in the global environment. (This will be inherited by all processes running after this command)

3. Ifup <interface>

Start the network interface

4. Import <filename>

Specifies the additional configuration files to resolve. is often used for extensions of the current configuration file

5. Hostname <name>

Set host name

6. ChDir <directory>

Change the working directory

7. chmod<octal-mode><path>

Change the access rights of a file

8. Chown<owner><group> <path>

Change the owner and group of files

9. Chroot <directory>

Change the processing root directory

Ten. class_start<serviceclass>

Starts the non-running service under all specified service classes.

Class_stop<serviceclass>

Stops all services that are running under the specified service class.

DomainName <name>

Set the domain name

Insmod <path>

Load <path> specified drive modules

mkdir <path>[mode][owner] [group]

Create a directory <path>, optionally specifying mode, owner, and group. If not specified, the default permissions are 755 and belong to the root user and root group.

Mount <type> <device> <dir>[<mountoption>]*

An attempt was made to mount the specified device in directory <dir>. <device> can be [email protected] in the form of specifying a MTD block device. <mountoption> includes "Ro", "RW", "Re

Setkey.

Reserved, temporarily unused

Setprop<name><value>.

Set the value of System Properties <name> to <value>.

Setrlimit <resource> <cur> <max>

Set up <resource> rlimit (resource limit)

. Start <service>

Starts the specified service (if the service is not running).

20. Stop<service>

Stops the specified service (if the service is running).

Symlink <target> <path>

Create a soft link <target> to <path>.

Sysclktz <mins_west_of_gmt>

Set the system clock base (0 for clock ticks, whichever is Greenwich Mean Time (GMT))

Trigger <event>

Triggers an event. For Action queuing

Wait <path>[<timeout>]

Waits for a file to exist, returns immediately when the file exists, or returns after the timeout specified by <timeout>, if <TIMEOUT> is not specified, the default time-out is 5 seconds.

Write <path> <string> [<string>]*

Writes one or more strings to the file specified by <path>.

Services is a program that starts at initialization and restarts (optionally) on exit. Services (service) is in the following form:

Service <name><pathname> [<argument>]*

<option>

<option>

For example, here 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 Services option is a service modifier that can affect how and how services are run. The following options are available for service support:

1. Critical

Indicates that this is a very important service. If the service exits more than 4 times within 4 minutes, the system restarts and enters Recovery (recovery) mode.

2. Disabled

Indicates that the service does not start automatically with the service under the same trigger (trigger). The service must be started explicitly by name.

3. setenv<name><value>

Set environment variables <name> to <value> at process startup.

4. socket<name><type> <perm> [<user> [<group>]]

Create a UNIX domainsocketnamed/dev/socket/<name> and pass

Its FD to thelaunchedprocess. <type> must be "Dgram", "stream" or "Seqpacket".

User and group default to0.

Create a UNIX domain named/dev/socket/<name> socket and pass its file descriptor to the started process. <type> must be "Dgram", "stream" or "Seqpacket". The default is 0 for users and groups.

5. User <username>

Change the user name of the service before starting the service. This defaults to root.

6. Group <groupname>[<groupname>]*

Change the group name of the service before starting the service. In addition to the first group name (required), the attached group name is typically used to set up a supplemental group of processes (via the Setgroups function), and the file defaults to root.

7. OneShot

The service does not restart when it exits.

8. Class <name>

Specifies a service class. All services of the same class can be started and stopped at the same time. If you do not specify a class by using the Class option, the default is the "Default" class service.

9. Onrestart

When the service restarts, execute a life

Android Init language

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.