Skip to content

Commit

Permalink
Merge pull request #74 from bebehei/signal-handling
Browse files Browse the repository at this point in the history
use correct signal-handler for supervisord
  • Loading branch information
jjethwa authored Feb 1, 2017
2 parents 70edab1 + 5c186ee commit ad6543a
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 58 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
9 changes: 9 additions & 0 deletions content/etc/supervisor/conf.d/apache2.conf
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions content/etc/supervisor/conf.d/fatalservicelistener.conf
Original file line number Diff line number Diff line change
@@ -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
33 changes: 7 additions & 26 deletions content/etc/supervisor/conf.d/icinga2.conf
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions content/etc/supervisor/conf.d/mysql.conf
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion content/opt/run
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 2 additions & 11 deletions content/opt/supervisor/apache2_supervisor
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions content/opt/supervisor/fatalservicelistener
Original file line number Diff line number Diff line change
@@ -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
12 changes: 2 additions & 10 deletions content/opt/supervisor/icinga2_supervisor
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
12 changes: 2 additions & 10 deletions content/opt/supervisor/mysql_supervisor
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ad6543a

Please sign in to comment.