Running into an odd error with Phoenix on Heroku, where it doesn't seem to bind to the port properly.
Running into a situation where phoenix is not binding to $PORT. Heroku's log:
2016-03-25T22:22:54.716907+00:00 heroku[web.1]: State changed from crashed to starting
2016-03-25T22:23:03.156662+00:00 heroku[web.1]: Starting process with command mix phoenix.server
2016-03-25T22:23:07.985368+00:00 app[web.1]: [info] Running AppName.Endpoint with Cowboy using http on port 4000
2016-03-25T22:23:10.027386+00:00 app[web.1]: 25 Mar 22:23:10 - info: compiled 5 files into 2 files, copied 3 in 1.5 sec
2016-03-25T22:24:03.442109+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2016-03-25T22:24:03.442109+00:00 heroku[web.1]: Stopping process with SIGKILL
2016-03-25T22:24:04.195291+00:00 heroku[web.1]: Process exited with status 137
2016-03-25T22:24:04.211713+00:00 heroku[web.1]: State changed from starting to crashed
My prod.exs:
config :appname, AppName.Endpoint,
http: [port: {:system, "PORT"}],
url: [scheme: "https", host: "AppName.herokuapp.com", port: 443],
force_ssl: [rewrite_on: [:x_forwarded_proto]],
cache_static_manifest: "priv/static/manifest.json",
secret_key_base: System.get_env("SECRET_KEY_BASE")
It looks like it's going to port 4000 instead of whatever port Heroku wants, and I'm not sure why.
The fix is twofold:
to use the phoenix buildpack config and export the PORT as well, like so: config_vars_to_export=(DATABASE_URL PORT)
Avoid changing the MIX_ENV without recompiling the app, as that behavior is unsupported, as explained here.
Related
I programmed a simple bot that is connected to Google Sheets API. It asks a few questions to the user and stores it in the Sheet I have. When I use bot.polling it works fine, but I was trying the webhook so I could use Heroku to have my bot running 24/7.
I introduced the code:
#server.route('/' + token, methods=['POST'])
def getMessage():
bot.process_new_updates([telebot.types.Update.de_json(request.stream.read().decode("utf-8"))])
return "!", 200
#server.route("/")
def webhook():
bot.remove_webhook()
bot.set_webhook(url = '<Heroku App Link>' + token)
return "!", 200
if __name__ == "__main__":
server.run(host="0.0.0.0", port = int(os.environ.get('PORT', 5000)))
I have the requirements.txt file and the Procfile that currently is like this:
web: python3 bot.py
I tried a bunch of things in the Procfile but this is the only one that didn't gave an error.
When I saw the log this is what I got:
2019-09-24T10:18:54.369238+00:00 heroku[web.1]: State changed from crashed to starting
2019-09-24T10:19:04.416777+00:00 heroku[web.1]: Starting process with command `python3 bot.py`
2019-09-24T10:19:09.868915+00:00 heroku[web.1]: State changed from starting to up
2019-09-24T10:19:09.790773+00:00 app[web.1]: * Serving Flask app "bot" (lazy loading)
2019-09-24T10:19:09.790800+00:00 app[web.1]: * Environment: production
2019-09-24T10:19:09.790853+00:00 app[web.1]: WARNING: This is a development server. Do not use it in a production deployment.
2019-09-24T10:19:09.790940+00:00 app[web.1]: Use a production WSGI server instead.
2019-09-24T10:19:09.790991+00:00 app[web.1]: * Debug mode: off
2019-09-24T10:19:09.799470+00:00 app[web.1]: * Running on http://0.0.0.0:57826/ (Press CTRL+C to quit)
2019-09-24T10:19:15.000000+00:00 app[api]: Build succeeded
Can anyone help me understand why the bot doesn't answer any commands?
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
I have big issues with deploying my application on heroku server. I've done it with help of tutorial from phoenix webpage. But it doesn't work. Below you can see the logs and configuration i used.
heroku logs
2016-02-07T04:28:55.623435+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web
process failed to bind to $PORT within 60 seconds of launch
2016-02-07T04:28:55.623435+00:00 heroku[web.1]: Stopping process with SIGKILL
2016-02-07T04:28:56.344649+00:00 heroku[web.1]: State changed from starting to c
rashed
2016-02-07T04:28:56.348324+00:00 heroku[web.1]: Process exited with status 137
2016-02-07T09:54:29.124036+00:00 heroku[web.1]: State changed from crashed to st
arting
2016-02-07T09:54:34.703208+00:00 heroku[web.1]: Starting process with command `m
ix run --no-halt`
2016-02-07T09:55:35.386922+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web
process failed to bind to $PORT within 60 seconds of launch
2016-02-07T09:55:35.386922+00:00 heroku[web.1]: Stopping process with SIGKILL
2016-02-07T09:55:36.330258+00:00 heroku[web.1]: State changed from starting to c
rashed
2016-02-07T09:55:36.323082+00:00 heroku[web.1]: Process exited with status 137
2016-02-07T12:14:35.182306+00:00 heroku[router]: at=error code=H10 desc="App cra
shed" method=GET path="/" host=kpsz.herokuapp.com request_id=7de0ee97-14cf-46f9-
a9a3-cbffa09ac379 fwd="83.7.11.212" dyno= connect= service= status=503 bytes=
2016-02-07T12:14:35.850018+00:00 heroku[router]: at=error code=H10 desc="App cra
shed" method=GET path="/favicon.ico" host=kpsz.herokuapp.com request_id=4e9b1979
-deb6-497b-80b2-655615f43d01 fwd="83.7.11.212" dyno= connect= service= status=50
3 bytes=
Configuration prod.exs
config :kpsz, Kpsz.Endpoint,
http: [port: System.get_env("PORT")],
url: [host: "example.com", port: 80],
cache_static_manifest: "priv/static/manifest.json",
secret_key_base: System.get_env("SECRET_KEY_BASE")
config :kpsz, Kpsz.Repo,
adapter: Ecto.Adapters.Postgres,
url: System.get_env("DATABASE_URL"),
pool_size: 20
I'm not sure if that's the problem but you could try to replace
http: [port: System.get_env("PORT")]
with
http: [port: {:system, "PORT"}]
At least that's what I'm using in my apps. You can also read the docs for more information http://www.phoenixframework.org/docs/heroku
I had a similar problem.
Adding a Procfile with a single line web: mix phoenix.server solved it.
heroku destroy project name
heroku create
and for some weird reason it works now...
Thanks very much for help.
I ran into this issue and, for me, the fix was as follow (copied from the answer on this question).
The fix is twofold:
to use the phoenix buildpack config and export the PORT as well, like so: config_vars_to_export=(DATABASE_URL PORT)
Avoid changing the MIX_ENV without recompiling the app, as that behavior is unsupported, as explained here.
As Recreation solves the problem, I suspect the problem is with loading environment variables.
Once I had a similar problem in my local. My observations
mix phoenix.server (you might see the message compiled so and so files)
Stopped the server
Export/Change the env variable in zshrc/bashrc file and source it
Start the server (you might not see that compilation message, as there are no changes in your codebase and so your new/edited env variables won't get reflected)
If you just add a space in that file will make it compile and take that env variable.
Reason for your problem might be: Setting env variables after the server is running/deployed, as env variables are converted to value during the compilation time itself.
I had a similar problem when deploying the phoenix umbrella project with docker.
I've taken these steps:
Heroku https://hexdocs.pm/phoenix/heroku.html#deploying-to-heroku-using-the-container-stack
Dockerfile https://hexdocs.pm/phoenix/releases.html#containers
I've also looked at other links, but these two was the best.
The only problem with that Dockerfile is that it needs $PORT (and $SECRET_KEY_BASE) on the build step which is not present. So we have to "stub" it somehow in prod.exs. BUT we have to provide real $PORT on a run step (runtime configuration). So you have to be sure that you renamed config/prod.secret.exs to config/releases.exs (the 1 step at https://hexdocs.pm/phoenix/releases.html#runtime-configuration) or just create config/releases.exs which would rewrite $PORT (and maybe some other application environment variables - for example, $SECRET_KEY_BASE).
UPD: as #Daniel mentions - releases is an Elixir 1.9 feature.
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.
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.