android init.rc命令快速對照表


注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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM