aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kernel/doc/src/application.xml
blob: 38c7b5acf156ea1bd4ab945f8ae5faeed686bfaf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE erlref SYSTEM "erlref.dtd">

<erlref>
  <header>
    <copyright>
      <year>1996</year><year>2018</year>
      <holder>Ericsson AB. All Rights Reserved.</holder>
    </copyright>
    <legalnotice>
      Licensed under the Apache License, Version 2.0 (the "License");
      you may not use this file except in compliance with the License.
      You may obtain a copy of the License at
 
          http://www.apache.org/licenses/LICENSE-2.0

      Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      See the License for the specific language governing permissions and
      limitations under the License.

    </legalnotice>

    <title>application</title>
    <prepared></prepared>
    <docno></docno>
    <date></date>
    <rev></rev>
  </header>
  <module>application</module>
  <modulesummary>Generic OTP application functions</modulesummary>
  <description>
    <p>In OTP, <em>application</em> denotes a component implementing
      some specific functionality, that can be started and stopped as a
      unit, and that can be reused in other systems. This
      module interacts with <em>application controller</em>, a process
      started at every Erlang runtime system. This module contains functions
      for controlling applications (for example, starting and stopping
      applications), and functions to access information about
      applications (for example, configuration parameters).</p>
    <p>An application is defined by an <em>application specification</em>.
      The specification is normally located in an
      <em>application resource file</em> named <c>Application.app</c>,
      where <c>Application</c> is the application name. For details
      about the application specification, see
    <seealso marker="app"><c>app(4)</c></seealso>.</p>
    <p>This module can also be viewed as a behaviour for an application
      implemented according to the OTP design principles as a
      supervision tree. The definition of how to start and stop
      the tree is to be located in an <em>application callback module</em>,
      exporting a predefined set of functions.</p>
    <p>For details about applications and behaviours, see
    <seealso marker="doc/design_principles:des_princ">OTP Design Principles</seealso>.</p>
  </description>
  <datatypes>
    <datatype>
      <name name="start_type"/>
    </datatype>
    <datatype>
      <name name="restart_type"/>
    </datatype>
    <datatype>
      <name>tuple_of(T)</name>
      <desc><p>A tuple where the elements are of type <c>T</c>.</p></desc>
    </datatype>
  </datatypes>
  <funcs>
    <func>
        <name name="ensure_all_started" arity="1"/>
        <name name="ensure_all_started" arity="2"/>
        <fsummary>Load and start an application and its dependencies, recursively.</fsummary>
        <desc>
          <p>Equivalent to calling
	  <seealso marker="#start/1"><c>start/1,2</c></seealso>
          repeatedly on all dependencies that are not yet started for an application.</p>
          <p>Returns <c>{ok, AppNames}</c> for a successful start or for an already started
          application (which is, however, omitted from the <c>AppNames</c> list).</p>
	  <p>The function reports <c>{error, {AppName,Reason}}</c> for errors, where
	  <c>Reason</c> is any possible reason returned by
	  <seealso marker="#start/1"><c>start/1,2</c></seealso>
	  when starting a specific dependency.</p>
	  <p>If an error occurs, the applications started by the function are stopped
	  to bring the set of running applications back to its initial state.</p>
        </desc>
    </func>
    <func>
      <name name="ensure_started" arity="1"/>
      <name name="ensure_started" arity="2"/>
      <fsummary>Load and start an application.</fsummary>
      <desc>
	<p>Equivalent to
	<seealso marker="#start/1"><c>start/1,2</c></seealso>
	except it returns <c>ok</c> for already started applications.</p>
      </desc>
    </func>
    <func>
      <name name="get_all_env" arity="0"/>
      <name name="get_all_env" arity="1"/>
      <fsummary>Get the configuration parameters for an application.</fsummary>
      <desc>
        <p>Returns the configuration parameters and their values for
          <c><anno>Application</anno></c>. If the argument is omitted, it defaults to
          the application of the calling process.</p>
        <p>If the specified application is not loaded, or if the process
          executing the call does not belong to any application,
          the function returns <c>[]</c>.</p>
      </desc>
    </func>
    <func>
      <name name="get_all_key" arity="0"/>
      <name name="get_all_key" arity="1"/>
      <fsummary>Get the application specification keys.</fsummary>
      <desc>
        <p>Returns the application specification keys and their values
          for <c><anno>Application</anno></c>. If the argument is omitted, it
          defaults to the application of the calling process.</p>
        <p>If the specified application is not loaded, the function
          returns <c>undefined</c>. If the process executing the call
          does not belong to any application, the function returns
          <c>[]</c>.</p>
      </desc>
    </func>
    <func>
      <name name="get_application" arity="0"/>
      <name name="get_application" arity="1"/>
      <fsummary>Get the name of an application containing a certain process or module.</fsummary>
      <desc>
        <p>Returns the name of the application to which the process
          <c><anno>Pid</anno></c> or the module <c><anno>Module</anno></c> belongs. Providing no
          argument is the same as calling
          <c>get_application(self())</c>.</p>
        <p>If the specified process does not belong to any application,
          or if the specified process or module does not exist,
          the function returns <c>undefined</c>.</p>
      </desc>
    </func>
    <func>
      <name name="get_env" arity="1"/>
      <name name="get_env" arity="2"/>
      <fsummary>Get the value of a configuration parameter.</fsummary>
      <desc>
        <p>Returns the value of configuration parameter <c><anno>Par</anno></c>
          for <c><anno>Application</anno></c>. If the application argument is
          omitted, it defaults to the application of the calling
          process.</p>
	  <p>Returns <c>undefined</c> if any of the following applies:</p>
	  <list type="bulleted">
	    <item>The specified application is not loaded.</item>
	    <item>The configuration parameter does not exist.</item>
	    <item>The process executing the call does not belong to any application.</item>
	  </list>
      </desc>
    </func>
    <func>
      <name name="get_env" arity="3"/>
      <fsummary>Get the value of a configuration parameter using a default.</fsummary>
      <desc>
        <p>Works like <seealso marker="#get_env/2"><c>get_env/2</c></seealso> but returns
          value <c><anno>Def</anno></c> when configuration parameter
          <c><anno>Par</anno></c> does not exist.</p>
      </desc>
    </func>
    <func>
      <name name="get_key" arity="1"/>
      <name name="get_key" arity="2"/>
      <fsummary>Get the value of an application specification key.</fsummary>
      <desc>
        <p>Returns the value of the application specification key
          <c><anno>Key</anno></c> for <c><anno>Application</anno></c>. If the application
          argument is omitted, it defaults to the application of
          the calling process.</p>
	  <p>Returns <c>undefined</c> if any of the following applies:</p>
	  <list type="bulleted">
	    <item>The specified application is not loaded.</item>
	    <item>The specification key does not exist.</item>
	    <item>The process executing the call does not belong to any application.</item>
	  </list>

      </desc>
    </func>
    <func>
      <name name="load" arity="1"/>
      <name name="load" arity="2"/>
      <fsummary>Load an application.</fsummary>
      <type name="application_spec"/>
      <type name="application_opt"/>
      <desc>
        <p>Loads the application specification for an application into
          the application controller. It also loads the application
          specifications for any included applications. Notice that
          the function does not load the Erlang object code.</p>
        <p>The application can be specified by its name <c><anno>Application</anno></c>.
          In this case, the application controller searches the code
          path for the application resource file <c><anno>Application</anno>.app</c>
          and loads the specification it contains.</p>
        <p>The application specification can also be specified directly as a
          tuple <c><anno>AppSpec</anno></c>, having the format and
          contents as described in
	<seealso marker="app"><c>app(4)</c></seealso>.</p>
        <p>If <c><anno>Distributed</anno> == {<anno>Application</anno>,[<anno>Time</anno>,]<anno>Nodes</anno>}</c>,
          the application becomes distributed. The argument overrides
          the value for the application in the Kernel configuration
          parameter <c>distributed</c>. <c><anno>Application</anno></c> must be
          the application name (same as in the first argument).
          If a node crashes and <c><anno>Time</anno></c> is specified,
          the application controller waits for <c><anno>Time</anno></c>
          milliseconds before attempting to restart the application on
          another node. If <c><anno>Time</anno></c> is not specified, it
          defaults to <c>0</c> and the application is restarted
          immediately.</p>
        <p><c><anno>Nodes</anno></c> is a list of node names where the application
          can run, in priority from left to right. Node names can be
          grouped using tuples to indicate that they have the same
          priority.</p>
	  <p><em>Example:</em></p>
        <code type="none">
