Monit doesn't start again with a bash script after docker stop -


i have docker container uses monit start few services mongodb, nginx. have bash script used docker start monit. here contents of file:

#!/bin/bash  # monit start apps /usr/bin/monit -c /etc/monitrc &  # stay container stay alive while [ 1 ] ;   if !(pgrep monit)   /usr/bin/monit -c /etc/monitrc &   fi   sleep 5m done 

the problem when run docker create command create container, bash script runs , monit brings services, if stop container , start again, monit doesn't come or if come up, doesn't start services. verify whether bash script fine. used following reference https://blog.deimos.fr/2016/01/13/docker-why-you-should-use-monit-instead-of-supervisord/

to run multiple processes in container, use init system supports running in docker pid 1 s6 via s6-overlay or supervisord. adding custom scripts in between adds link in service chain , possibility of introducing issues system.

signals , docker

a docker stop sends sigterm signal container process, , after default of 10 seconds sends sigkill terminate container , running in it.

a process running under docker pid 1 needs handle signals want take action on, otherwise ignored. in case of service manager need pass sigterm onto managed services. note example scripts on the blog trap exit of script, in turn runs script stop monit services cleanly. exit includes sigterm.

in example script, processes running in container terminated sigkill after docker stop times out.

services , sigkill

i haven't used monit much, service manager expect able gracefully handle being killed sigkill (or kill -9) , come next time (possibly not though).

nginx survive sigkill doesn't actively store state on disk default.

mongodb need shutdown cleanly. sigkill leave database lock file in place requires manual cleanup.


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -