| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1 |  | 
 | 2 | Android Init Language | 
 | 3 | --------------------- | 
 | 4 |  | 
| Tom Cherry | 3be66ed | 2015-09-01 14:49:38 -0700 | [diff] [blame] | 5 | The Android Init Language consists of five broad classes of statements, | 
 | 6 | which are Actions, Commands, Services, Options, and Imports. | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 7 |  | 
 | 8 | All of these are line-oriented, consisting of tokens separated by | 
 | 9 | whitespace.  The c-style backslash escapes may be used to insert | 
 | 10 | whitespace into a token.  Double quotes may also be used to prevent | 
 | 11 | whitespace from breaking text into multiple tokens.  The backslash, | 
 | 12 | when it is the last character on a line, may be used for line-folding. | 
 | 13 |  | 
 | 14 | Lines which start with a # (leading whitespace allowed) are comments. | 
 | 15 |  | 
 | 16 | Actions and Services implicitly declare a new section.  All commands | 
 | 17 | or options belong to the section most recently declared.  Commands | 
 | 18 | or options before the first section are ignored. | 
 | 19 |  | 
| Tom Cherry | 3be66ed | 2015-09-01 14:49:38 -0700 | [diff] [blame] | 20 | Actions and Services have unique names.  If a second Action is defined | 
 | 21 | with the same name as an existing one, its commands are appended to | 
 | 22 | the commands of the existing action.  If a second Service is defined | 
 | 23 | with the same name as an existing one, it is ignored and an error | 
 | 24 | message is logged. | 
 | 25 |  | 
 | 26 |  | 
 | 27 | Init .rc Files | 
 | 28 | -------------- | 
 | 29 | The init language is used in plaintext files that take the .rc file | 
 | 30 | extension.  These are typically multiple of these in multiple | 
 | 31 | locations on the system, described below. | 
 | 32 |  | 
 | 33 | /init.rc is the primary .rc file and is loaded by the init executable | 
 | 34 | at the beginning of its execution.  It is responsible for the initial | 
 | 35 | set up of the system.  It imports /init.${ro.hardware}.rc which is the | 
 | 36 | primary vendor supplied .rc file. | 
 | 37 |  | 
 | 38 | During the mount_all command, the init executable loads all of the | 
 | 39 | files contained within the /{system,vendor,odm}/etc/init/ directories. | 
 | 40 | These directories are intended for all Actions and Services used after | 
 | 41 | file system mounting. | 
 | 42 |  | 
| Tom Cherry | 1fb20b8 | 2016-01-20 16:53:08 -0800 | [diff] [blame] | 43 | One may specify paths in the mount_all command line to have it import | 
 | 44 | .rc files at the specified paths instead of the default ones listed above. | 
 | 45 | This is primarily for supporting factory mode and other non-standard boot | 
 | 46 | modes.  The three default paths should be used for the normal boot process. | 
 | 47 |  | 
| Tom Cherry | 3be66ed | 2015-09-01 14:49:38 -0700 | [diff] [blame] | 48 | The intention of these directories is as follows | 
 | 49 |    1) /system/etc/init/ is for core system items such as | 
| Tom Cherry | 1fb20b8 | 2016-01-20 16:53:08 -0800 | [diff] [blame] | 50 |       SurfaceFlinger, MediaService, and logcatd. | 
| Tom Cherry | 3be66ed | 2015-09-01 14:49:38 -0700 | [diff] [blame] | 51 |    2) /vendor/etc/init/ is for SoC vendor items such as actions or | 
 | 52 |       daemons needed for core SoC functionality. | 
 | 53 |    3) /odm/etc/init/ is for device manufacturer items such as | 
 | 54 |       actions or daemons needed for motion sensor or other peripheral | 
 | 55 |       functionality. | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 56 |  | 
