Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Supervisor & Docker: How to exit Supervisor if a service doesn't start?

I'm currently using Supervisor inside my Docker images to start and manage my services and I would like to configure Supervisor to exit if at least one of these services entered FATAL state.

Doing that, I want to avoid to have Docker containers in running state when nothing except Supervisor has succeeded to start.

like image 598
Brice Argenson Avatar asked Jan 27 '15 16:01

Brice Argenson


People also ask

What is the role of a supervisor?

The supervisor's overall role is to communicate organizational needs, oversee employees' performance, provide guidance, support, identify development needs, and manage the reciprocal relationship between staff and the organization so that each is successful.

Does supervisor mean boss?

What is a boss? A boss, or more formally addressed as a manager, team leader or supervisor, is someone who oversees employees of a company or organization. Their job is to make important decisions and to ensure tasks are completed and the company is meeting its goals.

What are the 5 role of supervisor?

The five key supervisory roles include Educator, Sponsor, Coach, Counselor, and Director. Each is described below. Note that in your role as a supervisor, you will be using these five roles, in some combination, simultaneously, depending on the needs of the team members.

What does it mean being a supervisor?

Supervisor definition The definition of a supervisor is a person who is in charge of overseeing and directing a project or people. The boss in charge at work who hands out assignments is an example of a supervisor. noun. 5.


2 Answers

As mhsmith mentioned, an event listener is the best way to achieve this. You could use the following listener (ADD this as e.g. /usr/local/bin/exit-event-listener):

#!/usr/bin/env python
import os
import signal

from supervisor import childutils

def main():
    while True:
        headers, payload = childutils.listener.wait()
        childutils.listener.ok()
        if headers['eventname'] != 'PROCESS_STATE_FATAL':
            continue
        os.kill(os.getppid(), signal.SIGTERM)

if __name__ == "__main__":
    main()

And then, register it with supervisor:

[eventlistener:exit_on_any_fatal]
command=exit-event-listener
events=PROCESS_STATE_FATAL
like image 125
Thomas Orozco Avatar answered Nov 15 '22 09:11

Thomas Orozco


You can do this with a Supervisor event listener. Subscribe it to the event PROCESS_STATE_FATAL, and respond to the event by sending a SIGTERM to supervisord, which you are presumably running as PID 1 within the container.

like image 32
mhsmith Avatar answered Nov 15 '22 08:11

mhsmith