安卓系统启动脚本init.rc说明文件readme.txt翻译

时间:2022-09-11 21:12:42

本说明文件位于system/core/init/readme.txt

本文参考深入解析安卓系统一书,进行翻译,版权部分归书的作者  刘超,资深Android专家,系统架构师。

博客地址:http://blog.csdn.net/u013234805/article/details/45438219

Android Init Language

---------------------

The Android Init Language consists of four broadclasses of statements,

which are Actions, Commands, Services, and Options.

安卓的初始化脚本语言包括了4种基本的类型声明:行为,命令,
服务和选项。

All of these are line-oriented, consisting of tokensseparated by

whitespace.  Thec-style backslash escapes may be used to insert

whitespace into a token.  Double quotes may also be used to prevent

whitespace from breaking text into multipletokens.  The backslash,

when it is the last character on a line, may be usedfor line-folding.

所有的这些都以行为单位,各种符号则由空格分开。当然,C语言风格种的\反斜杠符号用在符号的期间插入相应的空格。双引号可以用于防止字符串被空格分割成多个记号。行的最后的反斜杠用于折行。

Lines which start with a # (leading whitespaceallowed) are comments.

注释的方法是以#号开头,当然也可以以空格开头。

Actions and Services implicitly declare a newsection.  All commands

or options belong to the section most recentlydeclared.  Commands

or options before the first section are ignored.

行为和服务声明一个新的分组。所有命令或者是选项都依赖于最近所声明的分组里。其中位于分组之前的命令或者是选项将会被忽略。

Actions and Services have unique names.  If a second Action or Service

is declared with the same name as an existing one, itis ignored as

an error.  (???should we override instead)

行为和服务有着独特的名字。如果第二行为或者服务宣告名字已经存在。那么这会导致行为或者服务被忽略或者产生相应的错误。(也许会被覆盖)

Actions 
行为

-------

Actions are named sequences of commands.  Actions have a trigger which

is used to determine when the action shouldoccur.  When an event

occurs which matches an action's trigger, that actionis added to

the tail of a to-be-executed queue (unless it isalready on the

queue).

行为Actions其实就是一个序列的命令的集合。每个行为都有一个触发器trigger,触发器的作用决定了行为的什么时候将要执行。当一个符合Action触发条件的事件发生了,这个行为会加入到执行这个队列的结尾。

Each action in the queue is dequeued in sequence andeach command in

that action is executed in sequence.  Init handles other activities

(device creation/destruction, property setting,process restarting)

"between" the execution of the commands inactivities.

每一个行为都依次从队列里面被不断的取出来,然后这个行为的的每一个命令都将被一一执行。在这些命令执行的时候,init还同时处理着其它的活动,包括了设备节点的创建和销毁,设置属性,重新启动进程。

Actions take the form of:

Actions行为的格式如下:

on <trigger>

<command>

<command>

<command>

Services
服务

--------

Services are programs which init launches and(optionally) restarts

when they exit. Services take the form of:

服务其实是一个后台的程序,这个程序在init进程中被启动,如果退出了可以由系统重新启动(可选择)。

服务的格式如下:

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

<option>

<option>

...

Options
选项

-------

Options are modifiers to services.  They affect how and when init

runs the service.

选项是服务的一个修订项,他们决定了一个服务什么时候执行以及是如何去执行。

critical

This is adevice-critical service. If it exits more than four times in

four minutes,the device will reboot into recovery mode.

Critical表示这是一个关键的服务。如果服务4分钟内重新启动超过4次的情况下,系统将会重新启动进入recovery模式。

disabled

This servicewill not automatically start with its class.

It must beexplicitly started by name.

Disable表示服务不会通过trigger触发器启动,它必须是以命令“start service_name”的形式来进行启动。

setenv <name> <value>

Set theenvironment variable <name> to <value> in the launched process.

在服务启动的时候将环境变量name设置成value

socket <name> <type> <perm> [<user> [ <group> [ <context> ] ] ]

Create a unixdomain socket named /dev/socket/<name> and pass

its fd to thelaunched process.  <type> must be"dgram", "stream" or "seqpacket".