Nodes = [cp1@cave, {cp2@cave, cp3@cave}]</code>
        <p>This means that the application is preferably to be started
          at <c>cp1@cave</c>. If <c>cp1@cave</c> is down,
          the application is to be started at <c>cp2@cave</c>
          or <c>cp3@cave</c>.</p>
        <p>If <c>Distributed == default</c>, the value for
          the application in the Kernel configuration parameter
          <c>distributed</c> is used.</p>
      </desc>
    </func>
    <func>
      <name name="loaded_applications" arity="0"/>
      <fsummary>Get the currently loaded applications.</fsummary>
      <desc>
        <p>Returns a list with information about the applications, and included
	  applications, which are loaded using <c>load/1,2</c>.
          <c><anno>Application</anno></c> is the application name.
          <c><anno>Description</anno></c> and <c><anno>Vsn</anno></c> are the values
	  of their <c>description</c> and <c>vsn</c> application specification
          keys, respectively.</p>
      </desc>
    </func>
    <func>
      <name name="permit" arity="2"/>
      <fsummary>Change the permission for an application to run at a node.</fsummary>
      <desc>
        <p>Changes the permission for <c><anno>Application</anno></c> to run at
          the current node. The application must be loaded using
          <c>load/1,2</c> for the function to have effect.</p>
        <p>If the permission of a loaded, but not started, application
          is set to <c>false</c>, <c>start</c> returns <c>ok</c> but
          the application is not started until the permission is
          set to <c>true</c>.</p>
        <p>If the permission of a running application is set to
          <c>false</c>, the application is stopped. If
          the permission later is set to <c>true</c>, it is
          restarted.</p>
        <p>If the application is distributed, setting the permission to
          <c>false</c> means that the application will be started at, or
          moved to, another node according to how its distribution is
          configured
	(see <seealso marker="#load/2"><c>load/2</c></seealso>).</p>
        <p>The function does not return until the application is
          started, stopped, or successfully moved to another node.
          However, in some cases where permission is set to <c>true</c>,
          the function returns <c>ok</c> even though the application
          is not started. This is true when an application
          cannot start because of dependencies to other
          applications that are not yet started. When they are
          started, <c>Application</c> is started as well.</p>
        <p>By default, all applications are loaded with permission
          <c>true</c> on all nodes. The permission can be configured
          using the Kernel configuration parameter <c>permissions</c>.</p>
      </desc>
    </func>
    <func>
      <name name="set_env" arity="3"/>
      <name name="set_env" arity="4"/>
      <fsummary>Set the value of a configuration parameter.</fsummary>
      <desc>
        <p>Sets the value of configuration parameter <c><anno>Par</anno></c> for
          <c><anno>Application</anno></c>.</p>
        <p><c>set_env/4</c> uses the standard <c>gen_server</c> time-out
          value (5000 ms). Option <c>timeout</c> can be specified
          if another time-out value is useful, for example, in situations
          where the application controller is heavily loaded.</p>
        <p>If <c>set_env/4</c> is called before the application is loaded,
          the application environment values specified in file <c>Application.app</c>
          override the ones previously set. This is also true for application
          reloads.</p>
        <p>Option <c>persistent</c> can be set to <c>true</c>
          to guarantee that parameters set with <c>set_env/4</c>
          are not overridden by those defined in the application resource
          file on load. This means that persistent values will stick after the application
          is loaded and also on application reload.</p>
        <warning>
          <p>Use this function only if you know what you are doing,
            that is, on your own applications. It is very
	    application-dependent and
	    configuration parameter-dependent when and how often
            the value is read by the application. Careless use
            of this function can put the application in a
            weird, inconsistent, and malfunctioning state.</p>
        </warning>
      </desc>
    </func>
    <func>
      <name name="start" arity="1"/>
      <name name="start" arity="2"/>
      <fsummary>Load and start an application.</fsummary>
       <desc>
        <p>Starts <c><anno>Application</anno></c>. If it is not loaded,
          the application controller first loads it using
          <c>load/1</c>. It ensures that any included applications
          are loaded, but does not start them. That is assumed to be
          taken care of in the code for <c><anno>Application</anno></c>.</p>
        <p>The application controller checks the value of
          the application specification key <c>applications</c>, to
          ensure that all applications needed to be started before
          this application are running. Otherwise,
          <c>{error,{not_started,App}}</c> is returned, where <c>App</c>
          is the name of the missing application.</p>
        <p>The application controller then creates an <em>application master</em>
          for the application. The application master becomes the
          group leader of all the processes in the application. I/O is
          forwarded to the previous group leader, though, this is just
          a way to identify processes that belong to the application.
          Used for example to find itself from any process, or,
          reciprocally, to kill them all when it terminates.</p>
        <p>
          The application master starts the application by calling
          the application callback function <c>Module:start/2</c> as
          defined by the application specification key <c>mod</c>.</p>
        <p>Argument <c><anno>Type</anno></c> specifies the type of
          the application. If omitted, it defaults to <c>temporary</c>.</p>
        <list type="bulleted">
          <item>If a permanent application terminates, all other
           applications and the entire Erlang node are also terminated.</item>
          <item>
	    <list type="bulleted">
	      <item>If a transient application terminates with <c>Reason == normal</c>,
	      this is reported but no other applications are terminated.</item>
	      <item>If a transient application terminates abnormally, all other
	      applications and the entire Erlang node are also terminated.</item>
	    </list>
	   </item>
          <item>If a temporary application terminates, this is reported
           but no other applications are terminated.</item>
        </list>
        <p>Notice that an application can always be stopped
          explicitly by calling <c>stop/1</c>. Regardless of the type of
          the application, no other applications are affected.</p>
        <p>Notice also that the transient type is of little practical use,
          because when a supervision tree terminates, the reason is set to
          <c>shutdown</c>, not <c>normal</c>.</p>
      </desc>
    </func>
    <func>
      <name name="start_type" arity="0"/>
      <fsummary>Get the start type of an ongoing application startup.</fsummary>
      <desc>
        <p>This function is intended to be called by a process belonging
          to an application, when the application is started, to
          determine the start type, which is <c><anno>StartType</anno></c> or
          <c>local</c>.</p>
        <p>For a description of <c><anno>StartType</anno></c>, see
	  <seealso marker="#start_type"><c>Module:start/2</c></seealso>.</p>
        <p><c>local</c> is returned if only parts of the application are
          restarted (by a supervisor), or if the function is
          called outside a startup.</p>
        <p>If the process executing the call does not belong to any
          application, the function returns <c>undefined</c>.</p>
      </desc>
    </func>
    <func>
      <name name="stop" arity="1"/>
      <fsummary>Stop an application.</fsummary>
      <desc>
        <p>Stops <c><anno>Application</anno></c>. The application master calls
          <c>Module:prep_stop/1</c>, if such a function is defined, and
          then tells the top supervisor of the application to shut down
          (see <seealso marker="stdlib:supervisor"><c>supervisor(3)</c></seealso>).
	  This means that the entire
          supervision tree, including included applications, is
          terminated in reversed start order. After the shutdown,
          the application master calls <c>Module:stop/1</c>.
          <c>Module</c> is the callback module as defined by
          the application specification key <c>mod</c>.</p>
        <p>Last, the application master terminates. Notice that all
          processes with the application master as group leader, that is,
          processes spawned from a process belonging to the application,
          are also terminated.</p>
        <p>When stopped, the application is still loaded.</p>
        <p>To stop a distributed application, <c>stop/1</c>
          must be called on all nodes where it can execute (that is,
          on all nodes where it has been started). The call to
          <c>stop/1</c> on the node where the application currently
          executes stops its execution. The application is not
          moved between nodes, as <c>stop/1</c> is called on
          the node where the application currently executes before
          <c>stop/1</c> is called on the other nodes.</p>
      </desc>
    </func>
    <func>
      <name name="takeover" arity="2"/>
      <fsummary>Take over a distributed application.</fsummary>
      <desc>
        <p>Takes over the distributed application
          <c><anno>Application</anno></c>, which executes at another node
          <c>Node</c>. At the current node, the application is
          restarted by calling
          <c>Module:start({takeover,Node},StartArgs)</c>. <c>Module</c>
          and <c>StartArgs</c> are retrieved from the loaded application
          specification. The application at the other node is not
          stopped until the startup is completed, that is, when
          <c>Module:start/2</c> and any calls to
          <c>Module:start_phase/3</c> have returned.</p>
        <p>Thus, two instances of the application run simultaneously
          during the takeover, so that data can be transferred
          from the old to the new instance. If this is not an acceptable
          behavior, parts of the old instance can be shut down when
          the new instance is started. However, the application cannot
          be stopped entirely, at least the top supervisor
          must remain alive.</p>
        <p>For a description of <c>Type</c>, see
	<seealso marker="#start/1"><c>start/1,2</c></seealso>.</p>
      </desc>
    </func>
    <func>
      <name name="unload" arity="1"/>
      <fsummary>Unload an application.</fsummary>
      <desc>
        <p>Unloads the application specification for <c><anno>Application</anno></c>
          from the application controller. It also unloads
          the application specifications for any included applications.
          Notice that the function does not purge the Erlang
          object code.</p>
      </desc>
    </func>
    <func>
      <name name="unset_env" arity="2"/>
      <name name="unset_env" arity="3"/>
      <fsummary>Unset the value of a configuration parameter.</fsummary>
      <desc>
        <p>Removes the configuration parameter <c><anno>Par</anno></c> and its value
          for <c><anno>Application</anno></c>.</p>
        <p><c>unset_env/2</c> uses the standard <c>gen_server</c>
          time-out value (5000 ms). Option <c>timeout</c> can be
          specified if another time-out value is useful, for example, in
          situations where the application controller is heavily loaded.</p>
        <p><c>unset_env/3</c> also allows the persistent option to be passed
          (see <seealso marker="#set_env/4"><c>set_env/4</c></seealso>).</p>
	<warning>
          <p>Use this function only if you know what you are doing,
            that is, on your own applications. It is very
	    application-dependent and configuration
	    parameter-dependent when and how often
            the value is read by the application. Careless use
            of this function can put the application in a
            weird, inconsistent, and malfunctioning state.</p>
        </warning>
      </desc>
    </func>
    <func>
      <name name="which_applications" arity="0"/>
      <name name="which_applications" arity="1"/>
      <fsummary>Get the currently running applications.</fsummary>
      <desc>
        <p>Returns a list with information about the applications that
          are currently running. <c><anno>Application</anno></c> is the application
          name. <c><anno>Description</anno></c> and <c><anno>Vsn</anno></c> are the
	  values of their <c>description</c> and <c>vsn</c> application specification
          keys, respectively.</p>
        <p><c>which_applications/0</c> uses the standard
          <c>gen_server</c> time-out value (5000 ms). A <c><anno>Timeout</anno></c>
          argument can be specified if another time-out value is useful,
          for example, in situations where the application controller
          is heavily loaded.</p>
      </desc>
    </func>
  </funcs>

  <section>
    <title>Callback Module</title>
    <p>The following functions are to be exported from an
      <c>application</c> callback module.</p>
  </section>
  <funcs>
    <func>
      <name>Module:start(StartType, StartArgs) -> {ok, Pid} | {ok, Pid, State} | {error, Reason}</name>
      <fsummary>Start an application.</fsummary>
      <type>
        <v>StartType = <seealso marker="#type-start_type"><c>start_type()</c></seealso></v>
        <v>StartArgs = term()</v>
        <v>Pid = pid()</v>
        <v>State = term()</v>
      </type>
      <desc>
        <p>This function is called whenever an application is started
          using <c>start/1,2</c>, and is to start
          the processes of the application. If the application is
          structured according to the OTP design principles as a
          supervision tree, this means starting the top supervisor of
          the tree.</p>
        <p><marker id="start_type"/><c>StartType</c> defines the type of start:</p>
        <list type="bulleted">
          <item><c>normal</c> if it is a normal startup.</item>
          <item><c>normal</c> also if the application is distributed and
           started at the current node because of a failover from another
           node, and the application specification key <c>start_phases == undefined</c>.</item>
          <item><c>{takeover,Node}</c> if the application is
           distributed and started at the current node because of a
           takeover from <c>Node</c>, either because
          <c>takeover/2</c> has been called or because
           the current node has higher priority than <c>Node</c>.</item>
          <item><c>{failover,Node}</c> if the application is
           distributed and started at the current node because of a
           failover from <c>Node</c>, and the application
           specification key <c>start_phases /= undefined</c>.</item>
        </list>
        <p><c>StartArgs</c> is the <c>StartArgs</c> argument defined by
          the application specification key <c>mod</c>.</p>
        <p>The function is to return <c>{ok,Pid}</c> or
          <c>{ok,Pid,State}</c>, where <c>Pid</c> is the pid of the top
          supervisor and <c>State</c> is any term. If omitted,
          <c>State</c> defaults to <c>[]</c>. If the application
          is stopped later, <c>State</c> is passed to
          <c>Module:prep_stop/1</c>.</p>
      </desc>
    </func>
    <func>
      <name>Module:start_phase(Phase, StartType, PhaseArgs) -> ok | {error, Reason}</name>
      <fsummary>Extended start of an application.</fsummary>
      <type>
        <v>Phase = atom()</v>
        <v>StartType = <seealso marker="#type-start_type"><c>start_type()</c></seealso></v>
        <v>PhaseArgs = term()</v>
        <v>Pid = pid()</v>
        <v>State = state()</v>
      </type>
      <desc>
        <p>Starts an application with included
          applications, when synchronization is needed between
          processes in the different applications during startup.</p>
        <p>The start phases are defined by the application specification
          key <c>start_phases == [{Phase,PhaseArgs}]</c>. For included
          applications, the set of phases must be a subset of the set of
          phases defined for the including application.</p>
        <p>The function is called for each start phase (as defined for
          the primary application) for the primary application and all
          included applications, for which the start phase is defined.</p>
        <p>For a description of <c>StartType</c>, see
	<seealso marker="Module:start/2"><c>Module:start/2</c></seealso>.</p>
      </desc>
    </func>
    <func>
      <name>Module:prep_stop(State) -> NewState</name>
      <fsummary>Prepare an application for termination.</fsummary>
      <type>
        <v>State = NewState = term()</v>
      </type>
      <desc>
        <p>This function is called when an application is about to be
          stopped, before shutting down the processes of
          the application.</p>
        <p><c>State</c> is the state returned from
          <c>Module:start/2</c>, or <c>[]</c> if no state was returned.
          <c>NewState</c> is any term and is passed to
          <c>Module:stop/1</c>.</p>
        <p>The function is optional. If it is not defined, the processes
          are terminated and then <c>Module:stop(State)</c> is called.</p>
      </desc>
    </func>
    <func>
      <name>Module:stop(State)</name>
      <fsummary>Clean up after termination of an application.</fsummary>
      <type>
        <v>State = term()</v>
      </type>
      <desc>
        <p>This function is called whenever an application has stopped.
          It is intended to be the opposite of <c>Module:start/2</c>
          and is to do any necessary cleaning up. The return value is
          ignored.</p>
        <p><c>State</c> is the return value of <c>Module:prep_stop/1</c>,
	  if such a function exists. Otherwise <c>State</c> is taken from
	  the return value of <c>Module:start/2</c>.</p>
      </desc>
    </func>
    <func>
      <name>Module:config_change(Changed, New, Removed) -> ok</name>
      <fsummary>Update the configuration parameters for an application.</fsummary>
      <type>
        <v>Changed = [{Par,Val}]</v>
        <v>New = [{Par,Val}]</v>
        <v>Removed = [Par]</v>
        <v>&nbsp;Par = atom()</v>
        <v>&nbsp;Val = term()</v>
      </type>
      <desc>
        <p>This function is called by an application after a code
          replacement, if the configuration parameters have changed.</p>
        <p><c>Changed</c> is a list of parameter-value tuples including all
          configuration parameters with changed values.</p>
	<p><c>New</c> is a list of parameter-value tuples including all
	  added configuration parameters.</p>
	<p><c>Removed</c> is a list of all removed parameters.</p>
      </desc>
    </func>
  </funcs>

  <section>
    <title>See Also</title>
    <p><seealso marker="doc/design_principles:des_princ">OTP Design Principles</seealso>,
      <seealso marker="kernel_app">kernel(6)</seealso>,
      <seealso marker="app">app(4)</seealso></p>
  </section>
</erlref>