TBK145

TBK145

Signal or hook at the end of starting a release

Hi everyone,

A while ago we had an issue with one of our production systems where the application was stuck in some kind of startup process. This meant some processes were started and others not. Our monitoring didn’t fully pick this up. So now we’re looking for a way that we know that a release is fully started.

We’re using mix release to build the packages and deploy them on servers where they’re managed by systemd.

Initially I looked at the BEAM, and did find :init.get_status/0. So I was thinking to use an rpc to check that in intervals, but I’d rather have something nicer.

Someone in the Elixir slack channel shared erlang-systemd with me. This looks really promising, but we’re using a umbrella application, and make multiple different releases with different sub-applications. So this makes it a bit hard to determine in which application Supervisor to put the ready signal. A solution to this would be to create a new application that just does this ready signal and make sure to include that application as the last started application of each different release. But that seems like a lot of overhead to me.

Ideally what I think I’m looking for is some kind of option on the boot script or the BEAM to call some kind of (systemd?) hook or a signal that is broadcasted when startup is completely done.

I’m interested in hearing more options or opinions on this!

Most Liked

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

This is pretty close to the K8s approach of liveliness vs readiness. When our app boots we have the Phoenix Endpoint child very early in the tree, but then we have two distinct health checks, /alive and /ready which maps to this code:

  def alive(conn, _params) do
    json(conn, %{alive: true})
  end

  def ready(conn, _params) do
    if Application.get_env(:my_app, :ready) do
      json(conn, %{ready: true})
    else
      send_resp(conn, 503, "")
    end
  end

The default value of ready is false in our config. Then at the bottom of our supervision tree we have a simple genserver which sets Application.put_env(:my_app, :ready, true), and also can message out somewhere if you want it to.

So at that point once that child runs GET /ready returns 200, and you know your app is fully booted. If you want that pushed somewhere then your genserver can do so. Handily if you trap exits this also gives you a nice flow on node shutdown, because that same genserver is now the first child to shutdown, so you can set /ready 503 and again notify out if you want.

Where Next?

Popular in Questions Top

Tee
can someone please explain to me how Enum.reduce works with maps
New
mgjohns61585
Could someone help me? I’m making my first elixir program, number guessing game. I can’t figure out how to convert the user’s guess from ...
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
vac
Hi, I’m quite new in Elixir and I’m trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and I...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: The documentation above suggests that while ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New

Other popular topics Top

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29603 241
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement