Simple docker container project to handle many python scripts running in the background and monitor them using the supervisord web interface.
- Build a docker image
docker build -t supervisor .
- Run the container
docker run -dp 9001:9001 --name supervisor supervisor
- Now you can go to http://localhost:9001 in your browser and log in using the data from the supervisord.conf file
The supervisor configuration can be found in the supervisord.conf file.
To add a new script for monitoring, add at the end of the document:
[program:script]
command=python /app/script.py
stdout_logfile=/var/log/supervisor/%(program_name)s.log
To save script logs that will be available from the web interface, import the get_logger variable from the logger.py file and use it to create a Logger object.
import time
from logger import get_logger
if __name__ == '__main__':
logger = get_logger()
try:
logger.info('Custom service started')
while True:
time.sleep(2)
finally:
logger.info('Custom service stopped')