snipe-it/docker/supervisor-exit-event-listener
Wouter van Os 2c49c32e72 Fixed #10231: use correct python binary for exit listener
This fixes #10231, without creating an own Dockerfile.
2021-11-02 13:06:36 +01:00

20 lines
522 B
Python

#!/usr/bin/env python3
# A supervisor event listener which terminates supervisord if any of its child
# processes enter the FATAL state.
# https://stackoverflow.com/a/37527488/119527
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()