| Tom Cherry | 1fb20b8 | 2016-01-20 16:53:08 -0800 | [diff] [blame] | 57 | All services whose binaries reside on the system, vendor, or odm | 
 | 58 | partitions should have their service entries placed into a | 
 | 59 | corresponding init .rc file, located in the /etc/init/ | 
 | 60 | directory of the partition where they reside.  There is a build | 
 | 61 | system macro, LOCAL_INIT_RC, that handles this for developers.  Each | 
 | 62 | init .rc file should additionally contain any actions associated with | 
 | 63 | its service. | 
 | 64 |  | 
 | 65 | An example is the logcatd.rc and Android.mk files located in the | 
 | 66 | system/core/logcat directory.  The LOCAL_INIT_RC macro in the | 
 | 67 | Android.mk file places logcatd.rc in /system/etc/init/ during the | 
 | 68 | build process.  Init loads logcatd.rc during the mount_all command and | 
 | 69 | allows the service to be run and the action to be queued when | 
 | 70 | appropriate. | 
 | 71 |  | 
 | 72 | This break up of init .rc files according to their daemon is preferred | 
 | 73 | to the previously used monolithic init .rc files.  This approach | 
 | 74 | ensures that the only service entries that init reads and the only | 
 | 75 | actions that init performs correspond to services whose binaries are in | 
 | 76 | fact present on the file system, which was not the case with the | 
 | 77 | monolithic init .rc files.  This additionally will aid in merge | 
 | 78 | conflict resolution when multiple services are added to the system, as | 
 | 79 | each one will go into a separate file. | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 80 |  | 
 | 81 | Actions | 
 | 82 | ------- | 
 | 83 | Actions are named sequences of commands.  Actions have a trigger which | 
 | 84 | is used to determine when the action should occur.  When an event | 
 | 85 | occurs which matches an action's trigger, that action is added to | 
 | 86 | the tail of a to-be-executed queue (unless it is already on the | 
 | 87 | queue). | 
 | 88 |  | 
 | 89 | Each action in the queue is dequeued in sequence and each command in | 
 | 90 | that action is executed in sequence.  Init handles other activities | 
 | 91 | (device creation/destruction, property setting, process restarting) | 
 | 92 | "between" the execution of the commands in activities. | 
 | 93 |  | 
 | 94 | Actions take the form of: | 
 | 95 |  | 
| Tom Cherry | 3be66ed | 2015-09-01 14:49:38 -0700 | [diff] [blame] | 96 | on <trigger> [&& <trigger>]* | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 97 |    <command> | 
 | 98 |    <command> | 
 | 99 |    <command> | 
 | 100 |  | 
 | 101 |  | 
 | 102 | Services | 
 | 103 | -------- | 
 | 104 | Services are programs which init launches and (optionally) restarts | 
 | 105 | when they exit.  Services take the form of: | 
 | 106 |  | 
 | 107 | service <name> <pathname> [ <argument> ]* | 
 | 108 |    <option> | 
 | 109 |    <option> | 
 | 110 |    ... | 
 | 111 |  | 
 | 112 |  | 
 | 113 | Options | 
 | 114 | ------- | 
 | 115 | Options are modifiers to services.  They affect how and when init | 
 | 116 | runs the service. | 
 | 117 |  | 
 | 118 | critical | 
| Elliott Hughes | d62f060 | 2015-06-12 18:02:20 -0700 | [diff] [blame] | 119 |   This is a device-critical service. If it exits more than four times in | 
 | 120 |   four minutes, the device will reboot into recovery mode. | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 121 |  | 
 | 122 | disabled | 
| Elliott Hughes | d62f060 | 2015-06-12 18:02:20 -0700 | [diff] [blame] | 123 |   This service will not automatically start with its class. | 
 | 124 |   It must be explicitly started by name. | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 125 |  | 
 | 126 | setenv <name> <value> | 
| Elliott Hughes | d62f060 | 2015-06-12 18:02:20 -0700 | [diff] [blame] | 127 |   Set the environment variable <name> to <value> in the launched process. | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 128 |  | 
| Elliott Hughes | 8d82ea0 | 2015-02-06 20:15:18 -0800 | [diff] [blame] | 129 | socket <name> <type> <perm> [ <user> [ <group> [ <seclabel> ] ] ] | 
| Elliott Hughes | d62f060 | 2015-06-12 18:02:20 -0700 | [diff] [blame] | 130 |   Create a unix domain socket named /dev/socket/<name> and pass | 
 | 131 |   its fd to the launched process.  <type> must be "dgram", "stream" or "seqpacket". | 
 | 132 |   User and group default to 0. | 
 | 133 |   'seclabel' is the SELinux security context for the socket. | 
 | 134 |   It defaults to the service security context, as specified by seclabel or | 
 | 135 |   computed based on the service executable file security context. | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 136 |  | 
 | 137 | user <username> | 
| Elliott Hughes | d62f060 | 2015-06-12 18:02:20 -0700 | [diff] [blame] | 138 |   Change to username before exec'ing this service. | 
 | 139 |   Currently defaults to root.  (??? probably should default to nobody) | 
