The init module is pre-loaded and contains the code for the init system process which coordinates the start-up of the system. The first function evaluated at start-up is boot(BootArgs), where BootArgs is a list of command line arguments supplied to the Erlang runtime system from the local operating system. See erl(1).
init reads the boot script which contains instructions on how to initiate the system. See script(4) for more information about boot scripts.
init also contains functions to restart, reboot, and stop the system.
Types:
BootArgs = [binary()]
Starts the Erlang runtime system. This function is called when the emulator is started and coordinates system start-up.
BootArgs are all command line arguments except the emulator flags, that is, flags and plain arguments. See erl(1).
init itself interprets some of the flags, see Command Line Flags below. The remaining flags ("user flags") and plain arguments are passed to the init loop and can be retrieved by calling get_arguments/0 and get_plain_arguments/0, respectively.
Types:
Arg = atom()
Returns any plain command line arguments as a list of atoms (possibly empty). It is recommended that get_plain_arguments/1 is used instead, because of the limited length of atoms.
get_argument(Flag) -> {ok, Arg} | error
Types:
Flag = atom()
Arg = [Values]
Values = [string()]
Returns all values associated with the command line user flag Flag. If Flag is provided several times, each Values is returned in preserved order.
% erl -a b c -a d ... 1> init:get_argument(a). {ok,[["b","c"],["d"]]}
There are also a number of flags, which are defined automatically and can be retrieved using this function:
2> init:get_argument(root). {ok,[["/usr/local/otp/releases/otp_beam_solaris8_r10b_patched"]]}
3> init:get_argument(progname). {ok,[["erl"]]}
4> init:get_argument(home). {ok,[["/home/harry"]]}
Returns error if there is no value associated with Flag.
Types:
Flags = [{Flag, Values}]
Flag = atom()
Values = [string()]
Returns all command line flags, as well as the system defined flags, see get_argument/1.
get_plain_arguments() -> [Arg]
Types:
Arg = string()
Returns any plain command line arguments as a list of strings (possibly empty).
get_status() -> {InternalStatus, ProvidedStatus}
Types:
InternalStatus = starting | started | stopping
ProvidedStatus = term()
The current status of the init process can be inspected. During system startup (initialization), InternalStatus is starting, and ProvidedStatus indicates how far the boot script has been interpreted. Each {progress, Info} term interpreted in the boot script affects ProvidedStatus, that is, ProvidedStatus gets the value of Info.
All applications are taken down smoothly, all code is unloaded, and all ports are closed before the system terminates. If the -heart command line flag was given, the heart program will try to reboot the system. Refer to heart(3) for more information.
To limit the shutdown time, the time init is allowed to spend taking down applications, the -shutdown_time command line flag should be used.
The system is restarted inside the running Erlang node, which means that the emulator is not restarted. All applications are taken down smoothly, all code is unloaded, and all ports are closed before the system is booted again in the same way as initially started. The same BootArgs are used again.
To limit the shutdown time, the time init is allowed to spend taking down applications, the -shutdown_time command line flag should be used.
Types:
Id = term()
Get the identity of the boot script used to boot the system. Id can be any Erlang term. In the delivered boot scripts, Id is {Name, Vsn}. Name and Vsn are strings.
All applications are taken down smoothly, all code is unloaded, and all ports are closed before the system terminates. If the -heart command line flag was given, the heart program is terminated before the Erlang node terminates. Refer to heart(3) for more information.
To limit the shutdown time, the time init is allowed to spend taking down applications, the -shutdown_time command line flag should be used.
Types:
Status = int()>=0 | string()
All applications are taken down smoothly, all code is unloaded, and all ports are closed before the system terminates by calling halt(Status). If the -heart command line flag was given, the heart program is terminated before the Erlang node terminates. Refer to heart(3) for more information.
To limit the shutdown time, the time init is allowed to spend taking down applications, the -shutdown_time command line flag should be used.
The init module interprets the following command line flags:
% erl -eval '{X,Y,Z}' = now(), random:seed(X,Y,Z).'
% erl -noshell -eval 'R = 16#1F+16#A0, io:format("~.16B~n", [R])' \ -s erlang halt BF
% erl -run foo -run foo bar -run foo bar baz 1 2
foo:start() foo:bar() foo:bar(["baz", "1", "2"]).
% erl -s foo -s foo bar -s foo bar baz 1 2
foo:start() foo:bar() foo:bar([baz, '1', '2']).
% erl -- a b -children thomas claire -ages 7 3 -- x y ... 1> init:get_plain_arguments(). ["a","b","x","y"] 2> init:get_argument(children). {ok,[["thomas","claire"]]} 3> init:get_argument(ages). {ok, [["7","3"]]} 4> init:get_argument(silly). error