Qqwy
Is it possible to auto-restart a Phoenix server on config change (in development)?
For most changes made in your app’s files, Phoenix is able to reload individual modules while the app is kept running (using a combination of Phoenix.CodeReloader and Phoenix.LiveReloader).
However, if your config-files or mix.exs change, then this requires a manual restart.
This is of course completely reasonable: we might change what dependencies exist, what options are passed to the Elixir/Erlang compiler(s), etc.
However, it is very common to trigger this situation when e.g. switching between branches in git.
Thus my question: Is there a way to automate this full restart of the application?
Maybe by wrapping the call to mix run --no-halt or iex -S mix in some other command or shell-script?
Thank you for your help!
Most Liked
axelson
In the past I experimented with using :init.restart/0 by adding it to the Phoenix exception page that is displayed for those exceptions. It seemed to work pretty well but I never got around to making a PR for it.
stefanchrobot
To me it sounds like this is out of Phoenix’s scope of responsibilities. I think wrapping the command with a file watcher is the way to go. I personally use watchexec to format the code and run my tests (this could be tweaked, but I hope you get the idea):
watchexec -e 'ex,exs,eex,leex,lock' -- 'mix format & mix test --stale'
Seems this could do the job you need.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