| Tom Cherry | dbddb40 | 2015-12-11 12:54:50 -0800 | [diff] [blame] | 140 |   As of Android M, processes should use this option even if they | 
 | 141 |   require linux capabilities.  Previously, to acquire linux | 
 | 142 |   capabilities, a process would need to run as root, request the | 
 | 143 |   capabilities, then drop to its desired uid.  There is a new | 
 | 144 |   mechanism through fs_config that allows device manufacturers to add | 
 | 145 |   linux capabilities to specific binaries on a file system that should | 
 | 146 |   be used instead. This mechanism is described on | 
 | 147 |   http://source.android.com/devices/tech/config/filesystem.html.  When | 
 | 148 |   using this new mechanism, processes can use the user option to | 
 | 149 |   select their desired uid without ever running as root. | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 150 |  | 
 | 151 | group <groupname> [ <groupname> ]* | 
| Elliott Hughes | d62f060 | 2015-06-12 18:02:20 -0700 | [diff] [blame] | 152 |   Change to groupname before exec'ing this service.  Additional | 
 | 153 |   groupnames beyond the (required) first one are used to set the | 
 | 154 |   supplemental groups of the process (via setgroups()). | 
 | 155 |   Currently defaults to root.  (??? probably should default to nobody) | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 156 |  | 
| Elliott Hughes | 8d82ea0 | 2015-02-06 20:15:18 -0800 | [diff] [blame] | 157 | seclabel <seclabel> | 
 | 158 |   Change to 'seclabel' before exec'ing this service. | 
| Stephen Smalley | 3fb6110 | 2012-11-02 15:22:34 -0400 | [diff] [blame] | 159 |   Primarily for use by services run from the rootfs, e.g. ueventd, adbd. | 
 | 160 |   Services on the system partition can instead use policy-defined transitions | 
 | 161 |   based on their file security context. | 
 | 162 |   If not specified and no transition is defined in policy, defaults to the init context. | 
 | 163 |  | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 164 | oneshot | 
| Elliott Hughes | d62f060 | 2015-06-12 18:02:20 -0700 | [diff] [blame] | 165 |   Do not restart the service when it exits. | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 166 |  | 
 | 167 | class <name> | 
| Elliott Hughes | d62f060 | 2015-06-12 18:02:20 -0700 | [diff] [blame] | 168 |   Specify a class name for the service.  All services in a | 
 | 169 |   named class may be started or stopped together.  A service | 
 | 170 |   is in the class "default" if one is not specified via the | 
 | 171 |   class option. | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 172 |  | 
 | 173 | onrestart | 
| Elliott Hughes | d62f060 | 2015-06-12 18:02:20 -0700 | [diff] [blame] | 174 |   Execute a Command (see below) when service restarts. | 
 | 175 |  | 
 | 176 | writepid <file...> | 
 | 177 |   Write the child's pid to the given files when it forks. Meant for | 
 | 178 |   cgroup/cpuset usage. | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 179 |  | 
| Elliott Hughes | 841b263 | 2015-02-12 14:28:54 -0800 | [diff] [blame] | 180 |  | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 181 | Triggers | 
 | 182 | -------- | 
| Tom Cherry | 3be66ed | 2015-09-01 14:49:38 -0700 | [diff] [blame] | 183 | Triggers are strings which can be used to match certain kinds of | 
 | 184 | events and used to cause an action to occur. | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 185 |  | 
| Tom Cherry | 3be66ed | 2015-09-01 14:49:38 -0700 | [diff] [blame] | 186 | Triggers are subdivided into event triggers and property triggers. | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 187 |  | 
| Tom Cherry | 3be66ed | 2015-09-01 14:49:38 -0700 | [diff] [blame] | 188 | Event triggers are strings triggered by the 'trigger' command or by | 
 | 189 | the QueueEventTrigger() function within the init executable.  These | 
 | 190 | take the form of a simple string such as 'boot' or 'late-init'. | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 191 |  | 
| Tom Cherry | 3be66ed | 2015-09-01 14:49:38 -0700 | [diff] [blame] | 192 | Property triggers are strings triggered when a named property changes | 
 | 193 | value to a given new value or when a named property changes value to | 
 | 194 | any new value.  These take the form of 'property:<name>=<value>' and | 
 | 195 | 'property:<name>=*' respectively.  Property triggers are additionally | 
 | 196 | evaluated and triggered accordingly during the initial boot phase of | 
 | 197 | init. | 
