thbar
I’ve got a number of apps (e.g. Phoenix, but also pure Plug + Cowboy) where 1/ hot-reload cannot be easily used and 2/ the app runs on a single server.
The restart period can be a bit slow (and some apps are behind nginx too), which leads to a period during which the requests are refused (bad gateway etc).
I’m looking at ways to reduce that downtime.
Did anyone managed to use systemd “socket activation” together with either Phoenix or even Cowboy/Ranch directly?
For some context, here is how you can achieve that with Go:
or even with Python:
It could quite improve the deploy workflow of single-server setups.
If you have any information, let me know!
Thanks!
– Thibaut
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
idi527
It’s possible to pass
fdoption to:gen_tcp.listen: gen_tcp — OTP 29.0.2 (kernel 11.0.2). So something likemight work.
So working from bottom up,
:gen_tcp’sfdoption would probably make it workranchaccepts socket options via:socket_optspluguses:transport_optionsto configure that part of:ranchphoenixuses:httpoption to configure that part of plugthbar
This looks like a solid start - I will experiment, many thanks!
tristan
Very interested in hearing if you get it working. I tried once briefly and failed to get it to work.
I tried with
{fd, 3}as an option togen_tcp:listen.I’ll have to dig it back up to try again and see where it went wrong, I remember it was a hassle to get the systemd service and socket working properly to even test the Erlang code and that is likely the reason it didn’t work, and not an issue with Erlang.
I know @garazdawi said he was interested as well.
thbar
I will experiment the coming week, on a client setup for which I need to do maintenance (Ansible + Elixir). Will report back with my findings!
amarraja
I can’t help with the socket activation stuff, however I have been using a docker solution for zero downtime deploys, and it has been working great for me.
In a nutshell, it uses docker swarm which will start a new instance of the app, wait for it to become ready, move traffic over, and finally remove the old one. It’s surprisingly simple and works great on single server setups.
I can write up more details if people are interested.
thbar
While I won’t be able to use that technique on the projects I’m managing at the moment, I’d say it’s interesting to share anyway (if that’s not too much work on your side!).
thbar
An update on this: so far I’m not able to start the app, but here are bits of feedback in case someone else also tackles this (I will get back to this later).
I’ve created a file under
/etc/systemd/system/my_app.socket, with content:The documentation for
ListenStreametc is at Ubuntu Manpage: systemd.socket - Socket unit configuration.After a restart with
reload systemctl_daemon, I can see an active unit for the socket withsudo systemctl status my_app.socket.I’ve also modified my app service file under
/etc/systemd/system/my_app.service, with (extract, cannot share in full):I’ve (trial and error) updated the
prod.exsconfiguration used to build my releases (via Distillery) with:Ultimately though, my logs show the following error:
This is already progress, because I had a lot of other errors before earlier, but at this point I must dive deeper into Ranch to figure out what is happening.
tristan
I’d suggest starting with just a
gen_tcpmodule and not involve ranch or anything else.idi527
Getting the same error
{:error, :einval}with:gen_tcp.listen(5000, fd: 3)and the following systemd units:Just in case, here’s the env vars set for the service
the relevant ones are probably:
Can connect to it so it works …
But cannot listen
tristan
Yea, I think that is what I got when I tried as well and never had the time to debug further.