In my startup script I have this line:
PORT=xxxx MIX_ENV=prod elixir --erl “-detached” -S mix phx.server
This starts up the Phoenix Server in detached mode, I cant find anywhere online how I would ‘re-attach’ to the server to run commands, if somebody could direct me to some documentation for it, or show me how it would be much appreciated.
Why you start it in detached mode in the first place? Assuming it is for production:
- Why you do not use release?
- Why you do not use system supervisor to start and manage the daemon?
2 Likes
It means using systemd scripts (or similar) to start your release.
If it is just for test, I would use…
MIX_ENV=prod iex -S mix phx.server
… so that I can control the server from the console.
Ah yes, I use that but I turn off my laptop overnight therefore the shell process that it is running in gets cancelled.
Taking down the server.
nohup MIX_ENV=prod iex -S mix phx.server &
I think it can help you. But making a release is very easy and very rewarding for your use case.
https://hexdocs.pm/mix/main/Mix.Tasks.Release.html
Yeah I may just have to take the plunge and do proper releases if I can’t find a way to reconnect to a running detached server.
Instead of detaching use TMux/Screen/dtach and then just connect to session when you want to use that node.