I want to write a utility that launches, does one thing (which might take quite a while), then exits, without logging an error and returning 0 to the OS. I want the “one thing” to be supervised such that if it exits abnormally, it is run again. I want to deploy the normal way via using distillery to create a package which is complete.
I’m having trouble figuring out the options between escript vs my deploy needs, regular application vs the exit reporting an error.
I just hadn’t looked in all the right places: System.halt(0) will get me what I want, although it seems like a rude way to do it, so definitely open to better suggestions.
As I’m now on a computer instead of a mobile, I can give you better example:
def loop do
case System.cmd("./foo.sh", []) do
{_, 0} -> nil
{_, _} ->
IO.puts "."
loop()
end
end
loop
while foo.sh has this content:
#!/usr/bin/env bash
exit $((RANDOM % 10))
Of course, this is overly simplified, as it will not output anything from the cmd to run. It just prints a dot and a newline for every failing run.
If you need proper forwarding of the scripts output to stdout and stderr, you need to use the Port module or one of the available wrapper packages (which I only know that they exist, but I can’t name them)
That covers, roughly, the re-try (although to be clear I am not running an external command, I’m running Elixir code that may take a long time). But it doesn’t cover getting me a self-contained package to deploy.
Why? Such a file were about 50 megabytes in size, plus the code you wrote on your own.if you have multiple of such self contained packages they would contain much identical stuff, which is shared when you just require erlang.