| Badhri Jagan Sridharan | 0b41512 | 2014-10-10 23:19:06 -0700 | [diff] [blame] | 198 |  | 
| Tom Cherry | 3be66ed | 2015-09-01 14:49:38 -0700 | [diff] [blame] | 199 | An Action can have multiple property triggers but may only have one | 
 | 200 | event trigger. | 
| Badhri Jagan Sridharan | 0b41512 | 2014-10-10 23:19:06 -0700 | [diff] [blame] | 201 |  | 
| Tom Cherry | 3be66ed | 2015-09-01 14:49:38 -0700 | [diff] [blame] | 202 | For example: | 
 | 203 | 'on boot && property:a=b' defines an action that is only executed when | 
 | 204 | the 'boot' event trigger happens and the property a equals b. | 
 | 205 |  | 
 | 206 | 'on property:a=b && property:c=d' defines an action that is executed | 
 | 207 | at three times, | 
 | 208 |    1) During initial boot if property a=b and property c=d | 
 | 209 |    2) Any time that property a transitions to value b, while property | 
 | 210 |       c already equals d. | 
 | 211 |    3) Any time that property c transitions to value d, while property | 
 | 212 |       a already equals b. | 
| Badhri Jagan Sridharan | 0b41512 | 2014-10-10 23:19:06 -0700 | [diff] [blame] | 213 |  | 
| Elliott Hughes | 841b263 | 2015-02-12 14:28:54 -0800 | [diff] [blame] | 214 |  | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 215 | Commands | 
 | 216 | -------- | 
 | 217 |  | 
| Elliott Hughes | 91a3be5 | 2015-03-20 11:00:15 -0700 | [diff] [blame] | 218 | bootchart_init | 
 | 219 |    Start bootcharting if configured (see below). | 
 | 220 |    This is included in the default init.rc. | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 221 |  | 
 | 222 | chmod <octal-mode> <path> | 
 | 223 |    Change file access permissions. | 
 | 224 |  | 
 | 225 | chown <owner> <group> <path> | 
 | 226 |    Change file owner and group. | 
 | 227 |  | 
 | 228 | class_start <serviceclass> | 
 | 229 |    Start all services of the specified class if they are | 
 | 230 |    not already running. | 
 | 231 |  | 
 | 232 | class_stop <serviceclass> | 
| Elliott Hughes | 91a3be5 | 2015-03-20 11:00:15 -0700 | [diff] [blame] | 233 |    Stop and disable all services of the specified class if they are | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 234 |    currently running. | 
 | 235 |  | 
| Elliott Hughes | 91a3be5 | 2015-03-20 11:00:15 -0700 | [diff] [blame] | 236 | class_reset <serviceclass> | 
 | 237 |    Stop all services of the specified class if they are | 
 | 238 |    currently running, without disabling them. They can be restarted | 
 | 239 |    later using class_start. | 
 | 240 |  | 
 | 241 | copy <src> <dst> | 
 | 242 |    Copies a file. Similar to write, but useful for binary/large | 
 | 243 |    amounts of data. | 
 | 244 |  | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 245 | domainname <name> | 
 | 246 |    Set the domain name. | 
 | 247 |  | 
| JP Abgrall | 3beec7e | 2014-05-02 21:14:29 -0700 | [diff] [blame] | 248 | enable <servicename> | 
 | 249 |    Turns a disabled service into an enabled one as if the service did not | 
 | 250 |    specify disabled. | 
 | 251 |    If the service is supposed to be running, it will be started now. | 
 | 252 |    Typically used when the bootloader sets a variable that indicates a specific | 
 | 253 |    service should be started when needed. E.g. | 
 | 254 |      on property:ro.boot.myfancyhardware=1 | 
 | 255 |         enable my_fancy_service_for_my_fancy_hardware | 
 | 256 |  | 
| Elliott Hughes | 91a3be5 | 2015-03-20 11:00:15 -0700 | [diff] [blame] | 257 | exec [ <seclabel> [ <user> [ <group> ]* ] ] -- <command> [ <argument> ]* | 
 | 258 |    Fork and execute command with the given arguments. The command starts | 
 | 259 |    after "--" so that an optional security context, user, and supplementary | 
 | 260 |    groups can be provided. No other commands will be run until this one | 
