I wrote this patch , included in snap-server
0.9 and above, using which you can write:
let hook dat = print $ socketPort $ head $ getStartupSockets dat let config = setStartupHook hook $ setPort 0 mempty httpServer config ...
Now the hook
will be called after the server is ready, and will print the port on which it was launched.
source share