How to find the PID of the Phoenix process when running the server using UNIX socket

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.

Hi @acrolink, maybe this could help you?


Here is the simplest solution as proposed by @josevalim:

elixir --detached -e "File.write! 'pid', :os.getpid" -S mix phx.server && cat pid

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/
1 Like

Even simpler by:

lsof /path/to/socket/phx_prod.socket | awk 'NR > 1 {print $2}'