注1:另外还讲述了怎样输出log:

Debugging notes
---------------
By default, programs executed by init will drop stdout and stderr into
/dev/null. To help with debugging, you can execute your program via the
Andoird program logwrapper. This will redirect stdout/stderr into the
Android logging system (accessed via logcat).
For example
service akmd /system/bin/logwrapper /sbin/akmd

注2:讲述了一个新的命令

sysclktz <mins_west_of_gmt>
   Set the system clock base (0 if system clock ticks in GMT)

注3:triggers

boot
   This is the first trigger that will occur when init starts
   (after /init.conf is loaded)
<name>=<value>
   Triggers of this form occur when the property <name> is set
   to the specific value <value>.
device-added-<path>
device-removed-<path>
   Triggers of these forms occur when a device node is added
   or removed.
service-exited-<name>
   Triggers of this form occur when the specified service exits.

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

init 由如下四种类型语句组成:

  • Actionn       :行为
  • Commands
  • Services
  • Options

语法(language syntax)结构如下:

  • 每一个语句占据一行,并且各个关键字被空格分开。c规范中的(如 \n)反斜杠将被忽略(backslash escapes)而被认为是一个空格 ,双引号用来保证空格不会把一个文字串分分为多个关键字。行最后的反斜杠用作续行。
  • 由 # (前面允许有空格)开始的行都是注释行(comment)
  • 一个actions 或 services 的开始隐含声明了一个新的段,所有commands 或 options 属于最近的声明。在第一个段之前的 commands 或 options 都会被忽略
  • 每一个actions 和 services 都有不同的名字。后面与前面发生重名的,那么这个后面重名的将被忽略或被认为是一个错误

Actions

Actions其实就是一组被命名的命令序列。actions 都有一个触发条件,触发条件决定了action何时执行。当一个事件发生如果匹配action的触发条件,那么这个action将会被添加到预备执行队列的尾部(除非它已经在队列当中)

每一个action中的命令将被顺序执行。init进程负责在其它activities(如:设备创建/销毁,属性设置,进程重启)之间执行这些命令序列。

action 的格式如下

on <trigger>   <command>   <command>   <command> 

Services

services 是一些由init 启动 和 重新(如果有需要)启动的程序,当然这些程序如果是存在的。

services 的格式如下:
  service <name> <pathname> [ <argument> ]*   <option>   <option>   ...  

Options

options 是service的修饰符,用来告诉init 怎样及何时启动service。

Option Description
disabled This service will not automatically start with its class. It must be explicitly started by name.
socket <type> <name> <perm> [ <user> [ <group> ] ]

Create a unix domain socket named /dev/socket/<name>and pass its fd to the launched process. Valid<type>dgram and streamuser and group default to 0.(type 实际中是放在name之后)

values include

user <username> Change to username before exec'ing this service. Currently defaults to root.
group <groupname> [ <groupname> ]* Change to groupname before exec'ing this service.  Additional  groupnames beyond the first, which is required, are used to set additional groups of the process (with setgroups()). Currently defaults to root.
capability [ <capability> ]+ Set linux capability before exec'ing this service
oneshot Do not restart the service when it exits.
class <name> Specify a class name for the service.  All services in a named class must start and stop together. A service is considered of class "default" if one is not specified via the class option.

Triggers

Triggers are strings used to match certain kinds of events that cause an action to occur.

Trigger Description
boot This is the first trigger that occurs when init starts (after /init.conf is loaded).
<name>=<value> Triggers of this form occur when the property <name> is set to the specific value<value>.
device-added-<path>
device-removed-<path>
Triggers of these forms occur when a device node is added or removed.
service-exited-<name> Triggers of this form occur when the specified service exits.

Commands

Command Description
exec <path> [ <argument> ]* Fork and execute a program (<path>). This will block until the program completes execution. Try to avoid exec. Unlike thebuiltin commands, it runs the risk of getting init "stuck".
export <name> <value> Set the environment variable <name> equal to <value> in the global environment (which will be inherited by all processes started after this command is executed).
ifup <interface> Bring the network interface <interface> online.
import <filename> Parse an init config file, extending the current configuration.
hostname <name> Set the host name.
class_start <serviceclass> Start all services of the specified class if they are not already running.
class_stop <serviceclass> Stop all services of the specified class if they are currently running.
domainname <name> Set the domain name.
insmod <path> Install the module at <path>.
mkdir <path> Make a directory at <path>.
mount <type> <device> <dir> [ <mountoption> ]* Attempt to mount the named device at the directory <dir><device>. This may be of the form mtd@name to specify a mtd block device by name.
setkey - currenlty undefined -
setprop <name> <value> Set system property <name> to <value>.
setrlimit <resource> <cur> <max> Set the rlimit for a resource.
start <service> Start a service running if it is not already running.
stop <service> Stop a service from running if it is currently running.
symlink <target> <path> Create a symbolic link at <path> with the value <target>.
write <path> <string> [ <string> ]* Open the file at <path> and write one or more strings to it with write(2).

Properties

Init updates some system properties to provide some insight into 
what it's doing:

