📜 ⬆️ ⬇️

Erlang, rebar3 and installation of service under Windows

How to make the Erlang release work as a service under Windows. Let's leave the question behind why. Just sometimes it is needed. So let's focus on HOW. To make it even harder, we set ourselves the task of doing this with the help of wixtoolset .


This article is some kind of crib to yourself. Although I really hope that it will never come in handy. Go.


Imagine that we somehow put the files and brought a run-time with us. The launch of the application in the form of a console works and now you need to arrange the launch of the application as a service. If there are problems already at this stage - write to me, I was there, I was trampling there.


So, here we are waiting for some fun pitfalls. We somehow can run the script NAME-APPLICATION.cmd install. And it even works. But there are 2 drawbacks - a black screen jumps up and the service is not deleted when the application is removed.


So let's move on to what will be lacking:


1) The erl.ini file in the erts-NUMBER \ bin directory. Its content after installation contains the paths of the machine where the release was collected. Its contents must be changed. And in the ways you should put double slashes.
2) The service is started using the erlsrv.exe file. This is part of the runtime, everything is fine here. We must not forget to take it with you.
3) erlsrv.exe expects to find the start.boot file at releases \ VERSION. And he is not there. And you need to copy it.


<DirectoryRef Id="_VERSION"> <Component Id="CopyBootFile" Guid="{GUID}"> <CopyFile Id="start.boot" FileId="APPNAME.boot" DestinationDirectory="_VERSION" DestinationName="start.boot" /> </Component> </DirectoryRef> 

4) erlsrv.exe stores the service parameters in the register. And they need to finish themselves.


Now examples


For example, our miracle application is called erlang_service. We write to the register:


 <RegistryKey Root="HKLM" Key="Software\Ericsson\Erlang\ErlSrv\1.1\erlang_service" > <RegistryValue Type="expandable" Name="Args" Value="-setcookie MY_COOKIE ++ -rootdir &quot;[ProgramFiles64Folder]ErlangService&quot;" /> <RegistryValue Type="string" Name="Comment" Value="Erlang node service" /> <RegistryValue Type="integer" Name="DebugType" Value="0" /> <RegistryValue Type="multiString" Name="Env" Value="" /> <RegistryValue Type="string" Name="InternalServiceName" Value="erlang_service" /> <RegistryValue Type="expandable" Name="Machine" Value="[ROOT]erts-9.2\bin\start_erl.exe" /> <RegistryValue Type="string" Name="Name" Value="" /> <RegistryValue Type="integer" Name="OnFail" Value="0" /> <RegistryValue Type="integer" Name="Priority" Value="32" /> <RegistryValue Type="string" Name="SName" Value="erlang_service" /> <RegistryValue Type="string" Name="StopAction" Value="init:stop()." /> <RegistryValue Type="expandable" Name="WorkDir" Value="[ROOT]" /> </RegistryKey> 

Here we have:


--rootdir - the place where the application is installed. Exactly. If you take for example [ROOT] - id of the directory itself, then nothing will work, since at the end there will be a slash. And it confuses him.
InternalServiceName Value = "erlang_service" - under this name we will put the service.
SName is erlang short name
[ROOT] - ID of the directory in which our files are located.


Well, the service itself:


 <ServiceInstall Id="ErlangService" Type="ownProcess" Vital="yes" Start="auto" Account="LocalSystem" ErrorControl="normal" Name="erlang_service" DisplayName="ErlangService" Description="erlang_service-[ProductVersion]" Interactive="no" > <ServiceDependency Id="LanmanWorkstation" /> <util:ServiceConfig FirstFailureActionType="restart" SecondFailureActionType="restart" ThirdFailureActionType="none" ResetPeriodInDays="1"/> </ServiceInstall> <ServiceControl Id="ErlangServiceControl" Start="install" Stop="uninstall" Remove="uninstall" Name="erlang_service" Wait="yes" /> 

As a result, we have a service that is automatically set, stops and correctly deleted.


Everything.


')

Source: https://habr.com/ru/post/351734/


All Articles