From 6a486b088b957a2af6d1dfeb692ecef6ec8c5e06 Mon Sep 17 00:00:00 2001 From: "Suren A. Chilingaryan" Date: Sat, 5 Oct 2019 09:07:54 +0200 Subject: Optimize dockerfile --- files/etc/munin/munin.conf | 20 ++++ files/etc/nginx/nginx.conf | 31 ++++++ files/etc/nginx/sites-enabled/munin | 29 ++++++ files/munin.sh | 164 +++++++++++++++++++++++++++++++ files/patches/munin-ds-datalock.patch | 11 +++ files/patches/munin-graph-logging.patch | 10 ++ files/patches/munin-update-logging.patch | 10 ++ munin.conf | 20 ---- nginx-munin | 29 ------ nginx.conf | 31 ------ patches/munin-ds-datalock.patch | 11 --- patches/munin-graph-logging.patch | 10 -- patches/munin-update-logging.patch | 10 -- start-munin.sh | 164 ------------------------------- 14 files changed, 275 insertions(+), 275 deletions(-) create mode 100644 files/etc/munin/munin.conf create mode 100644 files/etc/nginx/nginx.conf create mode 100644 files/etc/nginx/sites-enabled/munin create mode 100755 files/munin.sh create mode 100644 files/patches/munin-ds-datalock.patch create mode 100644 files/patches/munin-graph-logging.patch create mode 100644 files/patches/munin-update-logging.patch delete mode 100644 munin.conf delete mode 100644 nginx-munin delete mode 100644 nginx.conf delete mode 100644 patches/munin-ds-datalock.patch delete mode 100644 patches/munin-graph-logging.patch delete mode 100644 patches/munin-update-logging.patch delete mode 100755 start-munin.sh diff --git a/files/etc/munin/munin.conf b/files/etc/munin/munin.conf new file mode 100644 index 0000000..aa3e550 --- /dev/null +++ b/files/etc/munin/munin.conf @@ -0,0 +1,20 @@ +dbdir /munin/db +rundir /tmp +htmldir /munin/www +logdir /munin/log + +includedir /etc/munin/munin-conf.d +tmpldir /etc/munin/templates +staticdir /etc/munin/static + +# strategies cron|cgi +html_strategy cgi +graph_strategy cgi +cgiurl_graph /munin-cgi/munin-cgi-graph + +#max_size_x 4000 +#max_size_y 4000 +#max_processes 16 +#munin_cgi_graph_jobs 6 +#graph_period second +#rrdcached_socket /var/run/rrdcached.sock diff --git a/files/etc/nginx/nginx.conf b/files/etc/nginx/nginx.conf new file mode 100644 index 0000000..1634164 --- /dev/null +++ b/files/etc/nginx/nginx.conf @@ -0,0 +1,31 @@ +worker_processes 4; +pid /tmp/nginx.pid; +error_log /proc/self/fd/2 warn; + +events { + worker_connections 768; + # multi_accept on; +} + +http { + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 65; + types_hash_max_size 2048; + + include /etc/nginx/mime.types; + default_type application/octet-stream; + + #client_body_temp_path /tmp/nginx/temp; + #proxy_temp_path /tmp/nginx/proxy; + + access_log /proc/self/fd/1; + error_log /proc/self/fd/2; + + gzip on; + gzip_disable "msie6"; + + include /etc/nginx/conf.d/*.conf; + include /etc/nginx/sites-enabled/*; +} diff --git a/files/etc/nginx/sites-enabled/munin b/files/etc/nginx/sites-enabled/munin new file mode 100644 index 0000000..4dc9764 --- /dev/null +++ b/files/etc/nginx/sites-enabled/munin @@ -0,0 +1,29 @@ +server { + listen 8080 default_server; + server_name munin; + + access_log /proc/self/fd/1; + error_log /proc/self/fd/2; + + location /munin/static { + alias /etc/munin/static; + } + + location ^~ /munin/ { + fastcgi_split_path_info ^(/munin)(.*); + fastcgi_param PATH_INFO $fastcgi_path_info; + fastcgi_pass 127.0.0.1:9001; + include fastcgi_params; + } + + location ^~ /munin-cgi/munin-cgi-graph/ { + fastcgi_split_path_info ^(/munin-cgi/munin-cgi-graph)(.*); + fastcgi_param PATH_INFO $fastcgi_path_info; + fastcgi_pass 127.0.0.1:9000; + include fastcgi_params; + } + + location / { + rewrite ^/$ munin/ redirect; break; + } +} diff --git a/files/munin.sh b/files/munin.sh new file mode 100755 index 0000000..63f5732 --- /dev/null +++ b/files/munin.sh @@ -0,0 +1,164 @@ +#!/bin/bash + +NODES=${NODES:-} +SNMP_NODES=${SNMP_NODES:-} +SSH_NODES=${SSH_NODES:-} +MUNIN_USERS=${MUNIN_USERS:-${MUNIN_USER:-user}} +MUNIN_PASSWORDS=${MUNIN_PASSWORDS:-${MUNIN_PASSWORD:-password}} +MAIL_CONF_PATH='/munin/db/.mailrc' +SMTP_USE_TLS=${SMTP_USE_TLS:-false} +SMTP_ALWAYS_SEND=${SMTP_ALWAYS_SEND:-true} +SMTP_MESSAGE_DEFAULT='[${var:group};${var:host}] -> ${var:graph_title} -> warnings: ${loop<,>:wfields ${var:label}=${var:value}} / criticals: ${loop<,>:cfields ${var:label}=${var:value}}' +SMTP_MESSAGE="${SMTP_MESSAGE:-$SMTP_MESSAGE_DEFAULT}" + + +mkdir -p /munin/{db,log,www/cache} +[ -a /munin/db/cgi-tmp ] || ln -s ../www/cache /munin/db/cgi-tmp +[ -a /var/lib/munin/cgi-tmp ] || ln -s /munin/www/cache /var/lib/munin/cgi-tmp +[ -a /var/log/nginx ] || ln -s /tmp /var/log/nginx + + +truncate -s 0 "${MAIL_CONF_PATH}" + +if [ "${SMTP_USE_TLS}" = true ] ; then + cat >> "${MAIL_CONF_PATH}" <> "${MAIL_CONF_PATH}" <> "${MAIL_CONF_PATH}" <> /etc/munin/munin.conf + if [ "${SMTP_ALWAYS_SEND}" = true ] ; then + echo 'contact.mail.always_send warning critical' >> /etc/munin/munin.conf + fi +fi + +# 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 + echo "Added node '$NAME' '$HOST'" + 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 + echo "Added SNMP node '$NAME' '$HOST'" + fi +done + +for SSH_NODE in $SSH_NODES +do + NAME=`echo $SSH_NODE | cut -d ":" -f1` + HOST=`echo $SSH_NODE | cut -d ":" -f2` + PORT=`echo $SSH_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 ssh://$HOST/usr/bin/nc localhost 4949 + use_node_name yes + port $PORT + +EOF + echo "Added SSH node '$NAME' '$HOST'" + fi +done + + +# placeholder html to prevent permission error +if [ ! -e /munin/www/index.html ]; then +cat << EOF > /munin/www/index.html + + + Munin + + +Munin has not run yet. Please try again in a few moments. + + +EOF +fi + +# start rsyslogd +truncate -s 0 /tmp/rsyslogd.pid +#/usr/sbin/rsyslogd -i /tmp/rsyslogd.pid + +# start munin updates +truncate -s 0 /munin/log/munin-update.log +/usr/local/bin/supercronic -split-logs /etc/munin/munin.cron & cron_pid=$! + + +echo "Using the following munin nodes:" +echo $NODES +echo "(ssh) $SSH_NODES" +echo "(snmp) $SNMP_NODES" + +# Pregenerate data +echo "First run" +munin-cron + +echo "Start data servers" +# start spawn-cgi to enable CGI interface with munin (dynamix graph generation) +spawn-fcgi -n -p 9000 /usr/lib/munin/cgi/munin-cgi-graph & graph_pid=$! +spawn-fcgi -n -p 9001 /usr/lib/munin/cgi/munin-cgi-html & html_pid=$1 +# start nginx +/usr/sbin/nginx +# show logs +echo "Tailing syslog and munin-update log..." +tail -F /munin/log/munin-update.log & pid=$! +echo "tail -F running in $pid" + +sleep 1 + +trap "echo 'stopping processes' ; kill $pid $cron_pid $graph_pid $html_pid $(cat /tmp/nginx.pid) $(cat /tmp/rsyslogd.pid)" SIGTERM SIGINT + +echo "Waiting for signal SIGINT/SIGTERM" +wait diff --git a/files/patches/munin-ds-datalock.patch b/files/patches/munin-ds-datalock.patch new file mode 100644 index 0000000..3ec249b --- /dev/null +++ b/files/patches/munin-ds-datalock.patch @@ -0,0 +1,11 @@ +--- Munin/Master/Update.pm ++++ Munin-ds/Master/Update.pm +@@ -265,7 +265,7 @@ + sub _write_new_service_configs_locked { + my ($self) = @_; + +- my $lock_file = "$config->{rundir}/munin-datafile.lock"; ++ my $lock_file = "$config->{dbdir}/datafile.lock"; + munin_runlock($lock_file); + + my $config_dump_file = $self->{config_dump_file}; diff --git a/files/patches/munin-graph-logging.patch b/files/patches/munin-graph-logging.patch new file mode 100644 index 0000000..aa4fc56 --- /dev/null +++ b/files/patches/munin-graph-logging.patch @@ -0,0 +1,10 @@ +--- /usr/share/munin/munin-graph 2015-11-28 00:45:25.274878597 +0100 ++++ /usr/share/munin/munin-graph 2015-11-28 00:45:44.622466044 +0100 +@@ -73,6 +73,7 @@ + + logger_open($config->{'logdir'}); + logger_debug() if $config->{debug} or defined($ENV{CGI_DEBUG}); ++logger_level("warn"); + + if (! graph_check_cron() ) { + # Should not be launched from cron. diff --git a/files/patches/munin-update-logging.patch b/files/patches/munin-update-logging.patch new file mode 100644 index 0000000..4f8e87b --- /dev/null +++ b/files/patches/munin-update-logging.patch @@ -0,0 +1,10 @@ +--- /usr/share/munin/munin-update 2015-11-28 00:44:27.175435050 +0100 ++++ /usr/share/munin/munin-update 2015-11-28 00:44:57.313544402 +0100 +@@ -34,6 +34,7 @@ + + logger_open($config->{'logdir'}); + logger_debug() if $config->{debug}; ++ logger_level("warn"); + + my $update = Munin::Master::Update->new(); + $update->run(); diff --git a/munin.conf b/munin.conf deleted file mode 100644 index aa3e550..0000000 --- a/munin.conf +++ /dev/null @@ -1,20 +0,0 @@ -dbdir /munin/db -rundir /tmp -htmldir /munin/www -logdir /munin/log - -includedir /etc/munin/munin-conf.d -tmpldir /etc/munin/templates -staticdir /etc/munin/static - -# strategies cron|cgi -html_strategy cgi -graph_strategy cgi -cgiurl_graph /munin-cgi/munin-cgi-graph - -#max_size_x 4000 -#max_size_y 4000 -#max_processes 16 -#munin_cgi_graph_jobs 6 -#graph_period second -#rrdcached_socket /var/run/rrdcached.sock diff --git a/nginx-munin b/nginx-munin deleted file mode 100644 index 4dc9764..0000000 --- a/nginx-munin +++ /dev/null @@ -1,29 +0,0 @@ -server { - listen 8080 default_server; - server_name munin; - - access_log /proc/self/fd/1; - error_log /proc/self/fd/2; - - location /munin/static { - alias /etc/munin/static; - } - - location ^~ /munin/ { - fastcgi_split_path_info ^(/munin)(.*); - fastcgi_param PATH_INFO $fastcgi_path_info; - fastcgi_pass 127.0.0.1:9001; - include fastcgi_params; - } - - location ^~ /munin-cgi/munin-cgi-graph/ { - fastcgi_split_path_info ^(/munin-cgi/munin-cgi-graph)(.*); - fastcgi_param PATH_INFO $fastcgi_path_info; - fastcgi_pass 127.0.0.1:9000; - include fastcgi_params; - } - - location / { - rewrite ^/$ munin/ redirect; break; - } -} diff --git a/nginx.conf b/nginx.conf deleted file mode 100644 index 1634164..0000000 --- a/nginx.conf +++ /dev/null @@ -1,31 +0,0 @@ -worker_processes 4; -pid /tmp/nginx.pid; -error_log /proc/self/fd/2 warn; - -events { - worker_connections 768; - # multi_accept on; -} - -http { - sendfile on; - tcp_nopush on; - tcp_nodelay on; - keepalive_timeout 65; - types_hash_max_size 2048; - - include /etc/nginx/mime.types; - default_type application/octet-stream; - - #client_body_temp_path /tmp/nginx/temp; - #proxy_temp_path /tmp/nginx/proxy; - - access_log /proc/self/fd/1; - error_log /proc/self/fd/2; - - gzip on; - gzip_disable "msie6"; - - include /etc/nginx/conf.d/*.conf; - include /etc/nginx/sites-enabled/*; -} diff --git a/patches/munin-ds-datalock.patch b/patches/munin-ds-datalock.patch deleted file mode 100644 index 3ec249b..0000000 --- a/patches/munin-ds-datalock.patch +++ /dev/null @@ -1,11 +0,0 @@ ---- Munin/Master/Update.pm -+++ Munin-ds/Master/Update.pm -@@ -265,7 +265,7 @@ - sub _write_new_service_configs_locked { - my ($self) = @_; - -- my $lock_file = "$config->{rundir}/munin-datafile.lock"; -+ my $lock_file = "$config->{dbdir}/datafile.lock"; - munin_runlock($lock_file); - - my $config_dump_file = $self->{config_dump_file}; diff --git a/patches/munin-graph-logging.patch b/patches/munin-graph-logging.patch deleted file mode 100644 index aa4fc56..0000000 --- a/patches/munin-graph-logging.patch +++ /dev/null @@ -1,10 +0,0 @@ ---- /usr/share/munin/munin-graph 2015-11-28 00:45:25.274878597 +0100 -+++ /usr/share/munin/munin-graph 2015-11-28 00:45:44.622466044 +0100 -@@ -73,6 +73,7 @@ - - logger_open($config->{'logdir'}); - logger_debug() if $config->{debug} or defined($ENV{CGI_DEBUG}); -+logger_level("warn"); - - if (! graph_check_cron() ) { - # Should not be launched from cron. diff --git a/patches/munin-update-logging.patch b/patches/munin-update-logging.patch deleted file mode 100644 index 4f8e87b..0000000 --- a/patches/munin-update-logging.patch +++ /dev/null @@ -1,10 +0,0 @@ ---- /usr/share/munin/munin-update 2015-11-28 00:44:27.175435050 +0100 -+++ /usr/share/munin/munin-update 2015-11-28 00:44:57.313544402 +0100 -@@ -34,6 +34,7 @@ - - logger_open($config->{'logdir'}); - logger_debug() if $config->{debug}; -+ logger_level("warn"); - - my $update = Munin::Master::Update->new(); - $update->run(); diff --git a/start-munin.sh b/start-munin.sh deleted file mode 100755 index 63f5732..0000000 --- a/start-munin.sh +++ /dev/null @@ -1,164 +0,0 @@ -#!/bin/bash - -NODES=${NODES:-} -SNMP_NODES=${SNMP_NODES:-} -SSH_NODES=${SSH_NODES:-} -MUNIN_USERS=${MUNIN_USERS:-${MUNIN_USER:-user}} -MUNIN_PASSWORDS=${MUNIN_PASSWORDS:-${MUNIN_PASSWORD:-password}} -MAIL_CONF_PATH='/munin/db/.mailrc' -SMTP_USE_TLS=${SMTP_USE_TLS:-false} -SMTP_ALWAYS_SEND=${SMTP_ALWAYS_SEND:-true} -SMTP_MESSAGE_DEFAULT='[${var:group};${var:host}] -> ${var:graph_title} -> warnings: ${loop<,>:wfields ${var:label}=${var:value}} / criticals: ${loop<,>:cfields ${var:label}=${var:value}}' -SMTP_MESSAGE="${SMTP_MESSAGE:-$SMTP_MESSAGE_DEFAULT}" - - -mkdir -p /munin/{db,log,www/cache} -[ -a /munin/db/cgi-tmp ] || ln -s ../www/cache /munin/db/cgi-tmp -[ -a /var/lib/munin/cgi-tmp ] || ln -s /munin/www/cache /var/lib/munin/cgi-tmp -[ -a /var/log/nginx ] || ln -s /tmp /var/log/nginx - - -truncate -s 0 "${MAIL_CONF_PATH}" - -if [ "${SMTP_USE_TLS}" = true ] ; then - cat >> "${MAIL_CONF_PATH}" <> "${MAIL_CONF_PATH}" <> "${MAIL_CONF_PATH}" <> /etc/munin/munin.conf - if [ "${SMTP_ALWAYS_SEND}" = true ] ; then - echo 'contact.mail.always_send warning critical' >> /etc/munin/munin.conf - fi -fi - -# 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 - echo "Added node '$NAME' '$HOST'" - 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 - echo "Added SNMP node '$NAME' '$HOST'" - fi -done - -for SSH_NODE in $SSH_NODES -do - NAME=`echo $SSH_NODE | cut -d ":" -f1` - HOST=`echo $SSH_NODE | cut -d ":" -f2` - PORT=`echo $SSH_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 ssh://$HOST/usr/bin/nc localhost 4949 - use_node_name yes - port $PORT - -EOF - echo "Added SSH node '$NAME' '$HOST'" - fi -done - - -# placeholder html to prevent permission error -if [ ! -e /munin/www/index.html ]; then -cat << EOF > /munin/www/index.html - - - Munin - - -Munin has not run yet. Please try again in a few moments. - - -EOF -fi - -# start rsyslogd -truncate -s 0 /tmp/rsyslogd.pid -#/usr/sbin/rsyslogd -i /tmp/rsyslogd.pid - -# start munin updates -truncate -s 0 /munin/log/munin-update.log -/usr/local/bin/supercronic -split-logs /etc/munin/munin.cron & cron_pid=$! - - -echo "Using the following munin nodes:" -echo $NODES -echo "(ssh) $SSH_NODES" -echo "(snmp) $SNMP_NODES" - -# Pregenerate data -echo "First run" -munin-cron - -echo "Start data servers" -# start spawn-cgi to enable CGI interface with munin (dynamix graph generation) -spawn-fcgi -n -p 9000 /usr/lib/munin/cgi/munin-cgi-graph & graph_pid=$! -spawn-fcgi -n -p 9001 /usr/lib/munin/cgi/munin-cgi-html & html_pid=$1 -# start nginx -/usr/sbin/nginx -# show logs -echo "Tailing syslog and munin-update log..." -tail -F /munin/log/munin-update.log & pid=$! -echo "tail -F running in $pid" - -sleep 1 - -trap "echo 'stopping processes' ; kill $pid $cron_pid $graph_pid $html_pid $(cat /tmp/nginx.pid) $(cat /tmp/rsyslogd.pid)" SIGTERM SIGINT - -echo "Waiting for signal SIGINT/SIGTERM" -wait -- cgit v1.2.3