Tuesday, August 18, 2009

erlang: how to make a windows service

Tired of fighting with the command line to make erlsrv work ?
I have a solution for you !
The problem are always the quotes, you have quotes for erlang and quotes for the windows command line...
Here's what I use to test my service:

(Pack everything in a simple "install.bat")

erlsrv remove "YourService"
erlsrv add "YourService" -stopaction "init:stop()." -sname Service -debugtype reuse -args "-kernel error_logger {file,\\""C:/Test/kernel.txt\\""} -setcookie YourCookie -s YourInit"

YourInit is the name of the module you want to start. The fun "start/0" will be called by "erl".

This install.bat is meant to be your debug version of your service, because the log file will grow indefinitely.

See the documentation for more information:

DebugType: Can be one of none (default), new, reuse or console. Specifies that output from the Erlang shell should be sent to a "debug log". The log file is named "servicename".debug or "servicename".debug."n", where "n" is an integer between 1 and 99. The log-file is placed in the working directory of the service (as specified in WorkDir). The reuse option always reuses the same log file ("servicename".debug) and the new option uses a separate log file for every invocation of the service ("servicename".debug."n"). The console option opens an interactive Windows® console window for the Erlang shell of the service.
The console option automatically disables the StopAction and a service started with an interactive console window will not survive logouts, OnFail actions do not work with debug-consoles either. If no DebugType is specified (none), the output of the Erlang shell is discarded.
The consoleDebugType is not in any way intended for production. It is only a convenient way to debug Erlang services during development. The new and reuse options might seem convenient to have in a production system, but one has to take into account that the logs will grow indefinitely during the systems lifetime and there is no way, short of restarting the service, to truncate those logs. In short, the DebugType is intended for debugging only. Logs during production are better produced with the standard Erlang logging facilities.

If you don't define the "WorkDir" (-w option) your debug file will be located in the "WINDOWS\system32" directory.

Finally, the service will be described in the registry in


No comments: