blob: 42a09cb82af9f7be59e92002c49a631ab9ec8746 [file] [log] [blame]
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -07001
2Android Init Language
3---------------------
4
5The Android Init Language consists of four broad classes of statements,
6which are Actions, Commands, Services, and Options.
7
8All of these are line-oriented, consisting of tokens separated by
9whitespace. The c-style backslash escapes may be used to insert
10whitespace into a token. Double quotes may also be used to prevent
11whitespace from breaking text into multiple tokens. The backslash,
12when it is the last character on a line, may be used for line-folding.
13
14Lines which start with a # (leading whitespace allowed) are comments.
15
16Actions and Services implicitly declare a new section. All commands
17or options belong to the section most recently declared. Commands
18or options before the first section are ignored.
19
20Actions and Services have unique names. If a second Action or Service
21is declared with the same name as an existing one, it is ignored as
22an error. (??? should we override instead)
23
24
25Actions
26-------
27Actions are named sequences of commands. Actions have a trigger which
28is used to determine when the action should occur. When an event
29occurs which matches an action's trigger, that action is added to
30the tail of a to-be-executed queue (unless it is already on the
31queue).
32
33Each action in the queue is dequeued in sequence and each command in
34that action is executed in sequence. Init handles other activities
35(device creation/destruction, property setting, process restarting)
36"between" the execution of the commands in activities.
37
38Actions take the form of:
39
40on <trigger>
41 <command>
42 <command>
43 <command>
44
45
46Services
47--------
48Services are programs which init launches and (optionally) restarts
49when they exit. Services take the form of:
50
51service <name> <pathname> [ <argument> ]*
52 <option>
53 <option>
54 ...
55
56
57Options
58-------
59Options are modifiers to services. They affect how and when init
60runs the service.
61
62critical
63 This is a device-critical service. If it exits more than four times in
64 four minutes, the device will reboot into recovery mode.
65
66disabled
67 This service will not automatically start with its class.
68 It must be explicitly started by name.
69
70setenv <name> <value>
71 Set the environment variable <name> to <value> in the launched process.
72
Stephen Smalley8348d272013-05-13 12:37:04 -040073socket <name> <type> <perm> [ <user> [ <group> [ <context> ] ] ]
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -070074 Create a unix domain socket named /dev/socket/<name> and pass
Mike Lockwood912ff852010-10-01 08:20:36 -040075 its fd to the launched process. <type> must be "dgram", "stream" or "seqpacket".
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -070076 User and group default to 0.
Stephen Smalley8348d272013-05-13 12:37:04 -040077 Context is the SELinux security context for the socket.
78 It defaults to the service security context, as specified by seclabel or
79 computed based on the service executable file security context.
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -070080
81user <username>
82 Change to username before exec'ing this service.
83 Currently defaults to root. (??? probably should default to nobody)
84 Currently, if your process requires linux capabilities then you cannot use
85 this command. You must instead request the capabilities in-process while
86 still root, and then drop to your desired uid.
87
88group <groupname> [ <groupname> ]*
89 Change to groupname before exec'ing this service. Additional
90 groupnames beyond the (required) first one are used to set the
91 supplemental groups of the process (via setgroups()).
92 Currently defaults to root. (??? probably should default to nobody)
93
Stephen Smalley3fb61102012-11-02 15:22:34 -040094seclabel <securitycontext>
95 Change to securitycontext before exec'ing this service.
96 Primarily for use by services run from the rootfs, e.g. ueventd, adbd.
97 Services on the system partition can instead use policy-defined transitions
98 based on their file security context.
99 If not specified and no transition is defined in policy, defaults to the init context.
100
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700101oneshot
102 Do not restart the service when it exits.
103
104class <name>
105 Specify a class name for the service. All services in a
106 named class may be started or stopped together. A service
107 is in the class "default" if one is not specified via the
108 class option.
109
110onrestart
111 Execute a Command (see below) when service restarts.
112
113Triggers
114--------
115 Triggers are strings which can be used to match certain kinds
116 of events and used to cause an action to occur.
117
118boot
119 This is the first trigger that will occur when init starts
120 (after /init.conf is loaded)
121
122<name>=<value>
123 Triggers of this form occur when the property <name> is set
124 to the specific value <value>.
125
126device-added-<path>
127device-removed-<path>
128 Triggers of these forms occur when a device node is added
129 or removed.
130
131service-exited-<name>
132 Triggers of this form occur when the specified service exits.
133
134
135Commands
136--------
137
138exec <path> [ <argument> ]*
139 Fork and execute a program (<path>). This will block until
140 the program completes execution. It is best to avoid exec
141 as unlike the builtin commands, it runs the risk of getting
142 init "stuck". (??? maybe there should be a timeout?)
143
144export <name> <value>
145 Set the environment variable <name> equal to <value> in the
146 global environment (which will be inherited by all processes
147 started after this command is executed)
148
149ifup <interface>
150 Bring the network interface <interface> online.
151
152import <filename>
153 Parse an init config file, extending the current configuration.
154
155hostname <name>
156 Set the host name.
157
Jay Freeman (saurik)e7cb1372008-11-17 06:41:10 +0000158chdir <directory>
159 Change working directory.
160
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700161chmod <octal-mode> <path>
162 Change file access permissions.
163
164chown <owner> <group> <path>
165 Change file owner and group.
166
Jay Freeman (saurik)e7cb1372008-11-17 06:41:10 +0000167chroot <directory>
168 Change process root directory.
169
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700170class_start <serviceclass>
171 Start all services of the specified class if they are
172 not already running.
173
174class_stop <serviceclass>
175 Stop all services of the specified class if they are
176 currently running.
177
178domainname <name>
179 Set the domain name.
180
181insmod <path>
182 Install the module at <path>
183
184mkdir <path> [mode] [owner] [group]
185 Create a directory at <path>, optionally with the given mode, owner, and
186 group. If not provided, the directory is created with permissions 755 and
187 owned by the root user and root group.
188
189mount <type> <device> <dir> [ <mountoption> ]*
190 Attempt to mount the named device at the directory <dir>
191 <device> may be of the form mtd@name to specify a mtd block
192 device by name.
193 <mountoption>s include "ro", "rw", "remount", "noatime", ...
194
Stephen Smalley726e8f72013-10-09 16:02:09 -0400195restorecon <path> [ <path> ]*
Stephen Smalley3fb61102012-11-02 15:22:34 -0400196 Restore the file named by <path> to the security context specified
197 in the file_contexts configuration.
198 Not required for directories created by the init.rc as these are
199 automatically labeled correctly by init.
200
Stephen Smalley726e8f72013-10-09 16:02:09 -0400201restorecon_recursive <path> [ <path> ]*
202 Recursively restore the directory tree named by <path> to the
203 security contexts specified in the file_contexts configuration.
204 Do NOT use this with paths leading to shell-writable or app-writable
205 directories, e.g. /data/local/tmp, /data/data or any prefix thereof.
206
Stephen Smalley3fb61102012-11-02 15:22:34 -0400207setcon <securitycontext>
208 Set the current process security context to the specified string.
209 This is typically only used from early-init to set the init context
210 before any other process is started.
211
212setenforce 0|1
213 Set the SELinux system-wide enforcing status.
214 0 is permissive (i.e. log but do not deny), 1 is enforcing.
215
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700216setkey
217 TBD
218
219setprop <name> <value>
220 Set system property <name> to <value>.
221
222setrlimit <resource> <cur> <max>
223 Set the rlimit for a resource.
224
Stephen Smalley0e23fee2012-11-28 13:52:12 -0500225setsebool <name> <value>
Stephen Smalley3fb61102012-11-02 15:22:34 -0400226 Set SELinux boolean <name> to <value>.
227 <value> may be 1|true|on or 0|false|off
228
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700229start <service>
230 Start a service running if it is not already running.
231
232stop <service>
233 Stop a service from running if it is currently running.
234
235symlink <target> <path>
236 Create a symbolic link at <path> with the value <target>
237
The Android Open Source Project35237d12008-12-17 18:08:08 -0800238sysclktz <mins_west_of_gmt>
239 Set the system clock base (0 if system clock ticks in GMT)
240
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700241trigger <event>
242 Trigger an event. Used to queue an action from another
243 action.
244
Patrick McCormick96d0a4d2011-02-04 10:51:39 -0800245wait <path> [ <timeout> ]
246 Poll for the existence of the given file and return when found,
247 or the timeout has been reached. If timeout is not specified it
248 currently defaults to five seconds.
249
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700250write <path> <string> [ <string> ]*
251 Open the file at <path> and write one or more strings
252 to it with write(2)
253
254
255Properties
256----------
257Init updates some system properties to provide some insight into
258what it's doing:
259
260init.action
261 Equal to the name of the action currently being executed or "" if none
262
263init.command
264 Equal to the command being executed or "" if none.
265
266init.svc.<name>
267 State of a named service ("stopped", "running", "restarting")
268
269
270Example init.conf
271-----------------
272
273# not complete -- just providing some examples of usage
274#
275on boot
276 export PATH /sbin:/system/sbin:/system/bin
277 export LD_LIBRARY_PATH /system/lib
278
279 mkdir /dev
280 mkdir /proc
281 mkdir /sys
282
283 mount tmpfs tmpfs /dev
284 mkdir /dev/pts
285 mkdir /dev/socket
286 mount devpts devpts /dev/pts
287 mount proc proc /proc
288 mount sysfs sysfs /sys
289
290 write /proc/cpu/alignment 4
291
292 ifup lo
293
294 hostname localhost
295 domainname localhost
296
297 mount yaffs2 mtd@system /system
298 mount yaffs2 mtd@userdata /data
299
300 import /system/etc/init.conf
301
302 class_start default
303
304service adbd /sbin/adbd
305 user adb
306 group adb
307
308service usbd /system/bin/usbd -r
309 user usbd
310 group usbd
311 socket usbd 666
312
313service zygote /system/bin/app_process -Xzygote /system/bin --zygote
314 socket zygote 666
315
316service runtime /system/bin/runtime
317 user system
318 group system
319
320on device-added-/dev/compass
321 start akmd
322
323on device-removed-/dev/compass
324 stop akmd
325
326service akmd /sbin/akmd
327 disabled
328 user akmd
329 group akmd
330
331Debugging notes
332---------------
333By default, programs executed by init will drop stdout and stderr into
334/dev/null. To help with debugging, you can execute your program via the
335Andoird program logwrapper. This will redirect stdout/stderr into the
336Android logging system (accessed via logcat).
337
338For example
339service akmd /system/bin/logwrapper /sbin/akmd