Erlang/Webmachine doesn't start on heroku - heroku

I've been trying to setup a Webmachine app on Heroku, using the buildpack recommended. My Procfile is
# Procfile
web: sh ./rel/app_name/bin/app_name console
Unfortunately this doesn't start the dyno correctly, it fails with
2015-12-08T16:34:55.349362+00:00 heroku[web.1]: Starting process with command `sh ./rel/app_name/bin/app_name console`
2015-12-08T16:34:57.387620+00:00 app[web.1]: Exec: /app/rel/app_name/erts-7.0/bin/erlexec -boot /app/rel/app_name/releases/1/app_name -mode embedded -config /app/rel/app_name/releases/1/sys.config -args_file /app/rel/app_name/releases/1/vm.args -- console
2015-12-08T16:34:57.387630+00:00 app[web.1]: Root: /app/rel/app_name
2015-12-08T16:35:05.396922+00:00 app[web.1]: 16:35:05.396 [info] Application app_name started on node 'app_name#127.0.0.1'
2015-12-08T16:35:05.388846+00:00 app[web.1]: 16:35:05.387 [info] Application lager started on node 'app_name#127.0.0.1'
2015-12-08T16:35:05.399281+00:00 app[web.1]: Eshell V7.0 (abort with ^G)
2015-12-08T16:35:05.399283+00:00 app[web.1]: (app_name#127.0.0.1)1> *** Terminating erlang ('app_name#127.0.0.1')
2015-12-08T16:35:06.448742+00:00 heroku[web.1]: Process exited with status 0
2015-12-08T16:35:06.441993+00:00 heroku[web.1]: State changed from starting to crashed
But when I run the same command via heroku toolbelt, it starts up with the console.
$ heroku run "./rel/app_name/bin/app_name console"
Running ./rel/app_name/bin/app_name console on tp-api... up, run.4201
Exec: /app/rel/app_name/erts-7.0/bin/erlexec -boot /app/rel/app_name/releases/1/app_name -mode embedded -config /app/rel/app_name/releases/1/sys.config -args_file /app/rel/app_name/releases/1/vm.args -- console
Root: /app/rel/app_name
Erlang/OTP 18 [erts-7.0] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false]
16:38:43.194 [info] Application lager started on node 'app_name#127.0.0.1'
16:38:43.196 [info] Application app_name started on node 'app_name#127.0.0.1'
Eshell V7.0 (abort with ^G)
(app_name#127.0.0.1)1>
Is there way to start the node, maybe as a daemon on the dyno(s)?
Note I've tried to use start instead of console, but that did not yield any success.

So after much tinkering, trial and error, figured out what was wrong. Heroku does not like the interactive shell to be there - hence the crash on starting the Erlang app through console fails.
I've adjusted my Procfile, to the following:
# Procfile
web: erl -pa $PWD/ebin $PWD/deps/*/ebin -noshell -boot start_sasl -s reloader -s app_name -config ./rel/app_name/releases/1/sys
Which boots up the application app_name, using the the release's sys.config configuration file. What was crucial here, is to have the -noshell option in the command, that allows heroku to run the process as they expect it.

Related

Deploy H2O Wave application to Heroku?

I am relatively new to deploying python web applications but I was trying to deploy my H2O wave app to Heroku but kept running into issues and I couldn't find much help in the documentation.
Everything works fine locally if I start the server using the command (in the SDK for wave):
$ ./waved
2021/01/22 10:26:38 #
2021/01/22 10:26:38 # ┌─────────────────────────┐
2021/01/22 10:26:38 # │ ┌ ┌ ┌──┐ ┌ ┌ ┌──┐ │ H2O Wave
2021/01/22 10:26:38 # │ │ ┌──┘ │──│ │ │ └┐ │ 0.11.0 20210118061246
2021/01/22 10:26:38 # │ └─┘ ┘ ┘ └──┘ └─┘ │ © 2020 H2O.ai, Inc.
2021/01/22 10:26:38 # └─────────────────────────┘
2021/01/22 10:26:38 #
2021/01/22 10:26:38 # {"address":":10101","t":"listen","webroot":"/Users/kenjohnson/Documents/TTT/H2O Wave/wave/www"}
2021/01/22 10:26:39 # {"addr":"127.0.0.1:64065","route":"/tennis-pred","t":"ui_add"}
2021/01/22 10:46:04 # {"host":"http://127.0.0.1:8000","route":"/counter","t":"app_add"}
then in the root directory of the project running:
uvicorn tennis_pred_app:main
For deployment, all I have other than my wave python file is a requirements.txt and a Procfile:
web: uvicorn tennis_pred_app:main --host 0.0.0.0 --port 10101
this is what my foo (tennis_pred_app.py) looks like (simplified):
from h2o_wave import Q, main, app, ui
#app("/tennis-pred")
async def serve(q: Q):
show_form(q)
await q.page.save()
The error I am currently running into is:
2021-01-22T00:28:41.000000+00:00 app[api]: Build started by user x
2021-01-22T00:31:07.040695+00:00 heroku[web.1]: State changed from crashed to starting
2021-01-22T00:31:06.879674+00:00 app[api]: Deploy 1dc65130 by user x
2021-01-22T00:31:06.879674+00:00 app[api]: Release v23 created by user x
2021-01-22T00:31:26.580199+00:00 heroku[web.1]: Starting process with command `uvicorn tennis_pred_app:main --host 0.0.0.0 --port 20819`
2021-01-22T00:31:30.299421+00:00 app[web.1]: INFO: Uvicorn running on http://0.0.0.0:20819 (Press CTRL+C to quit)
2021-01-22T00:31:30.299892+00:00 app[web.1]: INFO: Started parent process [4]
2021-01-22T00:31:46.000000+00:00 app[api]: Build succeeded
2021-01-22T00:32:27.041954+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2021-01-22T00:32:27.093099+00:00 heroku[web.1]: Stopping process with SIGKILL
2021-01-22T00:32:27.199933+00:00 heroku[web.1]: Process exited with status 137
2021-01-22T00:32:27.242769+00:00 heroku[web.1]: State changed from starting to crashed
You don't get to choose your port on Heroku. Instead, Heroku assigns you a port via the PORT environment variable.
Change your Procfile from
web: uvicorn foo:main --host 0.0.0.0 --port 10101
to
web: uvicorn foo:main --host 0.0.0.0 --port $PORT
See this blog post for the exact guide.
More explanation for why the other answer is generally correct but does not apply to H2O Wave:
If you look at architecture, you may notice there are actually 2 servers included. The first is a python (uvicorn) one that is used for your Wave app - this is not exposed to the outside directly but uses a kind of a proxy server - the second server. This second (Golang) server communicates directly with a browser (outside) and thus should be started on the $PORT Heroku assigned to you, e.g. via the H2O_WAVE_LISTEN env variable - see other config options.

Problem deploying Phoenix app to Gigalixir: "No file named server#127.0.0.1"

I am trying to deploy Hashrockets TIL Phoenix App to Gigalixir.
This is what I get after push to Gigalixir:
2020-08-23T05:58:55.071975+00:00 til[gigalixir-run]: Attempting to start 'til' on host 'til-6c4c5d7854-ddpfh'
2020-08-23T05:58:55.071987+00:00 til[gigalixir-run]: Attempting health checks on port 4000
2020-08-23T05:58:55.874467+00:00 til[til-6c4c5d7854-ddpfh]: web.1 | started with pid 49
2020-08-23T05:58:57.568099+00:00 til[til-6c4c5d7854-ddpfh]: web.1 | No file named server#127.0.0.1
2020-08-23T05:58:57.976006+00:00 til[til-6c4c5d7854-ddpfh]: web.1 | exited with code 1
2020-08-23T05:58:57.976034+00:00 til[til-6c4c5d7854-ddpfh]: system | sending SIGTERM to all processes
I cannot make sense of the error message No file named server#127.0.0.1. What can I do now?
The reason for this problem is, that the Procfile coming with the project is probably meant to be used with Heroku and contains
web: MIX_ENV=prod elixir --cookie $OTP_COOKIE --name server#127.0.0.1 --erl '-kernel inet_dist_listen_min 9000' --erl '-kernel inet_dist_listen_max 9000' -S mix phx.server
Renaming the file to Procfile.disabled and thus making Gigalixir use its default Procfile solves this problem.

Deploy Phoenix application in Heroku, but result in application error

I'm deployed my application in Heroku, but although deploy ok, in browser show view:
The Only clue of error is in log of application:
: State changed from crashed to starting
2017-03-31T020 heroku[web.1]: Process exited with status 1
1]: Starting process with command `MIX_ENV=prod mix phoenix.server`
=INFO REPORT==== 31-Mar-2017::02:20:04 ===
application: boom_one
exited: {{shutdown,
{failed_to_start_child,'Elixir.BoomOne.Endpoint',
{shutdown,
{failed_to_start_child,'Elixir.Phoenix.Endpoint.Server',
{shutdown,
{failed_to_start_child,
{ranch_listener_sup,'Elixir.BoomOne.Endpoint.HTTP'},
{'EXIT',
{noproc,
{gen_server,call,
[ranch_server,
{set_new_listener_opts,'Elixir.BoomOne.Endpoint.HTTP',
16384,
[{env,
[{'_',[],
[{[<<"socket">>,<<"websocket">>],
[{dispatch,
[],'Elixir.Phoenix.Endpoint.CowboyWebSocket',
{'Elixir.Phoenix.Transports.WebSocket',
{'Elixir.BoomOne.Endpoint',
'Elixir.BoomOne.UserSocket',websocket}}},
{'Elixir.BoomOne.Endpoint',
{'_',[],'Elixir.Plug.Adapters.Cowboy.Handler',
[]}}]}]}]}]}]}}}}}}}}},
{'Elixir.BoomOne',start,[normal,[]]}}
type: permanent
** (exit) exited in: GenServer.call(Mix.State, {:get, {Map, :get, [:debug, false]}}, 5000)
** (EXIT) no process
(mix) lib/mix/cli.ex:65: Mix.CLI.run_task/2
(elixir) lib/code.ex:363: Code.require_file/2
(elixir) lib/gen_server.ex:596: GenServer.call/3
{"init terminating in do_boot",{noproc,{gen_server,call,[elixir_config,{get_and_put,at_exit,[]}]}}}
init terminating in do_boot ()
Crash dump is being written to: erl_crash.dump...done
1]: Process exited with status 1
1]: State changed from starting to crashed
I followed this phoenix page tutorial on heroku.
I encountered the same problem and solved it by hardcoding "secret_key_base" setting instead of reading from system environment variable. This solution is not generally recommended as it exposes the secret key in the code repository but it might help debug the issue.
The problem has solution. As mentioned in elixirforum.com, you have to change the elixir version from 1.3 to 1.4

"iex -S mix" returns error server cannot start in Mac

I was trying to start up my mix project in elixir on Mac. The project works fine on CentOS.
The error looks like this:
_build/dev/lib/<project_name>/ebin/Elixir.Mix.Tasks.Proddata.beam failed: :badfile
** (Mix) Could not start application exq: Exq.start(:normal, []) returned an error:
shutdown: failed to start child: Exq.Manager
** (EXIT) {:connection_error, {:connection_error, :econnrefused}}
I tried updating my erlang version from brew, but it did not help. I have also tried cleaning dependencies. I am using
Erlang/OTP 18 [erts-7.0.3] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
and Elixir 1.0.5.
Let's look at the errors:
_build/dev/lib//ebin/Elixir.Mix.Tasks.Proddata.beam failed: :badfile
This one means you are trying to invoke a task with the wrong name. Maybe you are calling "mix run proddata" and that will look for the task named Proddata but you may have named it differently. Use mix help to see which tasks are available.
** (Mix) Could not start application exq: Exq.start(:normal, []) returned an error: shutdown: failed to start child: Exq.Manager
** (EXIT) {:connection_error, {:connection_error, :econnrefused}}
It it saying it cannot connect to something. It seems that Exq.Manager needs Redis, so make sure Redis is running and you have configured it with the proper credentials.

Deploying Play 2.0 app on Heroku

So I am kind of new to setting up servers. And I have been struggling with various sql issues all night. I think the only thing that sits between me and a successfully running play app is this: error
Starting process with command `target/start -Dhttp.port=80 `
2012-04-04T05:58:52+00:00 app[web.1]: Play server process ID is 1
2012-04-04T05:58:53+00:00 app[web.1]: [info] play - database [default] connected at jdbc:mysql://us-cdbr-east.cleardb.com/heroku_cd914b667dae168
2012-04-04T05:58:56+00:00 app[web.1]: [info] play - Application started (Prod)
2012-04-04T05:58:56+00:00 app[web.1]: Oops, cannot start the server.
2012-04-04T05:58:56+00:00 app[web.1]: org.jboss.netty.channel.ChannelException: Failed to bind to: /0.0.0.0:80
... more errors
Does anyone spot any problems? Do I need any java options arguments?
I tried specifying a user port in the Procfile, and got a different error message:
2012-04-04T07:01:36+00:00 heroku[web.1]: Starting process with command `target/start -Dhttp.port=2000`
2012-04-04T07:01:37+00:00 app[web.1]: Play server process ID is 1
2012-04-04T07:01:40+00:00 app[web.1]: [info] play - database [default] connected at jdbc:mysql://us-cdbr-east.cleardb.com/heroku_cd914b667dae168
2012-04-04T07:01:45+00:00 app[web.1]: [info] play - Application started (Prod)
2012-04-04T07:01:45+00:00 app[web.1]: [info] play - Listening for HTTP on port 2000...
2012-04-04T07:01:46+00:00 heroku[web.1]: Error R11 (Bad bind) -> Process bound to port 2000, should be 47248 (see environment variable PORT)
2012-04-04T07:01:46+00:00 heroku[web.1]: Stopping process with SIGKILL
2012-04-04T07:01:47+00:00 heroku[web.1]: Process exited with status 137
2012-04-04T07:01:47+00:00 heroku[web.1]: State changed from starting to crashed
I have no idea what is happening. How do I change this environment variable? This heroku process model is very confusing to me.
I think the problem is that you're not allowing Heroku to specify the port. Googling your error I find: https://devcenter.heroku.com/articles/error-codes#r11__bad_bind
So instead of doing this:
web: target/start -Dhttp.port=80
Do this
web: target/start -Dhttp.port=$PORT
James has a nice writeup on getting a more advanced Play 2.0 app deployed here.

Resources