我需要你的帮助!我正在尝试在应用程序自动启动(通过Boot Hooks -https://hexdocs.pm/distillery/boot-hooks.html#content)之前在一个酿酒厂版本(Elixir-应用程序)中运行迁移。开发和生产平台必须为Windows。
问题:我找不到任何关于Windows (.bat)-Scripts的信息,它引用了这个问题-我搜索了一个"pre_start.bat"-File的脚本-用来调用ERTS节点,最后在其中调用我的Elixir代码。
我的distillery-config : rel\config.exs
environment :prod do
...
set pre_start_hook: "rel/hooks/pre_start"
...
end所需的脚本应该调用我的"Elixir.MyApp.ReleaseTask.migrate"-Function的代码,我如何实现这一点?
下面的代码是我到目前为止得到的代码。但是它不起作用..
@echo off
echo Running migrations
echo.
echo.
echo.
cd %RELEASE_ROOT_DIR%
@set system_erl="<erl_directory>\erts-9.1\bin\erl.exe"
@set erl=%system_erl%
@set system_root_dir_cmd=%system_erl% -noshell -eval "io:format(\"~s\", [filename:nativename(code:root_dir())])." -s init stop
@set rootdir=%system_root%
@set system_erts_vsn_cmd=%system_erl% -noshell -eval "Ver=erlang:system_info(version),io:format(\"~s\", [Ver])" -s init stop
@set erts_vsn=%system_erts_vsn%
@set erts_dir=%rootdir%\erts-%erts_vsn%
@set rel_name="my_api"
@set rel_vsn="1.0"
@set consolidated_dir=%rootdir%\lib\%rel_name%-%rel_vsn%\consolidated
@%erl% -boot_var ERTS_LIB_DIR "%erts_dir%\..\lib" ^
-hidden -noshell -boot start_clean ^
-pa "%consolidated_dir%" ^
-s "Elixir.MyApp.ReleaseTasks" "seed" -s init stop
echo Migrations run successfully当我完全错误的时候,请纠正我。感谢任何人的帮助!顺便说一句,这是一个phoenix应用程序。
发布于 2017-11-09 23:01:35
我会改用erlang的原生escript。要构建它,请执行以下操作:
更新mix.exs,,例如::
escript: [main_module: MyApp, path: "bin/migrator"]添加到MyApp.Mixfile.project/0函数返回的数组中,并将bin目录添加到版本中:
# ⇓⇓⇓
files: ~w|bin lib mix.exs README.md|,返回到由MyApp.Mixfile.package/0返回的数组
创建MyApp.main/1函数2.创建函数:
def main(_args) do
MyApp.ReleaseTasks.migrate
end你已经准备好了。在release中将有bin/migrator中的escript (您在步骤1中使用的名称)。
现在您应该能够运行bin/migrator了,因为它是一个普通的、很好的可执行文件。
旁注:mix compile也会构建这个可执行文件,所以在使用distillery运行之前,您可以试用它并测试它。
https://stackoverflow.com/questions/47204350
复制相似问题