Android Startup script –init.rc

Source: Internet
Author: User

Using the startup script in Android Init.rc can perform some simple initialization operations during the initialization of the system. This script is directly installed on the target system's root filesystem and parsed by the Init executable. Init.rc is the startup script that is executed after Init is started.

We can modify the boot process by modifying the init.rc script. However, in general, we do not modify init.rc directly, but instead add or modify the additional initialization configuration we need in the file Init.%product%.rc file. Because the main function in INIT.C will continue parsing the init.%product%.rc file after parsing the init.rc. In particular, init.rc files and init.%product%.rc files are written in the Android Init language language.

Android Init language consists of four types of statements: Actions, Commands, Services, Options.

–actions–
Actions are the naming of a series of commands. The actions have a trigger (trigger) that determines when the action executes. When an action is executed when the trigger condition is met, it is added to the queue at the end if it is not yet added to the pending queue.
The action in the queue executes sequentially, and the command in the action executes sequentially. Init handles other activities (device creation/destruction, property settings, Process restarts) in the middle of executing the command.
The actions are expressed in the following form:
On <trigger>
<command>
<command>
<command>

–services–
Services are initiated by Init and are optionally restarted when they exit. Service representations are:
Service <name> <pathname> [<argument>]*
<option>
<option>

–options–
Options are the adornments of services that affect when and how the service is run by Init.

Critical
This is a Device critical service (device-critical services). If it exits more than 4 times within 4 minutes, the device restarts and enters recovery mode.

Disabled
The level of this service will not start automatically, it must be started according to the service name specified.

Setenv <name> <value>
Set the environment variable for the started process <name> value <value>.

Sockets <name> <type> <perm> [<user> [<group>]]
Create a UNIX domin socket named/dev/socket/<name>, and transfer its FD to the started process. <type> must be "Dgram" or "stream". Users and groups default to 0.

User <username>
Change the user name before executing the service. The current default is root. If your process requires Linux capabilities, you cannot use this command. You have to ask for power at or root and drop to the UID you need.

Group <groupname> [<groupname>]*
Change the group before executing the service. The group after the first group is set to the process attach group (via Setgroups ()). The current default is root.

OneShot
Does not restart after the service exits.

Class <name>
Specify a category name for the service. All services of the same class name can be started or stopped together. If a service that does not specify a category defaults to the "Default" class.

Onrestart
Executes a command when the service restarts.

–triggers–
A Triggers (trigger) is a string that can be used to match a type of event and execute an action.

Boot
This is the first trigger that executes when Init starts (when/init.conf is loaded).

<name>=<value>
Triggered when property <name> is set to the specified value <value>.

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

Service-exited-<name>
Triggered when the specified service is present.

–commands–
exec <path> [<argument>]*
Fork and execute a program (<path>). This will be blocked by the block until the program executes. It is best to avoid executing programs such as the built-in command, which may cause Init to be blocked.

Export <name> <value>
Set the value of the Global environment variable <name> <value> When this command is executed, all processes can be obtained.

Ifup <interface>
Make the network interface <interface> online.

Import <filename>
Parses an init configuration file, extending the current profile.

Hostname <name>
Set the host name.

chmod <octal-mode> <path>
Change file access permissions.

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

Class_start <serviceclass>
When a service of the specified category is not running, start all services for that category.

Class_stop <serviceclass>
When a service of the specified category is running, stop all services in that category.

DomainName <name>
Set the domain name.

Insmod <path>
The module that loads the path <path>.

mkdir <path> [mode] [owner] [group]
Create a directory in <path>, optional options: MoD, owner, group. If not specified, the directory is created with 755 permissions and owner is root,group for root.

Mount <type> <device> <dir> [<mountoption>]*
Try Mount <device> to directory <dir>. <device> can be named to specify a MTD block device in the format. <mountoption> contains "Ro", "RW", "remount", "Noatime".

Setkey
Not at the moment.

SetProp <name> <value>
Set the value <value> for system property <name>.

Setrlimit <resource> <cur> <max>
Sets the rlimit of the resource.

Start <service>
Start a service that is not running.

Stop <service>
Stop a service that is running.

Symlink <target> <path>
Create a <path> symbol link to <target>.

Sysclktz <mins_west_of_gmt>
Set the system time zone (GMT is 0).

Trigger <event>
Triggers an event. Used to invoke another action.

Write <path> <string> [<string>]*
Open the <path> file and write one or more strings.

–properties–
Init will update some system property to provide a view of what it is doing.

Init.action
The action that is currently executing, or "" if it is not.

Init.command
The command to be executed, or "" if not.

Init.svc.<name>

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.