This utility is specific to Windows NT/2000/XP® (and subsequent versions of Windows) It allows Erlang emulators to run as services on the Windows system, allowing embedded systems to start without any user needing to log in. The emulator started in this way can be manipulated through the Windows® services applet in a manner similar to other services.
Note that erlsrv is not a general service utility for Windows, but designed for embedded Erlang systems.
As well as being the actual service, erlsrv also provides a command line interface for registering, changing, starting and stopping services.
To manipulate services, the logged in user should have Administrator privileges on the machine. The Erlang machine itself is (default) run as the local administrator. This can be changed with the Services applet in Windows ®.
The processes created by the service can, as opposed to normal services, be "killed" with the task manager. Killing a emulator that is started by a service will trigger the "OnFail" action specified for that service, which may be a reboot.
The following parameters may be specified for each Erlang service:
On a system where release handling is
used, this should always be set to
If the system
uses release handling, this should be set to a program
similar to
The
This internal name can not be changed, it is fixed even if the service is renamed.
The internal service name can be seen in the Windows® service manager if viewing
The set and add commands adds or modifies a Erlang service respectively. The simplest form of an add command would be completely without options in which case all default values (described above) apply. The service name is mandatory.
Every option can be given without parameters, in which case
the default value is applied. Values to the options are
supplied only when the default should not be used
(i.e.
The following service options are currently available:
These commands are only added for convenience, the normal
way to manipulate the state of a service is through the
control panels services applet. The
This command removes the service completely with all its registered options. It will be stopped before it is removed.
If no service name is supplied, a brief listing of all Erlang services is presented. If a service-name is supplied, all options for that service are presented.
This command file is then set as heart command.
The environment variables can also be used to detect that we are running as a service and make port programs react correctly to the control events generated on logout (see below).
When a program runs in
the service context, it has to handle the control events that is
sent to every program in the system when the interactive user
logs off. This is done in different ways for programs running in
the console subsystem and programs running as window
applications. An application which runs in the console subsystem
(normal for port programs) uses the win32 function
/*
** A Console control handler that ignores the log off events,
** and lets the default handler take care of other events.
*/
BOOL WINAPI service_aware_handler(DWORD ctrl){
if(ctrl == CTRL_LOGOFF_EVENT)
return TRUE;
return FALSE;
}
void initialize_handler(void){
char buffer[2];
/*
* We assume we are running as a service if this
* environment variable is defined
*/
if(GetEnvironmentVariable("ERLSRV_SERVICE_NAME",buffer,
(DWORD) 2)){
/*
** Actually set the control handler
*/
SetConsoleCtrlHandler(&service_aware_handler, TRUE);
}
} ]]>
Even though the options are described in a Unix-like format, the case of the options or commands is not relevant, and the "/" character for options can be used as well as the "-" character.
Note that the program resides in the emulators
To easily manipulate the Erlang services, put
the
For release handling to work, use
start_erl(1), release_handler(3)