Graceful autostop and autostart?

I am interested in using the auto stop/start feature with my node app, but at the moment my app never recovers from autostop. I assume that the startup scripts could be used to gracefully autostart? And that by tinkering with the runtime options the app could gracefully autostop?

Still, are there any guides or advice about how to implement the graceful autostop? I have scripts for both starting and stopping the app, but I am wondering how exactly to trigger the stop.


Here’s what we do for a NodeJS app we run on Fly Machines:

  1. Def kill_signal in fly.toml to send a SIGINT on autostops.
  2. Set kill_timeout to 10s (this varies from app to app depending on how it chooses to handle the kill_signal).
  3. On SIGINT:
    • Clear and unref all timers.
    • Stop responding to incoming conns (set server.maxConnections to -1).
    • Shutdown and unref all lingering incoming connections.
    • Shutdown and unref all lingering outgoing connections.
    • Shutdown and unref servers.

Not the best code, but: serverless-dns/src/server-node.js at f9d4d71afd099505f1bc4f56f14efe2b7c207cc3 · serverless-dns/serverless-dns · GitHub

1 Like

Great, thank you @ignoramous!

For auto start did you just create a directory .fly/scripts and add a bash script? (fly launch did not create that directory or the Docker entrypoint, so I’m guessing that doc is somewhat outdated.)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.