Hi,
I have an Elixir 1.15.7 application. At first, it was intended to be installed only on Windows. Therefore I configured mix.iex
with Windows-specific environment variable ALLUSERSPROFILE
in my config provider:
defmodule MyApp.MixProject do
use Mix.Project
def project do
[
...
releases: releases(),
]
end
...
defp releases do
[
myapp: [
include_executables_for: [:windows],
config_providers: [
{MyApp.Config.TOMLConfigProvider,
"%ALLUSERSPROFILE%\\MyCompany\\MyApp\\config.toml"}
]
]
]
end
end
Now, I need to provide releases for linux as well and I first would like to get rid of the Windows-specific environment variable in mix.iex
.
I have adapted my config provider to be used like so:
defp releases do
[
myapp: [
include_executables_for: [:unix, :windows],
config_providers: [
{MyApp.Config.TOMLConfigProvider,
{:system, "MYAPP_CONFIG_DIR", "/configuration.toml"}}
]
]
]
end
and I have created a rel/env.bat.eex
:
@echo off
set MYAPP_CONFIG_DIR=%ALLUSERSPROFILE%\MyCompany\MyApp
With that in place, I can successfully launch my release with:
C:\MyCompany\MyApp>dir
Volume in drive C is OS
Volume Serial Number is ************
Directory of C:\MyCompany\MyApp
17.01.2024 15:34 <DIR> .
17.01.2024 15:01 <DIR> ..
17.01.2024 15:33 <DIR> bin
17.01.2024 15:33 <DIR> erts-13.2.2.5
17.01.2024 15:34 <DIR> lib
17.01.2024 15:34 <DIR> releases
17.01.2024 15:34 451 643 unins000.dat
17.01.2024 15:33 3 223 613 unins000.exe
2 File(s) 3 675 256 bytes
6 Dir(s) 1 530 448 859 136 bytes free
C:\MyCompany\MyApp>bin\myapp.bat start
But the goal is to install the Windows service and after doing so (i.e. bin\myapp.bat install
), the problem is that the service stops immediately after it started:
C:\MyCompany\MyApp>erts-13.2.2.5\bin\erlsrv.exe start myapp_myapp
erts-13.2.2.5\bin\erlsrv.exe: Service myapp_myapp started.
I am pretty sure the env.bat
is not executed when starting the Windows service. I have no log to confirm this but when I use an absolute path in my config provider instead of the {:system, "MYAPP_CONFIG_DIR", "/configuration.toml"}
tuple, then the service starts and I can successfully access my web app.
Is mix release’s env.bat
suppose to work with Windows service?