archimondain

archimondain

Call Phoenix function in command line

I would like to be able to call functions from my Elixir code while the whole Cowboy/Phoenix machinery is running. For some reason when I’m not on production everything works fine with iex -S mix. But on production I get

[error] Failed to start Ranch listener SyntaxWeb.Endpoint.HTTP in :ranch_tcp:listen([{:cacerts, :...}, {:key, :...}, {:cert, :...}, :inet6, {:port, 80}]) for reason :eaddrinuse (address already in use)

I’m not sure of what the problem is. From the error message, it seems that iex -S mix tries to listen port 80, while Cowboy is already listening to it. On the other hand it seems odd for the iex -S mix command to try running a server, does’n it ?

My question is : what is really happening ? and how can I load my project modules and run some elixir code in command line while a server is running on the machine ?

Marked As Solved

yurko

yurko

Are you using releases? The server option has to do with them, otherwise if you are running the production system with mix it’s just your mix config.

If you are using releases and want to do something with the running system, check out the remote console: mix release — Mix v1.20.2

Also Liked

hauleth

hauleth

If this is Phoenix application, and you have:

config :phoenix, serve_endpoints: true

In your production configuration, then application will try to start application, and by extension - start listening -on application launch. And iex -S mix is the same as iex -S mix run, and mix help run returns:

                                    mix run

Starts the current application and runs code.

mix run can be used to start the current application dependencies, the
application itself, and optionally run some code in its context. For long
running systems, this is typically done with the --no-halt option:

    mix run --no-halt

Which mean it starts application which will fail due to trying to reuse listening port.

archimondain

archimondain

Good call. I am using releases :slight_smile:, so that must be it.
I will check the link you provide

Thanks

Last Post!

archimondain

archimondain

Good call. I am using releases :slight_smile:, so that must be it.
I will check the link you provide

Thanks

Where Next?

Popular in Questions Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 130579 1222
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44167 214
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New