Performing an orderly shutdown with OTP

Ulf Wiger <>
Wed Jan 14 09:55:49 CET 2004


On Tue, 13 Jan 2004 21:15:02 -0500, Vance Shipley <> 
wrote:

>
> How do you folks build systems which perform orderly shutdowns?

1) call init:stop().
2) if a restart escalates all the way past the top supervisor
    of an application, the application controller will initiate
    an orderly shutdown.

>
> How should we shut the system down manually?  q() seems rather
> brutal.
>
> If the system will be stopped in what order are children
> killed off?

The supervisor behaviour terminates its children in the
reverse of the order in which they were started.

> I would like to see a (relatively) orderly shutdown  occur
> even when an exceptional event occurs like for instance a
> permanent application exiting.

This is what should happen if the application has been started
using application:start(App, permanent) or if it has been
started from the boot script.

> How would you use the kernel configuration parameter
> shutdown_func?

I've never used it. I'll let someone else answer that one.

> How would you use the application behaviour callbacks
> prep_stop/1 and stop/1?

The start/2 callback allows the user to return a state,
which is then passed on to the stop/1 callback once the
processes of the application have been terminated.
The prep_stop/1 callback is called _before_ the processes
start terminating.

In AXD301, we use them for the following:

- prep_stop/1 is used in some occasions to close incoming
   signaling ports before the processes start dying. This is
   to reduce the noise when killing processes and removing
   ets tables.

- stop/1 is used e.g. to garbage-collect an ets table where
   we hold the supervisor specifications. This ets table is
   used to make it possible to add included applications
   to an existing application structure without having to
   restart the whole application.

We use a central application behaviour module, and allow the
applications to parameterize it through environment variables.

/Uffe
-- 
Ulf Wiger, Senior System Architect
EAB/UPD/S



More information about the erlang-questions mailing list