Property Description
init.action Equal to the name of the action currently being executed or "" if none.
init.command Equal to the command being executed or "" if none.
init.svc.<name> State of a named service ("stopped", "running", or "restarting").

在init.rc中使用属性的范例如下:

setprop ro.FOREGROUND_APP_MEM 1536

setprop ro.VISIBLE_APP_MEM 2048

on property:ro.kernel.qemu=1

start adbd

setprop用于设置属性,on property可以用于判断属性,这里的属性在整个Android系统运行中都是一致的。

init脚本中的关键字可以参考:system/core/init/keywords.h

android init.rc命令快速对照表的更多相关文章

  1. Android init.rc解析【转】

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

  2. Android init.rc文件格式解析

    /***************************************************************************** * Android init.rc文件格式 ...

  3. Android init.rc文件浅析

    Android init.rc文件浅析 分类: Android2012-04-13 18:00 13149人阅读 评论(2) 收藏 举报 androidservicepathactionsocketc ...

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

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

  5. Android Init进程命令的执行和服务的启动

    这里开始分析init进程中配置文件的解析,在配置文件中的命令的执行和服务的启动. 首先init是一个可执行文件,它的对应的Makfile是init/Android.mk. Android.mk定义了i ...

  6. android init.rc 语法分析

    此文来自于对http://source.android.com/porting/index.html中bring up段的简译.其中有一处与源码的 system/core/init/readme.tx ...

  7. Android init.rc执行顺序

    转自:http://blog.csdn.net/kickxxx/article/details/7590665 1. 所有的action运行于service之前 2.  下面为各个section的执行 ...

  8. MTK(android init.rc) 写一个开机启动的服务

    在开机往往我们想要做一些初始化的操作,这时候可以使用init.rc文件来实现,当然书写一个开机启动的服务也需要规范的. 假设是C程序,则需要准备C程序的源码,在我的例程中是一个在开机完成(androi ...

  9. android init.rc语法

    转自:http://www.cnblogs.com/nokiaguy/p/3164799.html init.rc由如下4部分组成. 动作(Actions) 命令(Commands) 3. 服务(Se ...

随机推荐

  1. 日志收集系统Flume及其应用

    Apache Flume概述 Flume 是 Cloudera 提供的一个高可用的,高可靠的,分布式的海量日志采集.聚合和传输的系统.Flume 支持定制各类数据发送方,用于收集各类型数据:同时,Fl ...

  2. Vue之简易的留言板功能

    今天我将带大家通过Vue的todolist案例来完成一个简易的网页留言板! LES'T GO! 首先我们需要在页面上搭建一个input文本输入框,并设置提交按钮,通过循环指令来完成输入框的信息提交! ...

  3. 精通SpringBoot--整合Redis实现缓存

    今天我们来讲讲怎么在spring boot 中整合redis 实现对数据库查询结果的缓存.首先第一步要做的就是在pom.xml文件添加spring-boot-starter-data-redis.要整 ...

  4. B1019 数字黑洞 (20分)

    B1019 数字黑洞 (20分) 给定任一个各位数字不完全相同的 4 位正整数,如果我们先把 4 个数字按非递增排序,再按非递减排序,然后用第 1 个数字减第 2 个数字,将得到一个新的数字.一直重复 ...

  5. 动态规划:最长上升子序列之基础(经典算法 n^2)

    解题心得: 1.注意动态转移方程式,d[j]+1>d[i]>?d[i]=d[j]+1:d[i] 2.动态规划的基本思想:将大的问题化为小的,再逐步扩大得到答案,但是小问题的基本性质要和大的 ...

  6. HDU5952 Counting Cliques 暴搜优化

    一.前言 这题看上去相当唬人(NPC问题),但是 因为限制了一些条件,所以实际上并没有太唬人. 二.题目 给你一个图,要求你找出数量为S的团的数量. 三.题解 暴搜,再加上一些玄学优化. 优化1:使用 ...

  7. ZOJ 3231 Apple Transportation 树DP

    一.前言 红书上面推荐的题目,在138页,提到了关键部分的题解,但是实际上他没提到的还有若干不太好实现的地方.尤其是在这道题是大家都拿网络流玩弄的大背景下,这个代码打不出来就相当的揪心了..最后在牛客 ...

  8. UVA_10653 公主与王子 #刘汝佳DP题刷完计划

    题意如蓝书66页例题27所示. 这个问题描述了一个LCS的特殊情况——单个字符串内所有元素各不相同. 题目要求输入两个数字串,A,B,要求求出最长公共字串.且数字上限是256*256. 做法:数组A表 ...

  9. SpringMVC controller接收的中文参数乱码

    CharacterEncodingFilter只对POST请求有用,GET请求的需要对你运行的tomcat 目录conf/server.xml文件中<Connector connectionTi ...

  10. RF,GBDT,XGBoost,lightGBM的对比

    转载地址:https://blog.csdn.net/u014248127/article/details/79015803 RF,GBDT,XGBoost,lightGBM都属于集成学习(Ensem ...