| Mark Salyzyn | 17fff89 | 2015-06-02 11:11:02 -0700 | [diff] [blame] | 261 |    finishes. <seclabel> can be a - to denote default. | 
| Elliott Hughes | 91a3be5 | 2015-03-20 11:00:15 -0700 | [diff] [blame] | 262 |  | 
| Elliott Hughes | 91a3be5 | 2015-03-20 11:00:15 -0700 | [diff] [blame] | 263 | export <name> <value> | 
 | 264 |    Set the environment variable <name> equal to <value> in the | 
 | 265 |    global environment (which will be inherited by all processes | 
 | 266 |    started after this command is executed) | 
 | 267 |  | 
 | 268 | hostname <name> | 
 | 269 |    Set the host name. | 
 | 270 |  | 
 | 271 | ifup <interface> | 
 | 272 |    Bring the network interface <interface> online. | 
 | 273 |  | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 274 | insmod <path> | 
 | 275 |    Install the module at <path> | 
 | 276 |  | 
| Elliott Hughes | 91a3be5 | 2015-03-20 11:00:15 -0700 | [diff] [blame] | 277 | load_all_props | 
 | 278 |    Loads properties from /system, /vendor, et cetera. | 
 | 279 |    This is included in the default init.rc. | 
 | 280 |  | 
 | 281 | load_persist_props | 
 | 282 |    Loads persistent properties when /data has been decrypted. | 
 | 283 |    This is included in the default init.rc. | 
 | 284 |  | 
| Elliott Hughes | f682b47 | 2015-02-06 12:19:48 -0800 | [diff] [blame] | 285 | loglevel <level> | 
 | 286 |    Sets the kernel log level to level. Properties are expanded within <level>. | 
 | 287 |  | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 288 | mkdir <path> [mode] [owner] [group] | 
 | 289 |    Create a directory at <path>, optionally with the given mode, owner, and | 
 | 290 |    group. If not provided, the directory is created with permissions 755 and | 
| Johan Redestig | 0b42ba2 | 2015-03-15 17:39:41 +0100 | [diff] [blame] | 291 |    owned by the root user and root group. If provided, the mode, owner and group | 
 | 292 |    will be updated if the directory exists already. | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 293 |  | 
| Hung-ying Tyan | dc738ea | 2016-01-14 11:18:21 +0800 | [diff] [blame] | 294 | mount_all <fstab> [ <path> ]* | 
 | 295 |    Calls fs_mgr_mount_all on the given fs_mgr-format fstab and imports .rc files | 
 | 296 |    at the specified paths (e.g., on the partitions just mounted). Refer to the | 
 | 297 |    section of "Init .rc Files" for detail. | 
| Elliott Hughes | 91a3be5 | 2015-03-20 11:00:15 -0700 | [diff] [blame] | 298 |  | 
| Niklas Tibbling | bc3f69f | 2012-08-01 13:15:38 +0200 | [diff] [blame] | 299 | mount <type> <device> <dir> [ <flag> ]* [<options>] | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 300 |    Attempt to mount the named device at the directory <dir> | 
 | 301 |    <device> may be of the form mtd@name to specify a mtd block | 
 | 302 |    device by name. | 
| Niklas Tibbling | bc3f69f | 2012-08-01 13:15:38 +0200 | [diff] [blame] | 303 |    <flag>s include "ro", "rw", "remount", "noatime", ... | 
 | 304 |    <options> include "barrier=1", "noauto_da_alloc", "discard", ... as | 
 | 305 |    a comma separated string, eg: barrier=1,noauto_da_alloc | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 306 |  | 
| Elliott Hughes | 91a3be5 | 2015-03-20 11:00:15 -0700 | [diff] [blame] | 307 | powerctl | 
 | 308 |    Internal implementation detail used to respond to changes to the | 
 | 309 |    "sys.powerctl" system property, used to implement rebooting. | 
 | 310 |  | 
 | 311 | restart <service> | 
 | 312 |    Like stop, but doesn't disable the service. | 
 | 313 |  | 
| Stephen Smalley | 726e8f7 | 2013-10-09 16:02:09 -0400 | [diff] [blame] | 314 | restorecon <path> [ <path> ]* | 
| Stephen Smalley | 3fb6110 | 2012-11-02 15:22:34 -0400 | [diff] [blame] | 315 |    Restore the file named by <path> to the security context specified | 
 | 316 |    in the file_contexts configuration. | 
 | 317 |    Not required for directories created by the init.rc as these are | 
 | 318 |    automatically labeled correctly by init. | 
 | 319 |  | 
| Stephen Smalley | 726e8f7 | 2013-10-09 16:02:09 -0400 | [diff] [blame] | 320 | restorecon_recursive <path> [ <path> ]* | 
 | 321 |    Recursively restore the directory tree named by <path> to the | 
 | 322 |    security contexts specified in the file_contexts configuration. | 
