Android Init语句主要有四大类说明语句构成:行为(Action)、命令(Command)、服务(Service)和选择(Option)。

Init语句以行为单位,由用空格隔开的字符构成。

C语言的反斜杠通常用作往字符中插入空格的用途,而双引号则可以避免字符被空格符分隔成多个独立的字符,当反斜杠用在一行的末尾的时候即意味着续行。


以#开始的语句是注释语句。

actions 或 services 隐含的声明了一个新的段,所有commands 或 options 属于最近的声明。第一个段之前的 commands 或 options 都会被忽略。
Actions和Services都有自己唯一的Name,当第二个Action或者Service被声明的时候会被作为一个Error忽视掉。
Actions是一组被命名的命令序列。Actions都有一个触发条件,触发条件决定了action何时执行。当一个事件发生了且匹配Action的触发条件,那么这个Action将会被添加到预备执行队列的尾部(除非它已经在队列当中)
顺序队列中的每个Action都会被移除且Action中的命令都将被顺序执行,init进程负责在其它activities(如:设备创建/销毁,属性设置,进程重启)之间执行这些命令序列。

Action 的格式如下:
on <trigger>
   <command>
   <command>
   <command>
Service 是由Init启动或当其退出后需要重启的程序,Service的格式如下:
service <name> <pathname> [ <argument> ]*
   <option>
   <option>
   ...
Option 是services的修饰词,他们影响service什么时候以及如何初始化和启动service

critical 

在4分钟之内如果重启4次以上,手机重启进入recovery模式
disabled   

服务不会自动启动,需要手动调用名字启动
setEnv <name> <value> 

设置变量name的值为value
socket <name> <type> <permission> [<user> [<group>]] 

开启一个unix域的socket,名字为/dev/socket/<name> , <type>只能是dgram或者stream,<user>和<group>默认为0
user <username> 

将user 设置为 username
group <groupname> 

将group 设置为groupname
oneshot 

Service退出后不能重启
class <name> 

指定一个要启动的类,这个类中如果有多个service,将会被同时启动。默认的class将会是“default”
onrestart 

在服务重启的时候执行一条命令

Trigger

Boot 

第一次触发,当init.conf已经加载后
<name>=<value> 

当name设置为value时触发
Device-added-<path> 

Device添加时触发
Sevice-exited-<name> 

特定service退出时触发

Commands

exec <path> [ <argument> ]*

   执行一个<path>指定的程序

   export <name> <value>
   设置一个全局变量

   ifup <interface>
   使网络接口<interface>连接

   import <filename>
   引入其他的配置文件

   hostname <name>
   设置主机名

   chdir <directory>
   切换工作目录

   chmod <octal-mode> <path>
   设置访问权限

   chown <owner> <group> <path>
   设置用户和组
 
   chroot <directory>
   设置根目录

   class_start <serviceclass>
   启动类中的service

   class_stop <serviceclass>
   停止类中的service

   domainname <name>
   设置域名

   insmod <path>
   安装模块

   mkdir <path> [mode] [owner] [group]
   创建一个目录,并可以指定权限,用户和组

   mount <type> <device> <dir> [ <mountoption> ]*
   加载指定设备到目录下
   <mountoption> 包括"ro", "rw", "remount", "noatime"

   setprop <name> <value>
   设置系统属性

   setrlimit <resource> <cur> <max>
   设置资源访问权限

   start <service>
   开启服务

   stop <service>
   停止服务

   symlink <target> <path>
   创建一个动态链接

   sysclktz <mins_west_of_gmt>
   设置系统时钟

   trigger <event>
   触发事件

   write <path> <string> [ <string> ]*
   向<path>路径的文件写入多个<string>

   其中restorecon 和restorecon recurise 以及setcon,由于对selinux不是很熟,大概明白将参数内容设置为selinux 安    全文本格式。