containerized-monitoring/root/etc/s6-overlay/s6-rc.d/setup/setup

302 lines
8.3 KiB
Plaintext
Executable file

#!/command/with-contenv bash
####################
# Email notifications
####################
echo "---------- Setting up email notifications (msmtp-mta) ----------"
if [ ! -d "/opt/misc" ] ; then
mkdir /opt/misc
fi
if [ ! -f "/opt/misc/msmtp.log" ] ; then
touch /opt/misc/msmtp.log
chown root: /opt/misc/msmtp.log
chmod 666 /opt/misc/msmtp.log
fi
if [ ! -f "/opt/misc/aliases" ] ; then
cat > /opt/misc/aliases <<EOF
root: $CONFIG_NOTIFY_EMAIL
cron: $CONFIG_NOTIFY_EMAIL
default: $CONFIG_NOTIFY_EMAIL
EOF
fi
if [ ! -f "/opt/misc/msmtprc" ] ; then
cat > /opt/misc/msmtprc <<EOF
# Accounts will inherit settings from this section
defaults
auth on
tls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
logfile /opt/misc/msmtp.log
from $CONFIG_NOTIFY_SMTP_USER
keepbcc on
account containermonitoring
host $CONFIG_NOTIFY_SMTP_SERVER
port 587
auth on
user $CONFIG_NOTIFY_SMTP_USER
password $CONFIG_NOTIFY_SMTP_PASS
# Set a default account
account default : containermonitoring
aliases /etc/aliases
EOF
fi
ln -sf /opt/misc/aliases /etc/aliases
ln -sf /opt/misc/msmtprc /etc/msmtprc
####################
# Monit
####################
echo "---------- Setting up monit ----------"
if [ ! -d "/opt/monit/conf.d" ] ; then
mkdir /opt/monit/conf.d
fi
if [ ! -f "/opt/monit/monitrc" ] ; then
cat > /opt/monit/monitrc <<EOF
set daemon 120
set log /opt/monit/monit.log
set idfile /opt/monit/id
set statefile /opt/monit/state
set eventqueue
basedir /opt/monit/events # set the base directory where events will be stored
slots 100 # optionally limit the queue size
set httpd port 2812 and
use address 0.0.0.0
allow ${CONFIG_MONIT_USER}:${CONFIG_MONIT_PASS}
include /opt/monit/conf.d/*
EOF
chmod 600 /opt/monit/monitrc
fi
####################
# Munin
####################
echo "---------- Setting up munin config ----------"
if [ ! -d "/opt/munin" ] ; then
mkdir /opt/munin
fi
if [ ! -f "/opt/munin/munin.conf" ] ; then
cat > /opt/munin/munin.conf <<EOF
dbdir /opt/munin/db
htmldir /opt/munin/www
logdir /opt/munin/log
rundir /opt/munin/run
cgitmpdir /opt/munin/cgi-tmp
graph_strategy cgi
html_strategy cgi
timeout 15
[munin.local]
address 127.0.0.1
use_node_name yes
EOF
fi
if [ ! -f "/opt/munin/munin-node.conf" ] ; then
cat > /opt/munin/munin-node.conf <<EOF
log_level 4
log_file /opt/munin/log/munin-node.log
pid_file /opt/munin/munin-node.pid
background 0
setsid 0
user munin
group munin
# Regexps for files to ignore
ignore_file [\#~]\$
ignore_file DEADJOE\$
ignore_file \.bak\$
ignore_file %\$
ignore_file \.dpkg-(tmp|new|old|dist)\$
ignore_file \.rpm(save|new)\$
ignore_file \.pod\$
allow ^127\.0\.0\.1\$
allow ^::1\$
host 127.0.0.1
port 4949
EOF
fi
rm /etc/munin/munin-node.conf
ln -sf /opt/munin/munin-node.conf /etc/munin/munin-node.conf
rm /etc/munin/munin.conf
ln -sf /opt/munin/munin.conf /etc/munin/munin.conf
echo "---------- Setting up munin directories ---------"
if [ ! -d "/opt/munin/log" ] ; then
mkdir /opt/munin/log
fi
chown munin: /opt/munin/log
if [ ! -d "/opt/munin/run" ] ; then
mkdir /opt/munin/run
fi
chown munin: /opt/munin/run
if [ ! -d "/opt/munin/db" ] ; then
mkdir /opt/munin/db
fi
chown munin: /opt/munin/db
if [ ! -d "/opt/munin/www" ] ; then
mkdir /opt/munin/www
fi
chown munin: /opt/munin/www
if [ ! -d "/opt/munin/cgi-tmp" ] ; then
mkdir /opt/munin/cgi-tmp
fi
chown munin: /opt/munin/cgi-tmp
if [ ! -f "/opt/munin/log/munin-update.log" ] ; then
touch /opt/munin/log/munin-update.log
chown munin: /opt/munin/log/munin-update.log
fi
echo "---------- Setting up lighttpd munin config ----------"
if [ ! -d "/var/run/lighttpd" ] ; then
mkdir /var/run/lighttpd
fi
chown munin: /var/run/lighttpd
if [ ! -f "/opt/munin/lighttpd-munin.conf" ] ; then
cat > /opt/munin/lighttpd-munin.conf <<EOF
server.errorlog = "/dev/stdout"
accesslog.filename = "/dev/stdout"
dir-listing.activate = "disable"
server.follow-symlink = "enable"
server.modules = (
"mod_auth",
"mod_authn_file",
"mod_access",
"mod_accesslog",
"mod_alias",
"mod_rewrite",
"mod_redirect",
"mod_cgi",
"mod_fastcgi",
)
mimetype.assign = (
".html" => "text/html",
".txt" => "text/plain",
".css" => "text/css",
".js" => "application/x-javascript",
".jpg" => "image/jpeg",
".jpeg" => "image/jpeg",
".gif" => "image/gif",
".png" => "image/png",
"" => "application/octet-stream"
)
index-file.names = ( "index.html", "index.htm" )
server.pid-file = "/run/lighttpd-munin.pid"
server.username = "munin"
server.groupname = "munin"
server.document-root = "/opt/munin/www"
server.port = 2813
url.redirect += ( "^/$" => "/munin/index.html" )
url.redirect += ( "^/munin$" => "/munin/index.html" )
url.redirect += ( "^/munin/$" => "/munin/index.html" )
alias.url += ( "/munin/static" => "/opt/munin/www/static" )
alias.url += ( "/munin" => "/opt/munin/www" )
fastcgi.server += (
"/munin-cgi/munin-cgi-graph" =>
(( "socket" => "/var/run/lighttpd/munin-cgi-graph.sock",
"bin-path" => "/usr/lib/munin/cgi/munin-cgi-graph",
"check-local" => "disable",
)),
"/munin-cgi/munin-cgi-html" =>
(( "socket" => "/var/run/lighttpd/munin-cgi-html.sock",
"bin-path" => "/usr/lib/munin/cgi/munin-cgi-html",
"check-local" => "disable",
))
)
\$HTTP["url"] !~ "/static/.*$" {
\$HTTP["url"] !~ "/munin-cgi/.*$" {
url.rewrite-once += (
"/munin/(.*\.html)" => "/munin-cgi/munin-cgi-html/\$1",
"/munin-cgi/munin-cgi-html$" => "/munin-cgi/munin-cgi-html/",
)
}
}
EOF
fi
echo "---------- Munin node setup ----------"
rm /etc/munin/plugin-conf.d/*
munin-node-configure --shell --remove-also --debug | sh -x
#su - munin --shell=/bin/sh /usr/bin/munin-cron
####################
# Dashboard
####################
echo "---------- Setting up dashboard ----------"
if [ ! -d "/opt/dashboard" ] ; then
mkdir /opt/dashboard
fi
if [ ! -f "/opt/dashboard/lighttpd.conf" ] ; then
cat > /opt/dashboard/lighttpd.conf <<EOF
server.username = "www-data"
server.groupname = "www-data"
server.document-root = "/opt/dashboard/www"
server.port = 80
server.errorlog = "/dev/stdout"
accesslog.filename = "/dev/stdout"
dir-listing.activate = "disable"
server.modules = (
"mod_access",
"mod_accesslog",
"mod_alias",
"mod_rewrite",
"mod_redirect",
"mod_cgi",
"mod_fastcgi",
"mod_auth",
"mod_authn_file",
)
server.pid-file = "/run/lighttpd.pid"
server.follow-symlink = "enable"
index-file.names = ( "index.html", "index.htm" )
mimetype.assign = (
".html" => "text/html",
".txt" => "text/plain",
".css" => "text/css",
".js" => "application/x-javascript",
".jpg" => "image/jpeg",
".jpeg" => "image/jpeg",
".gif" => "image/gif",
".png" => "image/png",
"" => "application/octet-stream"
)
EOF
fi
if [ ! -d "/opt/dashboard/www" ] ; then
mkdir /opt/dashboard/www
chown www-data /opt/dashboard/www
fi
if [ ! -f "/opt/dashboard/www/index.html" ] ; then
cat > /opt/dashboard/www/index.html <<EOF
<html>
<head>
<title>containerized-monitoring</title>
</head>
<body>
<p>This page uses javascript to avoid manual entry of an ip for the href tag. Ports for the service have been listed below in case you do not have a javascript enabled browser.</p>
<p><a href="#" onclick="javascript:window.location.port=2812">Monit Monitoring (port 2812)</a></p>
<p><a href="#" onclick="javascript:window.location.port=2813">Munin Monitoring (port 2813)</a></p>
</body>
</html>
EOF
chown www-data /opt/dashboard/www/index.html
fi