blob: 9c2422019fd4f5a4a85f22ecc6ea01ba66582e30 [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> [ <context> ] ] ]
  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. Context 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 <securitycontext>
  72. Change to securitycontext 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. exec <path> [ <argument> ]*
  105. This command is not implemented.
  106. execonce <path> [ <argument> ]*
  107. Fork and execute a program (<path>). This will block until
  108. the program completes execution. This command can be run at most
  109. once during init's lifetime. Subsequent invocations are ignored.
  110. It is best to avoid exec as unlike the builtin commands, it runs
  111. the risk of getting init "stuck".
  112. export <name> <value>
  113. Set the environment variable <name> equal to <value> in the
  114. global environment (which will be inherited by all processes
  115. started after this command is executed)
  116. ifup <interface>
  117. Bring the network interface <interface> online.
  118. import <filename>
  119. Parse an init config file, extending the current configuration.
  120. hostname <name>
  121. Set the host name.
  122. chdir <directory>
  123. Change working directory.
  124. chmod <octal-mode> <path>
  125. Change file access permissions.
  126. chown <owner> <group> <path>
  127. Change file owner and group.
  128. chroot <directory>
  129. Change process root directory.
  130. class_start <serviceclass>
  131. Start all services of the specified class if they are
  132. not already running.
  133. class_stop <serviceclass>
  134. Stop all services of the specified class if they are
  135. currently running.
  136. domainname <name>
  137. Set the domain name.
  138. enable <servicename>
  139. Turns a disabled service into an enabled one as if the service did not
  140. specify disabled.
  141. If the service is supposed to be running, it will be started now.
  142. Typically used when the bootloader sets a variable that indicates a specific
  143. service should be started when needed. E.g.
  144. on property:ro.boot.myfancyhardware=1
  145. enable my_fancy_service_for_my_fancy_hardware
  146. insmod <path>
  147. Install the module at <path>
  148. loglevel <level>
  149. Sets the kernel log level to level. Properties are expanded within <level>.
  150. mkdir <path> [mode] [owner] [group]
  151. Create a directory at <path>, optionally with the given mode, owner, and
  152. group. If not provided, the directory is created with permissions 755 and
  153. owned by the root user and root group.
  154. mount <type> <device> <dir> [ <mountoption> ]*
  155. Attempt to mount the named device at the directory <dir>
  156. <device> may be of the form mtd@name to specify a mtd block
  157. device by name.
  158. <mountoption>s include "ro", "rw", "remount", "noatime", ...
  159. restorecon <path> [ <path> ]*
  160. Restore the file named by <path> to the security context specified
  161. in the file_contexts configuration.
  162. Not required for directories created by the init.rc as these are
  163. automatically labeled correctly by init.
  164. restorecon_recursive <path> [ <path> ]*
  165. Recursively restore the directory tree named by <path> to the
  166. security contexts specified in the file_contexts configuration.
  167. setcon <securitycontext>
  168. Set the current process security context to the specified string.
  169. This is typically only used from early-init to set the init context
  170. before any other process is started.
  171. setenforce 0|1
  172. Set the SELinux system-wide enforcing status.
  173. 0 is permissive (i.e. log but do not deny), 1 is enforcing.
  174. setkey
  175. TBD
  176. setprop <name> <value>
  177. Set system property <name> to <value>. Properties are expanded
  178. within <value>.
  179. setrlimit <resource> <cur> <max>
  180. Set the rlimit for a resource.
  181. setsebool <name> <value>
  182. Set SELinux boolean <name> to <value>.
  183. <value> may be 1|true|on or 0|false|off
  184. start <service>
  185. Start a service running if it is not already running.
  186. stop <service>
  187. Stop a service from running if it is currently running.
  188. symlink <target> <path>
  189. Create a symbolic link at <path> with the value <target>
  190. sysclktz <mins_west_of_gmt>
  191. Set the system clock base (0 if system clock ticks in GMT)
  192. trigger <event>
  193. Trigger an event. Used to queue an action from another
  194. action.
  195. wait <path> [ <timeout> ]
  196. Poll for the existence of the given file and return when found,
  197. or the timeout has been reached. If timeout is not specified it
  198. currently defaults to five seconds.
  199. write <path> <content>
  200. Open the file at <path> and write a string to it with write(2).
  201. If the file does not exist, it will be created. If it does exist,
  202. it will be truncated. Properties are expanded within <content>.
  203. Properties
  204. ----------
  205. Init updates some system properties to provide some insight into
  206. what it's doing:
  207. init.action
  208. Equal to the name of the action currently being executed or "" if none
  209. init.command
  210. Equal to the command being executed or "" if none.
  211. init.svc.<name>
  212. State of a named service ("stopped", "running", "restarting")
  213. Bootcharting
  214. ------------
  215. This version of init contains code to perform "bootcharting": generating log
  216. files that can be later processed by the tools provided by
  217. On the emulator, use the new -bootchart <timeout> option to boot with
  218. bootcharting activated for <timeout> seconds.
  219. On a device, create /data/bootchart/start with a command like the following:
  220. adb shell 'echo $TIMEOUT > /data/bootchart/start'
  221. Where the value of $TIMEOUT corresponds to the desired bootcharted period in
  222. seconds. Bootcharting will stop after that many seconds have elapsed.
  223. You can also stop the bootcharting at any moment by doing the following:
  224. adb shell 'echo 1 > /data/bootchart/stop'
  225. Note that /data/bootchart/stop is deleted automatically by init at the end of
  226. the bootcharting. This is not the case with /data/bootchart/start, so don't
  227. forget to delete it when you're done collecting data.
  228. The log files are written to /data/bootchart/. A script is provided to
  229. retrieve them and create a bootchart.tgz file that can be used with the
  230. bootchart command-line utility:
  231. sudo apt-get install pybootchartgui
  232. ANDROID_SERIAL=<device serial number>
  233. $ANDROID_BUILD_TOP/system/core/init/
  234. Debugging init
  235. --------------
  236. By default, programs executed by init will drop stdout and stderr into
  237. /dev/null. To help with debugging, you can execute your program via the
  238. Android program logwrapper. This will redirect stdout/stderr into the
  239. Android logging system (accessed via logcat).
  240. For example
  241. service akmd /system/bin/logwrapper /sbin/akmd
  242. For quicker turnaround when working on init itself, use:
  243. mm -j
  244. m ramdisk-nodeps
  245. m bootimage-nodeps
  246. adb reboot bootloader
  247. fastboot boot $ANDROID_PRODUCT_OUT/boot.img
  248. Alternatively, use the emulator:
  249. emulator -partition-size 1024 -verbose -show-kernel -no-window
  250. You might want to call klog_set_level(6) after the klog_init() call
  251. so you see the kernel logging in dmesg (or the emulator output).