Skip to content

Instantly share code, notes, and snippets.

@tomazzaman
Last active April 19, 2024 17:01
Show Gist options
  • Star 22 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save tomazzaman/63265dfab3a9a61781993212fa1057cb to your computer and use it in GitHub Desktop.
Save tomazzaman/63265dfab3a9a61781993212fa1057cb to your computer and use it in GitHub Desktop.
Kill supervisor on Docker when any of the services fail

Killing supervisor if any of it's child processes fail

The trick is to only register the listener for events that indicate failure, namely

  • PROCESS_STATE_STOPPED
  • PROCESS_STATE_EXITED
  • PROCESS_STATE_FATAL

Once they do, we should send a SIGQUIT to Supervisor.

#!/bin/bash
printf "READY\n";
while read line; do
echo "Processing Event: $line" >&2;
kill -3 $(cat "/var/run/supervisord.pid")
done < /dev/stdin
[supervisord]
nodaemon=true
loglevel=debug
logfile=/var/log/supervisor/supervisord.log
pidfile=/var/run/supervisord.pid
childlogdir=/var/log/supervisor
[program:nginx]
command=nginx -g "daemon off;"
redirect_stderr=true
[program:php-fpm]
command=php-fpm
redirect_stderr=true
[eventlistener:processes]
command=stop-supervisor.sh
events=PROCESS_STATE_STOPPED, PROCESS_STATE_EXITED, PROCESS_STATE_FATAL
@MiguelSilvaViana
Copy link

I don't understand do I need to put this code inside the while loop?

echo "Processing Event: $line" >&2;
kill -3 $(cat "/var/run/supervisord.pid")

The browser needs nothing else and this will solve the memory error really, I believe it is necessary that the dead processes are killing the application when the browser consumes 1gb but just these two lines would already solve the problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment