GoogleGit

blob: 6b9c42d3fd53be74ad2500b25e35945ea4b86e2b [file] [log] [blame]
  1. Android Init Language
  2. ---------------------
  3. The Android Init Language consists of four broad classes of statements,
  4. which are Actions, Commands, Services, and Options.
  5. All of these are line-oriented, consisting of tokens separated by
  6. whitespace. The c-style backslash escapes may be used to insert
  7. whitespace into a token. Double quotes may also be used to prevent
  8. whitespace from breaking text into multiple tokens. The backslash,
  9. when it is the last character on a line, may be used for line-folding.
  10. Lines which start with a # (leading whitespace allowed) are comments.
  11. Actions and Services implicitly declare a new section. All commands
  12. or options belong to the section most recently declared. Commands
  13. or options before the first section are ignored.
  14. Actions and Services have unique names. If a second Action or Service
  15. is declared with the same name as an existing one, it is ignored as
  16. an error. (??? should we override instead)
  17. Actions
  18. -------
  19. Actions are named sequences of commands. Actions have a trigger which
  20. is used to determine when the action should occur. When an event
  21. occurs which matches an action's trigger, that action is added to
  22. the tail of a to-be-executed queue (unless it is already on the
  23. queue).
  24. Each action in the queue is dequeued in sequence and each command in
  25. that action is executed in sequence. Init handles other activities
  26. (device creation/destruction, property setting, process restarting)
  27. "between" the execution of the commands in activities.
  28. Actions take the form of:
  29. on <trigger>
  30. <command>
  31. <command>
  32. <command>
  33. Services
  34. --------
  35. Services are programs which init launches and (optionally) restarts
  36. when they exit. Services take the form of:
  37. service <name> <pathname> [ <argument> ]*
  38. <option>
  39. <option>
  40. ...
  41. Options
  42. -------
  43. Options are modifiers to services. They affect how and when init
  44. runs the service.
  45. critical
  46. This is a device-critical service. If it exits more than four times in
  47. four minutes, the device will reboot into recovery mode.
  48. disabled
  49. This service will not automatically start with its class.
  50. It must be explicitly started by name.
  51. setenv <name> <value>
  52. Set the environment variable <name> to <value> in the launched process.
  53. socket <name> <type> <perm> [ <user> [ <group> [ <seclabel> ] ] ]
  54. Create a unix domain socket named /dev/socket/<name> and pass
  55. its fd to the launched process. <type> must be "dgram", "stream" or "seqpacket".
  56. User and group default to 0.
  57. 'seclabel' is the SELinux security context for the socket.
  58. It defaults to the service security context, as specified by seclabel or
  59. computed based on the service executable file security context.
  60. user <username>
  61. Change to username before exec'ing this service.
  62. Currently defaults to root. (??? probably should default to nobody)
  63. Currently, if your process requires linux capabilities then you cannot use
  64. this command. You must instead request the capabilities in-process while
  65. still root, and then drop to your desired uid.
  66. group <groupname> [ <groupname> ]*
  67. Change to groupname before exec'ing this service. Additional
  68. groupnames beyond the (required) first one are used to set the
  69. supplemental groups of the process (via setgroups()).
  70. Currently defaults to root. (??? probably should default to nobody)
  71. seclabel <seclabel>
  72. Change to 'seclabel' before exec'ing this service.
  73. Primarily for use by services run from the rootfs, e.g. ueventd, adbd.
  74. Services on the system partition can instead use policy-defined transitions
  75. based on their file security context.
  76. If not specified and no transition is defined in policy, defaults to the init context.
  77. oneshot
  78. Do not restart the service when it exits.
  79. class <name>
  80. Specify a class name for the service. All services in a
  81. named class may be started or stopped together. A service
  82. is in the class "default" if one is not specified via the
  83. class option.
  84. onrestart
  85. Execute a Command (see below) when service restarts.
  86. Triggers
  87. --------
  88. Triggers are strings which can be used to match certain kinds
  89. of events and used to cause an action to occur.
  90. boot
  91. This is the first trigger that will occur when init starts
  92. (after /init.conf is loaded)
  93. <name>=<value>
  94. Triggers of this form occur when the property <name> is set
  95. to the specific value <value>.
  96. One can also test multiple properties to execute a group
  97. of commands. For example:
  98. on property:test.a=1 && property:test.b=1
  99. setprop test.c 1
  100. The above stub sets test.c to 1 only when
  101. both test.a=1 and test.b=1
  102. Commands
  103. --------
  104. bootchart_init
  105. Start bootcharting if configured (see below).
  106. This is included in the default init.rc.
  107. chmod <octal-mode> <path>
  108. Change file access permissions.
  109. chown <owner> <group> <path>
  110. Change file owner and group.
  111. class_start <serviceclass>
  112. Start all services of the specified class if they are
  113. not already running.
  114. class_stop <serviceclass>
  115. Stop and disable all services of the specified class if they are
  116. currently running.
  117. class_reset <serviceclass>
  118. Stop all services of the specified class if they are
  119. currently running, without disabling them. They can be restarted
  120. later using class_start.
  121. copy <src> <dst>
  122. Copies a file. Similar to write, but useful for binary/large
  123. amounts of data.
  124. domainname <name>
  125. Set the domain name.
  126. enable <servicename>
  127. Turns a disabled service into an enabled one as if the service did not
  128. specify disabled.
  129. If the service is supposed to be running, it will be started now.
  130. Typically used when the bootloader sets a variable that indicates a specific
  131. service should be started when needed. E.g.
  132. on property:ro.boot.myfancyhardware=1
  133. enable my_fancy_service_for_my_fancy_hardware
  134. exec [ <seclabel> [ <user> [ <group> ]* ] ] -- <command> [ <argument> ]*
  135. Fork and execute command with the given arguments. The command starts
  136. after "--" so that an optional security context, user, and supplementary
  137. groups can be provided. No other commands will be run until this one
  138. finishes.
  139. export <name> <value>
  140. Set the environment variable <name> equal to <value> in the
  141. global environment (which will be inherited by all processes
  142. started after this command is executed)
  143. hostname <name>
  144. Set the host name.
  145. ifup <interface>
  146. Bring the network interface <interface> online.
  147. import <filename>
  148. Parse an init config file, extending the current configuration.
  149. insmod <path>
  150. Install the module at <path>
  151. load_all_props
  152. Loads properties from /system, /vendor, et cetera.
  153. This is included in the default init.rc.
  154. load_persist_props
  155. Loads persistent properties when /data has been decrypted.
  156. This is included in the default init.rc.
  157. loglevel <level>
  158. Sets the kernel log level to level. Properties are expanded within <level>.
  159. mkdir <path> [mode] [owner] [group]
  160. Create a directory at <path>, optionally with the given mode, owner, and
  161. group. If not provided, the directory is created with permissions 755 and
  162. owned by the root user and root group. If provided, the mode, owner and group
  163. will be updated if the directory exists already.
  164. mount_all <fstab>
  165. Calls fs_mgr_mount_all on the given fs_mgr-format fstab.
  166. mount <type> <device> <dir> [ <flag> ]* [<options>]
  167. Attempt to mount the named device at the directory <dir>
  168. <device> may be of the form mtd@name to specify a mtd block
  169. device by name.
  170. <flag>s include "ro", "rw", "remount", "noatime", ...
  171. <options> include "barrier=1", "noauto_da_alloc", "discard", ... as
  172. a comma separated string, eg: barrier=1,noauto_da_alloc
  173. powerctl
  174. Internal implementation detail used to respond to changes to the
  175. "sys.powerctl" system property, used to implement rebooting.
  176. restart <service>
  177. Like stop, but doesn't disable the service.
  178. restorecon <path> [ <path> ]*
  179. Restore the file named by <path> to the security context specified
  180. in the file_contexts configuration.
  181. Not required for directories created by the init.rc as these are
  182. automatically labeled correctly by init.
  183. restorecon_recursive <path> [ <path> ]*
  184. Recursively restore the directory tree named by <path> to the
  185. security contexts specified in the file_contexts configuration.
  186. rm <path>
  187. Calls unlink(2) on the given path. You might want to
  188. use "exec -- rm ..." instead (provided the system partition is
  189. already mounted).
  190. rmdir <path>
  191. Calls rmdir(2) on the given path.
  192. setprop <name> <value>
  193. Set system property <name> to <value>. Properties are expanded
  194. within <value>.
  195. setrlimit <resource> <cur> <max>
  196. Set the rlimit for a resource.
  197. start <service>
  198. Start a service running if it is not already running.
  199. stop <service>
  200. Stop a service from running if it is currently running.
  201. swapon_all <fstab>
  202. Calls fs_mgr_swapon_all on the given fstab file.
  203. symlink <target> <path>
  204. Create a symbolic link at <path> with the value <target>
  205. sysclktz <mins_west_of_gmt>
  206. Set the system clock base (0 if system clock ticks in GMT)
  207. trigger <event>
  208. Trigger an event. Used to queue an action from another
  209. action.
  210. verity_load_state
  211. Internal implementation detail used to load dm-verity state.
  212. verity_update_state <mount_point>
  213. Internal implementation detail used to update dm-verity state and
  214. set the partition.<mount_point>.verified properties used by adb remount
  215. because fs_mgr can't set them directly itself.
  216. wait <path> [ <timeout> ]
  217. Poll for the existence of the given file and return when found,
  218. or the timeout has been reached. If timeout is not specified it
  219. currently defaults to five seconds.
  220. write <path> <content>
  221. Open the file at <path> and write a string to it with write(2).
  222. If the file does not exist, it will be created. If it does exist,
  223. it will be truncated. Properties are expanded within <content>.
  224. Properties
  225. ----------
  226. Init updates some system properties to provide some insight into
  227. what it's doing:
  228. init.action
  229. Equal to the name of the action currently being executed or "" if none
  230. init.command
  231. Equal to the command being executed or "" if none.
  232. init.svc.<name>
  233. State of a named service ("stopped", "running", "restarting")
  234. Bootcharting
  235. ------------
  236. This version of init contains code to perform "bootcharting": generating log
  237. files that can be later processed by the tools provided by www.bootchart.org.
  238. On the emulator, use the -bootchart <timeout> option to boot with bootcharting
  239. activated for <timeout> seconds.
  240. On a device, create /data/bootchart/start with a command like the following:
  241. adb shell 'echo $TIMEOUT > /data/bootchart/start'
  242. Where the value of $TIMEOUT corresponds to the desired bootcharted period in
  243. seconds. Bootcharting will stop after that many seconds have elapsed.
  244. You can also stop the bootcharting at any moment by doing the following:
  245. adb shell 'echo 1 > /data/bootchart/stop'
  246. Note that /data/bootchart/stop is deleted automatically by init at the end of
  247. the bootcharting. This is not the case with /data/bootchart/start, so don't
  248. forget to delete it when you're done collecting data.
  249. The log files are written to /data/bootchart/. A script is provided to
  250. retrieve them and create a bootchart.tgz file that can be used with the
  251. bootchart command-line utility:
  252. sudo apt-get install pybootchartgui
  253. # grab-bootchart.sh uses $ANDROID_SERIAL.
  254. $ANDROID_BUILD_TOP/system/core/init/grab-bootchart.sh
  255. One thing to watch for is that the bootchart will show init as if it started
  256. running at 0s. You'll have to look at dmesg to work out when the kernel
  257. actually started init.
  258. Debugging init
  259. --------------
  260. By default, programs executed by init will drop stdout and stderr into
  261. /dev/null. To help with debugging, you can execute your program via the
  262. Android program logwrapper. This will redirect stdout/stderr into the
  263. Android logging system (accessed via logcat).
  264. For example
  265. service akmd /system/bin/logwrapper /sbin/akmd
  266. For quicker turnaround when working on init itself, use:
  267. mm -j
  268. m ramdisk-nodeps
  269. m bootimage-nodeps
  270. adb reboot bootloader
  271. fastboot boot $ANDROID_PRODUCT_OUT/boot.img
  272. Alternatively, use the emulator:
  273. emulator -partition-size 1024 -verbose -show-kernel -no-window
  274. You might want to call klog_set_level(6) after the klog_init() call
  275. so you see the kernel logging in dmesg (or the emulator output).