blob: 360a1b709997df3564f7108edc6e999c48c483e1 [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
73socket <name> <type> <perm> [ <user> [ <group> ] ]
74 Create a unix domain socket named /dev/socket/<name> and pass
75 its fd to the launched process. <type> must be "dgram" or "stream".
76 User and group default to 0.
77
78user <username>
79 Change to username before exec'ing this service.
80 Currently defaults to root. (??? probably should default to nobody)
81 Currently, if your process requires linux capabilities then you cannot use
82 this command. You must instead request the capabilities in-process while
83 still root, and then drop to your desired uid.
84
85group <groupname> [ <groupname> ]*
86 Change to groupname before exec'ing this service. Additional
87 groupnames beyond the (required) first one are used to set the
88 supplemental groups of the process (via setgroups()).
89 Currently defaults to root. (??? probably should default to nobody)
90
91oneshot
92 Do not restart the service when it exits.
93
94class <name>
95 Specify a class name for the service. All services in a
96 named class may be started or stopped together. A service
97 is in the class "default" if one is not specified via the
98 class option.
99
100onrestart
101 Execute a Command (see below) when service restarts.
102
103Triggers
104--------
105 Triggers are strings which can be used to match certain kinds
106 of events and used to cause an action to occur.
107
108boot
109 This is the first trigger that will occur when init starts
110 (after /init.conf is loaded)
111
112<name>=<value>
113 Triggers of this form occur when the property <name> is set
114 to the specific value <value>.
115
116device-added-<path>
117device-removed-<path>
118 Triggers of these forms occur when a device node is added
119 or removed.
120
121service-exited-<name>
122 Triggers of this form occur when the specified service exits.
123
124
125Commands
126--------
127
128exec <path> [ <argument> ]*
129 Fork and execute a program (<path>). This will block until
130 the program completes execution. It is best to avoid exec
131 as unlike the builtin commands, it runs the risk of getting
132 init "stuck". (??? maybe there should be a timeout?)
133
134export <name> <value>
135 Set the environment variable <name> equal to <value> in the
136 global environment (which will be inherited by all processes
137 started after this command is executed)
138
139ifup <interface>
140 Bring the network interface <interface> online.
141
142import <filename>
143 Parse an init config file, extending the current configuration.
144
145hostname <name>
146 Set the host name.
147
148chmod <octal-mode> <path>
149 Change file access permissions.
150
151chown <owner> <group> <path>
152 Change file owner and group.
153
154class_start <serviceclass>
155 Start all services of the specified class if they are
156 not already running.
157
158class_stop <serviceclass>
159 Stop all services of the specified class if they are
160 currently running.
161
162domainname <name>
163 Set the domain name.
164
165insmod <path>
166 Install the module at <path>
167
168mkdir <path> [mode] [owner] [group]
169 Create a directory at <path>, optionally with the given mode, owner, and
170 group. If not provided, the directory is created with permissions 755 and
171 owned by the root user and root group.
172
173mount <type> <device> <dir> [ <mountoption> ]*
174 Attempt to mount the named device at the directory <dir>
175 <device> may be of the form mtd@name to specify a mtd block
176 device by name.
177 <mountoption>s include "ro", "rw", "remount", "noatime", ...
178
179setkey
180 TBD
181
182setprop <name> <value>
183 Set system property <name> to <value>.
184
185setrlimit <resource> <cur> <max>
186 Set the rlimit for a resource.
187
188start <service>
189 Start a service running if it is not already running.
190
191stop <service>
192 Stop a service from running if it is currently running.
193
194symlink <target> <path>
195 Create a symbolic link at <path> with the value <target>
196
197trigger <event>
198 Trigger an event. Used to queue an action from another
199 action.
200
201write <path> <string> [ <string> ]*
202 Open the file at <path> and write one or more strings
203 to it with write(2)
204
205
206Properties
207----------
208Init updates some system properties to provide some insight into
209what it's doing:
210
211init.action
212 Equal to the name of the action currently being executed or "" if none
213
214init.command
215 Equal to the command being executed or "" if none.
216
217init.svc.<name>
218 State of a named service ("stopped", "running", "restarting")
219
220
221Example init.conf
222-----------------
223
224# not complete -- just providing some examples of usage
225#
226on boot
227 export PATH /sbin:/system/sbin:/system/bin
228 export LD_LIBRARY_PATH /system/lib
229
230 mkdir /dev
231 mkdir /proc
232 mkdir /sys
233
234 mount tmpfs tmpfs /dev
235 mkdir /dev/pts
236 mkdir /dev/socket
237 mount devpts devpts /dev/pts
238 mount proc proc /proc
239 mount sysfs sysfs /sys
240
241 write /proc/cpu/alignment 4
242
243 ifup lo
244
245 hostname localhost
246 domainname localhost
247
248 mount yaffs2 mtd@system /system
249 mount yaffs2 mtd@userdata /data
250
251 import /system/etc/init.conf
252
253 class_start default
254
255service adbd /sbin/adbd
256 user adb
257 group adb
258
259service usbd /system/bin/usbd -r
260 user usbd
261 group usbd
262 socket usbd 666
263
264service zygote /system/bin/app_process -Xzygote /system/bin --zygote
265 socket zygote 666
266
267service runtime /system/bin/runtime
268 user system
269 group system
270
271on device-added-/dev/compass
272 start akmd
273
274on device-removed-/dev/compass
275 stop akmd
276
277service akmd /sbin/akmd
278 disabled
279 user akmd
280 group akmd
281
282Debugging notes
283---------------
284By default, programs executed by init will drop stdout and stderr into
285/dev/null. To help with debugging, you can execute your program via the
286Andoird program logwrapper. This will redirect stdout/stderr into the
287Android logging system (accessed via logcat).
288
289For example
290service akmd /system/bin/logwrapper /sbin/akmd