otp icon indicating copy to clipboard operation
otp copied to clipboard

Windows service fails to start on OS (re)boot

Open weiss opened this issue 2 years ago • 1 comments

Describe the bug SCM services installed using erlsrv fail to start on Windows (re)boot, at least on Windows 10, 11, and Windows Server 2019 (earlier Windows versions don't seem to be affected). An ErlSrv error is reported to the Windows event log: Could not get registry keys for erlang service. Seems erlsrv writes a few things into the registry and for some reason fails to read them when called early during boot. Manually starting the service after reboot works, and setting the startup type to "Automatic (Delayed Start)" works around the issue.

To Reproduce On a non-ancient Windows system with a non-ancient Erlang/OTP version installed:

  • Download and extract my minimal example project.
  • Change into the extracted directory and build an OTP release in an erl shell:
up_to_date = make:all(),
{ok, Conf} = file:consult("reltool.config"),
{ok, Spec} = reltool:get_target_spec(Conf),
ok = reltool:eval_target_spec(Spec, code:root_dir(), "rel"),
halt().
  • Change into the same directory within a cmd shell with administrator privileges, and install/start the SCM service:
rel\erts-<version>\bin\erlsrv.exe add example_1.0.0 -sname example
rel\erts-<version>\bin\erlsrv.exe start example_1.0.0
  • Check that the service is running in the Service Control Manager.
  • Reboot Windows, and see how the service is not running in the Service Control Manager.

Expected behavior The service starts up on (re)boot.

Affected versions I've reproduced the problem with Erlang/OTP 25.0.1.

Additional context This issue has been reported to several projects over the past few years, e.g.:

  • erlware/relx#878
  • bitwalker/distillery#632
  • processone/ejabberd#2544
  • emqx/emqx#547

Therefore, I'd assume this isn't a new problem. The usual workaround seems to be to use the delayed startup type as mentioned above (e.g., https://github.com/emqx/emqx-rel/commit/28b1a002ebb1bcf3dd8407fef1954e365fcd5bc6 or https://github.com/processone/eturnal/commit/9b452ea5f5370abd77437e238374eb380a853dba).

weiss avatar Jun 11 '22 17:06 weiss

This is not prioritized for us right now. PR is welcome. Help Wanted label set.

sverker avatar Jun 16 '22 19:06 sverker