User andgroup default to 0. 
用户和组默认为0

Context isthe SELinux security context for the socket.

It defaultsto the service security context, as specified by seclabel or

computedbased on the service executable file security context.

创建名为/dev /socket/<name> UNIX域套接字,并传递

???其文件描述符fd的推出进程。 <类型>必须是“DGRAM”,“流”或“SEQPACKET”。

???用户和组默认为0。

???Context是套接字SELinux的安全上下文。

???它默认到服务的安全上下文,如SECLABEL指定或

???基于服务的可执行文件的安全上下文来计算。

user <username>

Change tousername before exec'ing this service.

Currentlydefaults to root.  (??? probably shoulddefault to nobody)

Currently, ifyour process requires linux capabilities then you cannot use

this command.You must instead request the capabilities in-process while

still root,and then drop to your desired uid.

在启动这个服务前设置服务的用户名,默认是root。如果你的进程没有相应的权限,你将不能使用这个命令。如果这个进程由root权限,可以在程序中设置到你想要

的组uid。

group <groupname> [ <groupname> ]*

Change togroupname before exec'ing this service. Additional

groupnamesbeyond the (required) first one are used to set the

supplementalgroups of the process (via setgroups()).

Currentlydefaults to root.  (??? probably shoulddefault to nobody)

在启动这个服务前设置服务的组名。除了第一个组名,剩下的组名通常用于设置进程的附加组(通过setgroups())。默认是root。

seclabel <securitycontext>

Change tosecuritycontext before exec'ing this service.

Primarily foruse by services run from the rootfs, e.g. ueventd, adbd.

Services onthe system partition can instead use policy-defined transitions

based on theirfile security context.

If notspecified and no transition is defined in policy, defaults to the init context.

SECLABEL<SecurityContext的>更改为执行该服务之前SecurityContext中。主要为按服务使用从根文件系统,例如运行ueventd,adbd。在系统分区服务可以改用基于其文件的安全上下文策略定义的转换。如果不指定,不转变政策规定,默认为初始化上下文。

oneshot

Do not restartthe service when it exits.服务在退出后不会再重新启动。

class <name>

Specify aclass name for the service.  All servicesin a

named classmay be started or stopped together.  Aservice

is in theclass "default" if one is not specified via the

class option.

给服务指定一个名字,所有的同名字的服务可以同时启动和停止。如果不通过class选项指定一个名字,则默认的名字是default

onrestart

Execute aCommand (see below) when service restarts.

当服务重启的时候,执行一条命令。

Triggers

--------

Triggers arestrings which can be used to match certain kinds

of events andused to cause an action to occur.

触发器是一个用于匹配某种事件类型的字符串,它将使对于的行为执行。

boot

This is thefirst trigger that will occur when init starts

(after/init.conf is loaded)

Boot是init执行后第一个触发的行为。在/init.conf被装载以后。

<name>=<value>

Triggers ofthis form occur when the property <name> is set

to thespecific value <value>.

这种形式的触发会在属性name设置为指定的值value时触发或者删除

device-added-<path>

device-removed-<path>

Triggers ofthese forms occur when a device node is added

or removed.

这种形式的触发器会在一个设备文件增加或者删除的时候触发。

service-exited-<name>

Triggers ofthis form occur when the specified service exits.

这种形式的触发器会在一个指定的服务退出的时候触发。

Commands
命令

--------

exec <path> [ <argument> ]*

Fork andexecute a program (<path>).  Thiswill block until

the programcompletes execution.  It is best to avoidexec

as unlike thebuiltin commands, it runs the risk of getting

init"stuck". (??? maybe there should be a timeout?)

Fork和启动第一个程序。在程序完成启动前,init将会阻塞。应该尽量避免使用exec,它可能会引起init卡死。

export <name> <value>

Set theenvironment variable <name> equal to <value> in the

globalenvironment (which will be inherited by all processes

started afterthis command is executed)

设置全局变量<name>为<value>,所有在这个命令执行后运行的进程都将继承该环境变量。

ifup <interface>

Bring thenetwork interface <interface> online.

启动网络接口interface

import <filename>

Parse an initconfig file, extending the current configuration.

引入一个init的配置文件,拓展当前配置。

hostname <name>

Set the hostname.

设置主机名。

chdir <directory>

Changeworking directory.

改变进程当前的工作目录。

chmod <octal-mode> <path>

Change fileaccess permissions.

设置文件或者目录的访问权限。

chown <owner> <group> <path>

Change fileowner and group.

设置文件或目录的所有者和组。

chroot <directory>

Change processroot directory.

设置进程的根目录。

class_start <serviceclass>

Start allservices of the specified class if they are

not alreadyrunning.

启动所有指定服务名称下的未运行服务。

class_stop <serviceclass>

Stop allservices of the specified class if they are

currently running.

停止所有指定服务名称下的已经运行的服务。

domainname <name>

Set thedomain name.

设置域名。

enable <servicename>

Turns adisabled service into an enabled one as if the service did not

specifydisabled.

If theservice is supposed to be running, it will be started now.

Typicallyused when the bootloader sets a variable that indicates a specific

serviceshould be started when needed. E.g.

onproperty:ro.boot.myfancyhardware=1

enablemy_fancy_service_for_my_fancy_hardware

启用<服务>如果服务没有指定禁用,则打开这个被禁用的服务。

如果服务是应该运行时,将立即开始。当引导加载程序设置一个变量,表示需要时一个特定的服务应启动通常使用。 例如:

service shouldbe started when needed. E.g.

onproperty:ro.boot.myfancyhardware=1

insmod <path>

Install themodule at <path>

安装一个驱动模块

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

Create adirectory at <path>, optionally with the given mode, owner, and

group. If notprovided, the directory is created with permissions 755 and

owned by theroot user and root group.

新建一个目录,可以指定访问权限、拥有者和组。如果没有被最后定,默认的访问权限是755,属于root用户和root组。

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

Attempt tomount the named device at the directory <dir>

<device> may be of the form mtd@name to specify a mtd block

device byname.

<mountoption>s include "ro", "rw","remount", "noatime", ...

在指定的目录下挂载一个设备。可以是以mtd@name的格式指定的一个mtd块设备。

<mountoption>包括了 "ro","rw", "remount", "noatime", ...

restorecon <path> [ <path> ]*

Restore thefile named by <path> to the security context specified

in thefile_contexts configuration.

Not requiredfor directories created by the init.rc as these are

automaticallylabeled correctly by init.

重新存储指定的文件到一个由file_contexts配置的安全上下文。不用指定目录,它们会被init进程自动创建。

restorecon_recursive <path> [ <path> ]*

Recursivelyrestore the directory tree named by <path> to the

securitycontexts specified in the file_contexts configuration.

Do NOT usethis with paths leading to shell-writable or app-writable

directories,e.g. /data/local/tmp, /data/data or any prefix thereof.

递归的restorecon<路径> [<路径>] *递归恢复通过<路径>命名的目录树中存储在file_contexts配置中指定的安全上下文。不要用路径,这会导致shell可写或应用可写目录,

例如使用/data/local/tmp, /data/data数据或任何其前缀。

setcon <securitycontext>

Set thecurrent process security context to the specified string.

This istypically only used from early-init to set the init context

before anyother process is started.

设置当前进程的安全上下文为指定的串。主要用在early-init中去设置init的安全上下文。

setenforce 0|1

Set theSELinux system-wide enforcing status.

0 ispermissive (i.e. log but do not deny), 1 is enforcing.

设置SELinux系统级的enforcing状态。0代表permissive(如记录但是不拒绝服务),1代表enforcing

setkey

TBD
目前没有使用

setprop <name> <value>

Set systemproperty <name> to <value>.

设置系统属性<name>为<value>值。

setrlimit <resource> <cur> <max>

Set therlimit for a resource.

设置系统属性<resource>的rlimit值。

setsebool <name> <value>

Set SELinuxboolean <name> to <value>.

<value>may be 1|true|on or 0|false|off

设置SELinux的boolean型属性"name"的值为"value"、"value"可以是1|true|on或者0|false|off