| Stephen Smalley | 726e8f7 | 2013-10-09 16:02:09 -0400 | [diff] [blame] | 323 |  | 
| Elliott Hughes | 91a3be5 | 2015-03-20 11:00:15 -0700 | [diff] [blame] | 324 | rm <path> | 
 | 325 |    Calls unlink(2) on the given path. You might want to | 
 | 326 |    use "exec -- rm ..." instead (provided the system partition is | 
 | 327 |    already mounted). | 
 | 328 |  | 
 | 329 | rmdir <path> | 
 | 330 |    Calls rmdir(2) on the given path. | 
 | 331 |  | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 332 | setprop <name> <value> | 
| Elliott Hughes | f682b47 | 2015-02-06 12:19:48 -0800 | [diff] [blame] | 333 |    Set system property <name> to <value>. Properties are expanded | 
 | 334 |    within <value>. | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 335 |  | 
 | 336 | setrlimit <resource> <cur> <max> | 
 | 337 |    Set the rlimit for a resource. | 
 | 338 |  | 
 | 339 | start <service> | 
 | 340 |    Start a service running if it is not already running. | 
 | 341 |  | 
 | 342 | stop <service> | 
 | 343 |    Stop a service from running if it is currently running. | 
 | 344 |  | 
| Elliott Hughes | 91a3be5 | 2015-03-20 11:00:15 -0700 | [diff] [blame] | 345 | swapon_all <fstab> | 
 | 346 |    Calls fs_mgr_swapon_all on the given fstab file. | 
 | 347 |  | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 348 | symlink <target> <path> | 
 | 349 |    Create a symbolic link at <path> with the value <target> | 
 | 350 |  | 
| The Android Open Source Project | 35237d1 | 2008-12-17 18:08:08 -0800 | [diff] [blame] | 351 | sysclktz <mins_west_of_gmt> | 
 | 352 |    Set the system clock base (0 if system clock ticks in GMT) | 
 | 353 |  | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 354 | trigger <event> | 
 | 355 |    Trigger an event.  Used to queue an action from another | 
 | 356 |    action. | 
 | 357 |  | 
| Elliott Hughes | 91a3be5 | 2015-03-20 11:00:15 -0700 | [diff] [blame] | 358 | verity_load_state | 
 | 359 |    Internal implementation detail used to load dm-verity state. | 
 | 360 |  | 
 | 361 | verity_update_state <mount_point> | 
 | 362 |    Internal implementation detail used to update dm-verity state and | 
 | 363 |    set the partition.<mount_point>.verified properties used by adb remount | 
 | 364 |    because fs_mgr can't set them directly itself. | 
 | 365 |  | 
| Patrick McCormick | 96d0a4d | 2011-02-04 10:51:39 -0800 | [diff] [blame] | 366 | wait <path> [ <timeout> ] | 
| Elliott Hughes | 91a3be5 | 2015-03-20 11:00:15 -0700 | [diff] [blame] | 367 |    Poll for the existence of the given file and return when found, | 
 | 368 |    or the timeout has been reached. If timeout is not specified it | 
 | 369 |    currently defaults to five seconds. | 
| Patrick McCormick | 96d0a4d | 2011-02-04 10:51:39 -0800 | [diff] [blame] | 370 |  | 
| Elliott Hughes | f682b47 | 2015-02-06 12:19:48 -0800 | [diff] [blame] | 371 | write <path> <content> | 
 | 372 |    Open the file at <path> and write a string to it with write(2). | 
 | 373 |    If the file does not exist, it will be created. If it does exist, | 
 | 374 |    it will be truncated. Properties are expanded within <content>. | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 375 |  | 
 | 376 |  | 
| Tom Cherry | 3be66ed | 2015-09-01 14:49:38 -0700 | [diff] [blame] | 377 | Imports | 
 | 378 | ------- | 
 | 379 | The import keyword is not a command, but rather its own section and is | 
 | 380 | handled immediately after the .rc file that contains it has finished | 
 | 381 | being parsed.  It takes the below form: | 
 | 382 |  | 
 | 383 | import <path> | 
 | 384 |    Parse an init config file, extending the current configuration. | 
 | 385 |    If <path> is a directory, each file in the directory is parsed as | 
 | 386 |    a config file. It is not recursive, nested directories will | 
 | 387 |    not be parsed. | 
 | 388 |  | 
 | 389 | There are only two times where the init executable imports .rc files, | 
 | 390 |    1) When it imports /init.rc during initial boot | 
