diff --git a/README.md b/README.md index c49fba4..b205f4c 100644 --- a/README.md +++ b/README.md @@ -154,5 +154,6 @@ All these folders are configured and able to get mounted as volume. The bottom o | /var/log/icinga2 | rw | logfolder for icinga2 (not neccessary) | | /var/log/icingaweb2 | rw | logfolder for icingaweb2 (not neccessary) | | /var/log/mysql | rw | logfolder for mysql (not neccessary) | +| /var/log/supervisor | rw | logfolder for supervisord (not neccessary) | | /var/spool/icinga2 | rw | spool-folder for icinga2 (not neccessary) | | /var/cache/icinga2 | rw | cache-folder for icinga2 (not neccessary) | diff --git a/content/etc/supervisor/conf.d/apache2.conf b/content/etc/supervisor/conf.d/apache2.conf new file mode 100644 index 0000000..ae47f01 --- /dev/null +++ b/content/etc/supervisor/conf.d/apache2.conf @@ -0,0 +1,9 @@ +[program:apache2] +command=/opt/supervisor/apache2_supervisor +autorestart=true +startretries=3 +# redirect output to stdout/stderr and do not use a regular logfile +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 diff --git a/content/etc/supervisor/conf.d/fatalservicelistener.conf b/content/etc/supervisor/conf.d/fatalservicelistener.conf new file mode 100644 index 0000000..da3010d --- /dev/null +++ b/content/etc/supervisor/conf.d/fatalservicelistener.conf @@ -0,0 +1,8 @@ +[eventlistener:fatalservice] +command=/opt/supervisor/fatalservicelistener +events=PROCESS_STATE_FATAL +# redirect output to stdout/stderr and do not use a regular logfile +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 diff --git a/content/etc/supervisor/conf.d/icinga2.conf b/content/etc/supervisor/conf.d/icinga2.conf index e6eab67..65865b7 100644 --- a/content/etc/supervisor/conf.d/icinga2.conf +++ b/content/etc/supervisor/conf.d/icinga2.conf @@ -1,28 +1,9 @@ -[unix_http_server] -file=/var/run/supervisor.sock -chmod=0700 - -[supervisord] -nodaemon=true -logfile=/tmp/supervisord.log -logfile_maxbytes=50MB -pidfile=/tmp/supervisord.pid - -[rpcinterface:supervisor] -supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface - -[supervisorctl] -serverurl=unix:///var/run/supervisor.sock - -[program:apache2] -command=/bin/bash -c "/opt/supervisor/apache2_supervisor" -redirect_stderr=true - -[program:mysql] -command=/bin/bash -c "/opt/supervisor/mysql_supervisor" -redirect_stderr=true - [program:icinga2] -command=/bin/bash -c "/opt/supervisor/icinga2_supervisor" -redirect_stderr=true +command=/opt/supervisor/icinga2_supervisor autorestart=true +startretries=3 +# redirect output to stdout/stderr and do not use a regular logfile +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 diff --git a/content/etc/supervisor/conf.d/mysql.conf b/content/etc/supervisor/conf.d/mysql.conf new file mode 100644 index 0000000..15309a0 --- /dev/null +++ b/content/etc/supervisor/conf.d/mysql.conf @@ -0,0 +1,9 @@ +[program:mysql] +command=/opt/supervisor/mysql_supervisor +autorestart=true +startretries=3 +# redirect output to stdout/stderr and do not use a regular logfile +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 diff --git a/content/opt/run b/content/opt/run index d61737b..2717dd3 100755 --- a/content/opt/run +++ b/content/opt/run @@ -48,4 +48,6 @@ Icinga Web 2 (/icingaweb2) default credentials: ${ICINGAWEB2_ADMIN_USER}:${ICING Starting Supervisor. END -/usr/bin/supervisord -c /etc/supervisor/conf.d/icinga2.conf > /dev/null +/usr/bin/supervisord -n & +trap "supervisorctl shutdown && wait" SIGTERM +wait diff --git a/content/opt/supervisor/apache2_supervisor b/content/opt/supervisor/apache2_supervisor index 7e1dc05..03dd0a8 100755 --- a/content/opt/supervisor/apache2_supervisor +++ b/content/opt/supervisor/apache2_supervisor @@ -1,17 +1,8 @@ #!/bin/bash -function shutdown() -{ - echo "`date +"%d.%m.%Y %T.%3N"` - Shutting down apache2" - /etc/init.d/apache2 stop -} - - -echo "`date +"%d.%m.%Y %T.%3N"` - Starting apache2" - -/etc/init.d/apache2 start +service apache2 start # Allow any signal which would kill a process to stop server -trap shutdown HUP INT QUIT ABRT KILL ALRM TERM TSTP +trap "service apache2 stop" HUP INT QUIT ABRT KILL ALRM TERM TSTP while pgrep -u www-data apache2 > /dev/null; do sleep 5; done diff --git a/content/opt/supervisor/fatalservicelistener b/content/opt/supervisor/fatalservicelistener new file mode 100755 index 0000000..83cc86f --- /dev/null +++ b/content/opt/supervisor/fatalservicelistener @@ -0,0 +1,14 @@ +#!/bin/bash + +# eventlistener to shutdown on first service event +# configured on events PROCESS_STATE_FATAL, it shuts down +# on first failing service. Useful for docker-containers + +# Report readiness to supervisord +echo READY + +# Wait for first input (first fatal event) +read line + +# and finally shutdown +supervisorctl shutdown diff --git a/content/opt/supervisor/icinga2_supervisor b/content/opt/supervisor/icinga2_supervisor index 4c99d61..fffd775 100755 --- a/content/opt/supervisor/icinga2_supervisor +++ b/content/opt/supervisor/icinga2_supervisor @@ -1,14 +1,6 @@ #!/bin/bash -function shutdown() -{ - echo "`date +"%d.%m.%Y %T.%3N"` - Shutting down icinga2" - /etc/init.d/icinga2 stop -} - -echo "`date +"%d.%m.%Y %T.%3N"` - Starting icinga2" - -/etc/init.d/icinga2 start +service icinga2 start # Kickstart is only possible after icinga2 start -> not in setup script if [ "${ICINGA2_FEATURE_DIRECTOR}" == "true" ] || [ "${ICINGA2_FEATURE_DIRECTOR}" == "1" ]; then @@ -18,6 +10,6 @@ if [ "${ICINGA2_FEATURE_DIRECTOR}" == "true" ] || [ "${ICINGA2_FEATURE_DIRECTOR} fi # Allow any signal which would kill a process to stop server -trap shutdown HUP INT QUIT ABRT KILL ALRM TERM TSTP +trap "service icinga2 stop" HUP INT QUIT ABRT KILL ALRM TERM TSTP while pgrep -u nagios icinga2 > /dev/null; do sleep 5; done diff --git a/content/opt/supervisor/mysql_supervisor b/content/opt/supervisor/mysql_supervisor index a80af32..b20aa6c 100755 --- a/content/opt/supervisor/mysql_supervisor +++ b/content/opt/supervisor/mysql_supervisor @@ -1,16 +1,8 @@ #!/bin/bash -function shutdown() -{ - echo "`date +"%d.%m.%Y %T.%3N"` - Shutting down mysql" - /etc/init.d/mysql stop -} - -echo "`date +"%d.%m.%Y %T.%3N"` - Starting mysql" - -/etc/init.d/mysql start +service mysql start # Allow any signal which would kill a process to stop server -trap shutdown HUP INT QUIT ABRT KILL ALRM TERM TSTP +trap "service mysql stop" HUP INT QUIT ABRT KILL ALRM TERM TSTP while pgrep -u mysql mysql > /dev/null; do sleep 5; done