axelson
Scenic Core Team
I know that you can tell the phoenix server to start manually? I know you can start the server automatically with mix phx.start or by setting server: true in your Endpoint configuration, but I don’t see a way to start it manually after the Endpoint is already started.
My use-case is that if a given port is already taken, I want to start on the next available port. I suppose one workaround is to set server: true but then don’t start the endpoint in the initial supervision tree and use a DynamicSupervisor or similar to start the endpoint manually. Tried this and it doesn’t work
If I change the port than the server doesn’t start. Is this just unsupported in Phoenix?
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted”
Version...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 6 to 1- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
axelson
Hmm, that does seem like it would clean up a bunch. Especially my crazy error checking pattern match. I’ll ty it out
idi527
You can probably also use
:gen_tcp.listen/2to check if the port is taken, and only after that start the phoenix app. It would probably simplify the logic a bit (no need for dynamic supervisors, just a function that runs before the application starts).axelson
Ah that is interesting, didn’t know about that option. But for this case I’d prefer to know what ports the server would possibly be running on.
idi527
Might be not what you want, but just in case, you can try setting the port to
0in your config, then cowboy would ask ranch would ask gen tcp would ask OS for a random available port (gen_tcp — OTP 29.0.2 (kernel 11.0.2)).You can then fetch the port by using something like
:ranch.get_port(YourAppWeb.Endpoint.HTTP). If you are not sure what module name plug decided to use for you cowboy server, try runing:ets.i(:ranch_server)in iex.axelson
Okay, here is what I ended up with:
Instead of adding
MyApp.Endpointdirectly to my supervision tree I am adding thisLsppWeb.PhoenixPortSupervisorthat usesDynamicSupervisorto start up my Phoenix Endpoint, incrementing the port if it fails to startup initially.Then in
LsppWeb.EndpointI define aninit/2callback:Any feedback or critique is welcome. The ugliest part of the code right now is how I shuttle the new port through the application environment. I suppose since
LsppWeb.PhoenixPortSupervisoris aGenServermaybe that could be handled with aGenServer.call, but then I would need anotherGenServer/process since currentlyLsppWeb.PhoenixPortSupervisordoesn’t finish it’s startup until myLsppWeb.Endpointhas finished.axelson
It looks like I’ll have to use the
init/2callback on an Endpoint: Phoenix.Endpoint — Phoenix v1.8.8Although I’m not sure how I’ll handle the restart and increment logic with that yet