| Hung-ying Tyan | dc738ea | 2016-01-14 11:18:21 +0800 | [diff] [blame] | 391 |    2) When it imports /{system,vendor,odm}/etc/init/ or .rc files at specified | 
 | 392 |       paths during mount_all | 
| Tom Cherry | 3be66ed | 2015-09-01 14:49:38 -0700 | [diff] [blame] | 393 |  | 
 | 394 |  | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 395 | Properties | 
 | 396 | ---------- | 
| Tom Cherry | 3be66ed | 2015-09-01 14:49:38 -0700 | [diff] [blame] | 397 | Init provides information about the services that it is responsible | 
 | 398 | for via the below properties. | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 399 |  | 
 | 400 | init.svc.<name> | 
| Tom Cherry | 3be66ed | 2015-09-01 14:49:38 -0700 | [diff] [blame] | 401 |    State of a named service ("stopped", "stopping", "running", "restarting") | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 402 |  | 
 | 403 |  | 
| Elliott Hughes | 841b263 | 2015-02-12 14:28:54 -0800 | [diff] [blame] | 404 | Bootcharting | 
 | 405 | ------------ | 
| Elliott Hughes | 841b263 | 2015-02-12 14:28:54 -0800 | [diff] [blame] | 406 | This version of init contains code to perform "bootcharting": generating log | 
 | 407 | files that can be later processed by the tools provided by www.bootchart.org. | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 408 |  | 
| Elliott Hughes | 59abac2 | 2015-03-28 12:12:51 -0700 | [diff] [blame] | 409 | On the emulator, use the -bootchart <timeout> option to boot with bootcharting | 
 | 410 | activated for <timeout> seconds. | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 411 |  | 
| Elliott Hughes | 841b263 | 2015-02-12 14:28:54 -0800 | [diff] [blame] | 412 | On a device, create /data/bootchart/start with a command like the following: | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 413 |  | 
| Elliott Hughes | 841b263 | 2015-02-12 14:28:54 -0800 | [diff] [blame] | 414 |   adb shell 'echo $TIMEOUT > /data/bootchart/start' | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 415 |  | 
| Elliott Hughes | 841b263 | 2015-02-12 14:28:54 -0800 | [diff] [blame] | 416 | Where the value of $TIMEOUT corresponds to the desired bootcharted period in | 
 | 417 | seconds. Bootcharting will stop after that many seconds have elapsed. | 
 | 418 | You can also stop the bootcharting at any moment by doing the following: | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 419 |  | 
| Elliott Hughes | 841b263 | 2015-02-12 14:28:54 -0800 | [diff] [blame] | 420 |   adb shell 'echo 1 > /data/bootchart/stop' | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 421 |  | 
| Elliott Hughes | 841b263 | 2015-02-12 14:28:54 -0800 | [diff] [blame] | 422 | Note that /data/bootchart/stop is deleted automatically by init at the end of | 
 | 423 | the bootcharting. This is not the case with /data/bootchart/start, so don't | 
 | 424 | forget to delete it when you're done collecting data. | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 425 |  | 
| Elliott Hughes | 841b263 | 2015-02-12 14:28:54 -0800 | [diff] [blame] | 426 | The log files are written to /data/bootchart/. A script is provided to | 
 | 427 | retrieve them and create a bootchart.tgz file that can be used with the | 
 | 428 | bootchart command-line utility: | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 429 |  | 
| Elliott Hughes | 841b263 | 2015-02-12 14:28:54 -0800 | [diff] [blame] | 430 |   sudo apt-get install pybootchartgui | 
| Elliott Hughes | 59abac2 | 2015-03-28 12:12:51 -0700 | [diff] [blame] | 431 |   # grab-bootchart.sh uses $ANDROID_SERIAL. | 
| Elliott Hughes | 841b263 | 2015-02-12 14:28:54 -0800 | [diff] [blame] | 432 |   $ANDROID_BUILD_TOP/system/core/init/grab-bootchart.sh | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 433 |  | 
| Elliott Hughes | 59abac2 | 2015-03-28 12:12:51 -0700 | [diff] [blame] | 434 | One thing to watch for is that the bootchart will show init as if it started | 
 | 435 | running at 0s. You'll have to look at dmesg to work out when the kernel | 
 | 436 | actually started init. | 
 | 437 |  | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 438 |  | 
