Putting a deployed phoenix application in maintenance mode?

What are people doing with regards to putting their Phoenix applications into maintenance mode when they need to make changes, or because a backend service is down?

Some sort of proxy ‘switch’ - ie nginx
A command that somehow switches it off?
Seperate storage that is queried each request? (redis, sqlite etc)

I’d suggest handling that in a layer above phoenix. A.k.a. any reverse proxy or loadbalancer you might have. If you don’t have both of those you probably don’t run a distributed setup, where a simple plug and a GenServer holding the state would probably be enough to limit access in the endpoint.

1 Like

I handle this at the reverse proxy by forwarding all requests to a static HTML site. With NGINX, I put my production config in /etc/nginx/conf.d/my-application.conf and the maintenance config into /etc/nginx/conf.d/my-application.maintenance.conf.off: NGINX will ignore this file because it doesn’t end with conf. To activate the maintenance mode, just rename the two files:

mv -n /etc/nginx/conf.d/my-application.conf{,.off}
mv -n /etc/nginx/conf.d/my-application.maintenance.conf{.off,}
systemctl restart nginx

the maintenance mode config looks somewhat like this:

server {
    server_name my-application.my-company.org;

    location / {
        expires -1;
        add_header 'Cache-Control' 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
        add_header Last-Modified $date_gmt;
        if_modified_since off;
        etag off;
        root /var/www/maintenance;

    error_page 404 /;

    listen [::]:443 ssl;
    listen 443 ssl;

    # Not included: SSL settings and certificate paths.

And /var/www/maintenance includes an index.html that basically just says “under maintenance, try again later.”


Cool thanks, I figured it would probably be at the proxy layer, but wondered if I had missed something that was built in, or the ‘phoenix norm’. :slight_smile: