I was able to do easily that when running on a TCP
port by finding the PID
by the TCP
port. However, how to find the PID
of mix phx.server
when running upon a UNIX socket
. I need the PID
to be able to restart the server.
Here is the simplest solution as proposed by @josevalim:
elixir --detached -e "File.write! 'pid', :os.getpid" -S mix phx.server && cat pid
2 Likes
I’d prefer to write the PID file from the application start, rather then doing it in this shell start wrapper, which might append arbitrary log output to the PID file if console logging is enabled or even worse if there are still calls to IO.puts
and IO.inspect
, then their output will end up in the PID file as well…
Alternatively if one didn’t want to, or isn’t able to, then shell capabilities should be used:
app start &
echo $! > /run/app.pid
1 Like
Even simpler by:
lsof /path/to/socket/phx_prod.socket | awk 'NR > 1 {print $2}'
2 Likes