start <service>

Start aservice running if it is not already running.

如果服务没有被执行就启动指定的服务

stop <service>

Stop aservice from running if it is currently running.

如果服务在运行,那么就停止指定的服务。

symlink <target> <path>

Create asymbolic link at <path> with the value <target>

创建一个符号链接。

sysclktz <mins_west_of_gmt>

Set thesystem clock base (0 if system clock ticks in GMT)

设置系统时钟基准,0代表格林尼治平均时GMT为准。

trigger <event>

Trigger anevent.  Used to queue an action fromanother

Action.

触发一个事件。用于将一个行为和另一个行为连接在一起执行。

wait <path> [ <timeout> ]

Poll for theexistence of the given file and return when found,

or the timeouthas been reached. If timeout is not specified it

currentlydefaults to five seconds.

等待指定路径的文件创建出来,创建完成就停止等待,或者等待超时时间到。如果未指定超时时间,默认是5秒。

write <path> <string>

Open the fileat <path> and write a string to it with write(2)

withoutappending.

打开指定的文件,并写入一个或者多个字符串。

Properties
属性

----------

Init updates some system properties to provide someinsight into

what it's doing:

初始化更新一些系统属性来提供一些见解

它在做什么:

init.action

Equal to thename of the action currently being executed or "" if none

等于当前正在执行或行动“的名义”,如果没有

init.command

Equal to thecommand being executed or "" if none.

等于命令被执行或“”如果没有。

init.svc.<name>

State of anamed service ("stopped", "running","restarting")

一个名为服务的状态(“停止”,“运行”,“重新启动”)

Example init.conf
例如init.conf

-----------------

# not complete -- just providing some examples ofusage

#

#不完整 -
只是提供一些用法示例

on boot

export PATH/sbin:/system/sbin:/system/bin

export LD_LIBRARY_PATH /system/lib

mkdir /dev

mkdir /proc

mkdir /sys

mount tmpfstmpfs /dev

mkdir/dev/pts

mkdir/dev/socket

mount devptsdevpts /dev/pts

mount procproc /proc

mount sysfssysfs /sys

write /proc/cpu/alignment4

ifup lo

hostnamelocalhost

domainnamelocalhost

mount yaffs2mtd@system /system

mount yaffs2mtd@userdata /data

import/system/etc/init.conf

class_startdefault

service adbd /sbin/adbd

user adb

group adb

service usbd /system/bin/usbd -r

user usbd

group usbd

socket usbd666

service zygote /system/bin/app_process -Xzygote/system/bin --zygote

socket zygote666

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 stdoutand stderr into

/dev/null. To help with debugging, you can executeyour program via the

Andoird program logwrapper. This will redirectstdout/stderr into the

Android logging system (accessed via logcat).

默认情况下,由init执行的程序将标准输出和标准错误信息输出定向到/dev/ null的。为帮助调试,您可以通过执行Android程序logwrapper。这将标准输出/标准错误重定向到Android的日志系统(通过logcat的访问)。

For example

service akmd /system/bin/logwrapper /sbin/akmd

例如

service akmd /system/bin/logwrapper /sbin/akmd

