axelson

axelson

Scenic Core Team

Unable to run erlexec in a escript

I’m trying to run erlexec in an escript. It seems like it should be possible, but since erlexec depends on a priv directory by default, (which isn’t supported by escripts) I just need to configure it to point to a different port executable. I should be able to pass a {:portexe, executable_path option, but I’m not sure where to put that configuration because the startup of erlexec happens automatically on since on application boot by Elixir.

Here’s a test repository: https://github.com/axelson/erlexec_escript_example
Just run:

mix deps.get
mix escript.build
./erl_exec_test

And you should see an error message like:

22:15:12.827 [warn]  Priv directory not available

22:15:12.834 [info]  Application erlexec exited: :exec_app.start(:normal, []) returned an error: shutdown: failed to start child: :exec
    ** (EXIT) bad return value: 'Cannot find file : no such file or directory'
Could not start application erlexec: :exec_app.start(:normal, []) returned an error: shutdown: failed to start child: :exec
    ** (EXIT) bad return value: 'Cannot find file : no such file or directory'

Relevant links:

Can anyone point me in the right direction?

Marked As Solved

josevalim

josevalim

Creator of Elixir

My suggestion would be to include the binary inside the escript (you can read it, put it in a module attribute and put it in a function) and then write it down to the user temporary directory. You can delay the start of erlexec by setting it to runtime: false in your mix.exs.

Also Liked

axelson

axelson

Scenic Core Team

Okay, based on your instructions I’ve created a little helper module that copies the exec-port binary into the systems temp folder and it is currently working well:

defmodule ErlexecInit do
  @moduledoc """
  Responsible for starting Erlexec in a manner compatible with escripts. By
  default the exec-port binary is compiled into erlexec's priv folder, but since
  escripts don't have access to the priv directories we need to store the binary
  into the code and then on startup we need to write it out into the system's
  tempdirectory

  Reference: https://forum.elixirforum.net/t/unable-to-run-erlexec-in-a-escript/21603
  """

  use GenServer

  @exec_port_binary_path Application.app_dir(:erlexec, [
                           "priv",
                           :erlang.system_info(:system_architecture),
                           "exec-port"
                         ])

  @execport_binary File.read!(@exec_port_binary_path)

  def start_link(_, name \\ __MODULE__) do
    GenServer.start_link(__MODULE__, nil, name: name)
  end

  @impl GenServer
  def init(_) do
    port_exe_path =
      System.tmp_dir!()
      |> Path.join("tmp-exec-port-#{System.unique_integer([:positive])}")
      |> String.to_charlist()

    File.write!(port_exe_path, @execport_binary)
    File.chmod!(port_exe_path, 0o700)

    :exec.start(portexe: port_exe_path)

    {:ok, []}
  end
end
axelson

axelson

Scenic Core Team

I haven’t looked at this code in a while but I think you’re referring to this part of the snippet above:

:exec.start(portexe: port_exe_path)

I’m calling that function in a GenServer that is part of my supervision tree but you would likely also be okay if you dropped that code directly into your application.ex file in the start/2 function.

Here’s the full code if you want to take a look ls_proxy/ls_proxy/lib/erlexec_init.ex at 2435d956f924813021493a9b292f81b81a7eb00d · axelson/ls_proxy · GitHub

JeremyWildsmith

JeremyWildsmith

axelson, thanks for your quick response.

That did indeed work, I misunderstood the purpose of that line of code, but it makes sense now.

Best Regards,

Where Next?

Popular in Questions Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
logicmason
Hi there, I'm working through my first release with elixir/phoenix. I've built a release with distillery and found that it crashes when I...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New

Other popular topics Top

chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30048 115
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

We're in Beta

About us Mission Statement