| Ben Cheng | 50bbde0 | 2015-06-09 17:04:36 +0800 | [diff] [blame] | 439 | Comparing two bootcharts | 
 | 440 | ------------------------ | 
 | 441 | A handy script named compare-bootcharts.py can be used to compare the | 
 | 442 | start/end time of selected processes. The aforementioned grab-bootchart.sh | 
 | 443 | will leave a bootchart tarball named bootchart.tgz at /tmp/android-bootchart. | 
 | 444 | If two such barballs are preserved on the host machine under different | 
 | 445 | directories, the script can list the timestamps differences. For example: | 
 | 446 |  | 
 | 447 | Usage: system/core/init/compare-bootcharts.py base_bootchart_dir | 
 | 448 |        exp_bootchart_dir | 
 | 449 |  | 
 | 450 | process: baseline experiment (delta) | 
 | 451 |  - Unit is ms (a jiffy is 10 ms on the system) | 
 | 452 | ------------------------------------ | 
 | 453 | /init: 50 40 (-10) | 
 | 454 | /system/bin/surfaceflinger: 4320 4470 (+150) | 
 | 455 | /system/bin/bootanimation: 6980 6990 (+10) | 
 | 456 | zygote64: 10410 10640 (+230) | 
 | 457 | zygote: 10410 10640 (+230) | 
 | 458 | system_server: 15350 15150 (-200) | 
 | 459 | bootanimation ends at: 33790 31230 (-2560) | 
 | 460 |  | 
 | 461 |  | 
| Yasuhiro Matsuda | f93db4b | 2015-06-15 18:49:35 +0900 | [diff] [blame] | 462 | Systrace | 
 | 463 | -------- | 
 | 464 | Systrace [1] can be used for obtaining performance analysis reports during boot | 
 | 465 | time on userdebug or eng builds. | 
 | 466 | Here is an example of trace events of "wm" and "am" categories: | 
 | 467 |  | 
 | 468 |   $ANDROID_BUILD_TOP/external/chromium-trace/systrace.py wm am --boot | 
 | 469 |  | 
 | 470 | This command will cause the device to reboot. After the device is rebooted and | 
 | 471 | the boot sequence has finished, the trace report is obtained from the device | 
 | 472 | and written as trace.html on the host by hitting Ctrl+C. | 
 | 473 |  | 
 | 474 | LIMITATION | 
 | 475 | Recording trace events is started after persistent properties are loaded, so | 
 | 476 | the trace events that are emitted before that are not recorded. Several | 
 | 477 | services such as vold, surfaceflinger, and servicemanager are affected by this | 
 | 478 | limitation since they are started before persistent properties are loaded. | 
 | 479 | Zygote initialization and the processes that are forked from the zygote are not | 
 | 480 | affected. | 
 | 481 |  | 
 | 482 | [1] http://developer.android.com/tools/help/systrace.html | 
 | 483 |  | 
 | 484 |  | 
| Elliott Hughes | 841b263 | 2015-02-12 14:28:54 -0800 | [diff] [blame] | 485 | Debugging init | 
 | 486 | -------------- | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 487 | By default, programs executed by init will drop stdout and stderr into | 
 | 488 | /dev/null. To help with debugging, you can execute your program via the | 
| Elliott Hughes | f682b47 | 2015-02-06 12:19:48 -0800 | [diff] [blame] | 489 | Android program logwrapper. This will redirect stdout/stderr into the | 
| The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 490 | Android logging system (accessed via logcat). | 
 | 491 |  | 
 | 492 | For example | 
 | 493 | service akmd /system/bin/logwrapper /sbin/akmd | 
| Elliott Hughes | f682b47 | 2015-02-06 12:19:48 -0800 | [diff] [blame] | 494 |  | 
 | 495 | For quicker turnaround when working on init itself, use: | 
 | 496 |  | 
| Elliott Hughes | 841b263 | 2015-02-12 14:28:54 -0800 | [diff] [blame] | 497 |   mm -j | 
| Elliott Hughes | f682b47 | 2015-02-06 12:19:48 -0800 | [diff] [blame] | 498 |   m ramdisk-nodeps | 
 | 499 |   m bootimage-nodeps | 
 | 500 |   adb reboot bootloader | 
 | 501 |   fastboot boot $ANDROID_PRODUCT_OUT/boot.img | 
 | 502 |  | 
 | 503 | Alternatively, use the emulator: | 
 | 504 |  | 
 | 505 |   emulator -partition-size 1024 -verbose -show-kernel -no-window | 
 | 506 |  | 
 | 507 | You might want to call klog_set_level(6) after the klog_init() call | 
 | 508 | so you see the kernel logging in dmesg (or the emulator output). |