安卓系统启动脚本init.rc说明文件readme.txt翻译的更多相关文章

  1. Android启动脚本init&period;rc说明文档readme&period;txt翻译

    Android Init Language--------------------- Android初始化语言--------------------- The Android Init Langua ...

  2. init进程 &amp&semi;&amp&semi; 解析Android启动脚本init&period;rc &amp&semi;&amp&semi; 修改它使不启动android &amp&semi;&amp&semi; init&period;rc中启动一个sh文件

    Android启动后,系统执行的第一个进程是一个名称为init 的可执行程序.提供了以下的功能:设备管理.解析启动脚本.执行基本的功能.启动各种服务.代码的路径:system/core/init,编译 ...

  3. Android启动脚本init&period;rc&lpar;2&rpar;

    在Android中使用启动脚本init.rc,可以在系统的初始化中进行简单的操作. init.rc启动脚本路径:system/core/rootdir/init.rc 内容: Commands:命令 ...

  4. 自启动脚本&sol;etc&sol;rc&period;local文件

    /etc目录下 rc文件均是/rc.d目录中的链接,需要添加自启,只要编辑/etc/rc.local即可

  5. android中init&period;rc文件的解析问题

    init.rc中文件里会通过import /init.${ro.hardware}.rc文件,这个ro.hardware应该是某个详细的属性.而这个ro.hardware赋值应该是在Init进程中赋值 ...

  6. Android init&period;rc解析【转】

    转自:http://www.linuxidc.com/Linux/2014-10/108438.htm 本文主要来自$Android_SOURCE/system/init/readme.txt的翻译. ...

  7. android 6 中init&period;rc的生成过程【转】

    本文转载自:https://blog.csdn.net/quhj/article/details/51819638 android 系统开机是会有一个初始化过程 init ,整个初始化过程是根据配置脚 ...

  8. Android如何配置init&period;rc中的开机启动进程&lpar;service&rpar;【转】

    本文转载自:http://blog.csdn.net/qq_28899635/article/details/56289063 开篇:为什么写这篇文章 先说下我自己的情况,我是个普通的大四学生,之前在 ...

  9. git中报错---fatal&colon; pathspec &&num;39&semi;readme&period;txt&&num;39&semi; did not match any files

    1.git安装 git官网下载最新版本,一键安装或custom install. 2.会弹出一个类似的命令窗口的东西,就说明Git安装成功. 3.安装完成后,还需要最后一步设置,在命令行输入如下--- ...

随机推荐

  1. oracle wrapped 代码解密工具 unwraper

    Oracle中的Wrap 功能是为了不让别人看到函数/存储过程的SQL源码的明文, 作为技术宅,有的时候想看源码但是看不到的那种心情是可以理解的, 发一个简单易用的 Oracle wrapped 解码 ...

  2. BIP&lowbar;Oracle Erp标准银行接口XML文件(案例)(待整理)

    2014-07-07 Created By BaoXinjian  

  3. java版大数相乘

    在搞ACM的时候遇到大数相乘的问题,在网上找了一下,看到了一个c++版本的 http://blog.csdn.net/jianzhibeihang/article/details/4948267 用j ...

  4. SVN允许修改日志

    1.强制写日志在每次提交的时候写明提交的目的是一个很好的习惯,Subversion默认没有提供,但是可以通过钩子实现:将下面的代码存为放到版本库的hooks目录下即可,当你不写日志提交的话就会报告错误 ...

  5. Oracle 11g完全卸载方案(注册表清理)

    1.如果数据库配置了自动存储管理(ASM),应该先删除聚集同步服务CSS(Cluster Synchronization Services). 删除CSS服务的方法是在DOS命令行中执行如下命令:   ...

  6. C&num;爬虫系列(一)——国家标准全文公开系统

    网上有很多Python爬虫的帖子,不排除很多培训班借着AI的概念教Python,然后爬网页自然是其中的一个大章节,毕竟做算法分析没有大量的数据怎么成. C#相比Python可能笨重了些,但实现简单爬虫 ...

  7. 阿里云ecs使用补充说明

    前置文章:http://www.cnblogs.com/newbob/articles/5400495.html 阿里云ecs使用心得的一些个人补充部分 一.在yum安装node/npm的过程中出现的 ...

  8. CSRF 和 XSS 的区别

    XSS 利用的是用户对指定网站的信任,CSRF 利用的是网站对用户网页浏览器的信任 XSS: 跨站脚本攻击 原名为Cross Site Scriptin,为避免和网页层级样式表概念混淆, 另名为XSS ...

  9. Node&period;js之mysql增删改查

    1.安装库 npm install mysql 2.编写db.js(用作公共模块) //连接MySQL数据库 var mysql = require("mysql"); var p ...

  10. 20155318 2016-2017-2 《Java程序设计》第九学习总结

    20155318 2016-2017-2 <Java程序设计>第九学习总结 教材学习内容总结 学习目标 了解JDBC架构 掌握JDBC架构 掌握反射与ClassLoader 了解自定义泛型 ...