#!/bin/bash NODES=${NODES:-} SNMP_NODES=${SNMP_NODES:-} MUNIN_USER=${MUNIN_USER:-user} MUNIN_PASSWORD=${MUNIN_PASSWORD:-password} MAIL_CONF_PATH='/var/lib/munin/.mailrc' SMTP_USE_TLS=false SMTP_ALWAYS_SEND=true truncate -s 0 "${MAIL_CONF_PATH}" if [ "${SMTP_USE_TLS}" = true ] ; then cat >> "${MAIL_CONF_PATH}" <> "${MAIL_CONF_PATH}" <> "${MAIL_CONF_PATH}" < ${var:graph_title} -> warnings: ${loop<,>:wfields ${var:label}=${var:value}} / criticals: ${loop<,>:cfields ${var:label}=${var:value}}"' ${ALERT_RECIPIENT} >> /etc/munin/munin.conf if [ "${SMTP_ALWAYS_SEND}" = true ] ; then echo 'contact.mail.always_send warning critical' >> /etc/munin/munin.conf fi fi [ -e /etc/munin/htpasswd.users ] || htpasswd -b -c /etc/munin/htpasswd.users "$MUNIN_USER" "$MUNIN_PASSWORD" # generate node list for NODE in $NODES do NAME=`echo $NODE | cut -d ":" -f1` HOST=`echo $NODE | cut -d ":" -f2` PORT=`echo $NODE | cut -d ":" -f3` if [ ${#PORT} -eq 0 ]; then PORT=4949 fi if ! grep -q $HOST /etc/munin/munin.conf ; then cat << EOF >> /etc/munin/munin.conf [$NAME] address $HOST use_node_name yes port $PORT EOF fi done # generate node list for NODE in $SNMP_NODES do NAME=`echo $NODE | cut -d ":" -f1` HOST=`echo $NODE | cut -d ":" -f2` PORT=`echo $NODE | cut -d ":" -f3` if [ ${#PORT} -eq 0 ]; then PORT=4949 fi if ! grep -q $HOST /etc/munin/munin.conf ; then cat << EOF >> /etc/munin/munin.conf [$NAME] address $HOST use_node_name no port $PORT EOF fi done [ -d /var/cache/munin/www ] || mkdir /var/cache/munin/www # placeholder html to prevent permission error if [ ! -e /var/cache/munin/www/index.html ]; then cat << EOF > /var/cache/munin/www/index.html Munin Munin has not run yet. Please try again in a few moments. EOF chown munin:munin -R /var/cache/munin/www chmod g+w /var/cache/munin/www/index.html fi # start rsyslogd /usr/sbin/rsyslogd # start cron /usr/sbin/cron # start local munin-node /usr/sbin/munin-node echo "Using the following munin nodes:" echo $NODES # start nginx /usr/sbin/nginx # show logs echo "Tailing /var/log/syslog..." tail -F /var/log/syslog /var/log/munin/munin-update.log & pid=$! echo "tail -F running in $pid" sleep 1 trap "echo 'stopping processes' ; kill $pid $(cat /var/run/munin/munin-node.pid) $(cat /var/run/nginx.pid) $(cat /var/run/crond.pid) $(cat /var/run/rsyslogd.pid)" SIGTERM SIGINT echo "Waiting for signal SIGINT/SIGTERM" wait