Something I wanted to add to this conversation. The information from the_architecht was pretty invaluable, but something that was missing at least for me.
Using CentOS 6.8 here:
-
1) Paths for the CGI files changed, those can be found via locate:
/var/www/cgi-bin/munin-cgi-graph
/var/www/cgi-bin/munin-cgi-html
I had to go line by line in the start script to compare locations and break out the daemon start lines to see what was wrong which let me track down the file path differences.
-
2) Permissions for the logs were set to the "munin" user which caused a silent error of sorts. To solve this I added www-data user to the munin group and chmod 664 the log files:
-rw-rw-r-- 1 munin munin 0 Apr 27 20:35 /var/log/munin/munin-cgi-graph.log
-rw-rw-r-- 1 munin munin 0 Apr 27 20:35 /var/log/munin/munin-cgi-html.log
The give away for the file permissions involved the Munin wiki adding the -n at the end of the spawn-fcgi process start and strace -s1024 which gave error
write(2, "[Thu Apr 27 21:47:35 2017] munin-cgi-html: Can't open
/var/log/munin/munin-cgi-html.log (Permission denied) at
/usr/share/perl5/vendor_perl/Log/Log4perl/Appender/File.pm line
103.\n", 180[Thu Apr 27 21:47:35 2017] munin-cgi-html: Can't open /var/log/munin/munin-cgi-html.log (Permission denied) at
/usr/share/perl5/vendor_perl/Log/Log4perl/Appender/File.pm line 103.
My final Nginx and spawn-fcgi is below with my modifications:
server {
listen $IP;
server_name $host.example.com;
access_log /var/log/nginx/domlogs/munin-access.log;
error_log /var/log/nginx/domlogs/munin-error.log;
root /var/www/html/munin/;
index index.html;
location / {
auth_basic "Restricted";
# Create the htpasswd file with the htpasswd tool.
auth_basic_user_file /etc/nginx/htpasswd/munin;
}
location ^~ /munin-cgi/munin-cgi-graph/ {
# if ($uri ~ /munin-cgi/munin-cgi-graph/([^/]*)) { set $path $1; }
fastcgi_split_path_info ^(/munin-cgi/munin-cgi-graph)(.*);
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass unix:/var/run/munin/fastcgi-munin-graph.sock;
include fastcgi_params;
}
location ^~ /munin-cgi/munin-cgi-html/ {
# if ($uri ~ /munin-cgi/munin-cgi-html/([^/]*)) { set $path $1; }
fastcgi_split_path_info ^(/munin-cgi/munin-cgi-html)(.*);
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass unix:/var/run/munin/fastcgi-munin-html.sock;
include fastcgi_params;
}
}
#! /bin/bash
### BEGIN INIT INFO
# Provides: munin-fastcgi
# Required-Start: $remote_fs $network
# Required-Stop: $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts munin-fastcgi
# Description: Spawn Munin FCGI sockets for Web access
### END INIT INFO
#
# munin-fastcgi Startup script for Munin CGI services
#
# chkconfig: - 84 15
# description: Loading Munin CGI services using spawn-cgi
# HTML files and CGI.
#
# Author: Ryan Norbauer
# Modified: Geoffrey Grosenbach http://topfunky.com
# Modified: David Krmpotic http://davidhq.com
# Modified: Kun Xi http://kunxi.org
# Modified: http://drumcoder.co.uk/
# Modified: http://uname.pingveno.net/
# Modified: the_architecht http://iwbyt.com/
# Modified: Jame Scott - NeCr0mStR
DESC="Munin FCGI for Graph and HTML"
SCRIPTNAME="$(tput setaf 1)Munin-FastCGI$(tput sgr0)"
PATH=/usr/local/bin/:/usr/local/sbin:$PATH
DAEMON=$(which spawn-fcgi)
FCGI_GRAPH_SOCK=/var/run/munin/fastcgi-munin-graph.sock
FCGI_HTML_SOCK=/var/run/munin/fastcgi-munin-html.sock
WWW_USER=www-data
FCGI_USER=www-data
FCGI_GROUP=www-data
FCGI_SPAWN_GRAPH=/var/www/cgi-bin/munin-cgi-graph
FCGI_SPAWN_HTML=/var/www/cgi-bin/munin-cgi-html
PIDFILE_GRAPH=/var/run/munin/fastcgi-munin-graph.pid
PIDFILE_HTML=/var/run/munin/fastcgi-munin-html.pid
# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0
test -x $FCGI_SPAWN_GRAPH || exit 0
test -x $FCGI_SPAWN_HTML || exit 0
start_graph() {
if [[ $(/bin/ps ax | awk '/munin-cgi-graph$/ {print $1}') ]];then
local RUNNING_PID_GRAPH=$(/bin/ps ax | awk '/munin-cgi-graph$/ {print $1}')
fi
if [[ -s ${PIDFILE_GRAPH} && ${RUNNING_PID_GRAPH} = $(cat ${PIDFILE_GRAPH}) ]];then
echo -e "\nMunin-Graph already running"
elif [[ -n ${RUNNING_PID_GRAPH} && ${RUNNING_PID_GRAPH} != $(cat ${PIDFILE_GRAPH}) && -S ${FCGI_GRAPH_SOCK} ]];then
echo -e "\nMunin-Graph PID mismatch :: Cleaning up and starting Munin-Graph"
kill -QUIT ${RUNNING_PID_GRAPH}
sleep 1
$DAEMON -s $FCGI_GRAPH_SOCK -U $WWW_USER -u $FCGI_USER -g $FCGI_GROUP -P $PIDFILE_GRAPH $FCGI_SPAWN_GRAPH > /dev/null 2>&1
else
$DAEMON -s $FCGI_GRAPH_SOCK -U $WWW_USER -u $FCGI_USER -g $FCGI_GROUP -P $PIDFILE_GRAPH $FCGI_SPAWN_GRAPH > /dev/null 2>&1
echo -e "Starting Munin-Graph\n"
fi
}
start_html() {
if [[ $(/bin/ps ax | awk '/munin-cgi-html$/ {print $1}') ]];then
local RUNNING_PID_HTML=$(/bin/ps ax | awk '/munin-cgi-html$/ {print $1}')
fi
if [[ -s ${PIDFILE_HTML} && ${RUNNING_PID_HTML} = $(cat ${PIDFILE_HTML}) ]];then
echo -e "\nMunin-HTML already running"
elif [[ -n ${RUNNING_PID_HTML} && ${RUNNING_PID_HTML} != $(cat ${PIDFILE_HTML}) && -S ${FCGI_HTML_SOCK} ]];then
echo -e "\nMunin-HTML PID mismatch :: Cleaning up and starting Munin-HTML"
kill -QUIT ${RUNNING_PID_HTML}
sleep 1
$DAEMON -s $FCGI_HTML_SOCK -U $WWW_USER -u $FCGI_USER -g $FCGI_GROUP -P $PIDFILE_HTML $FCGI_SPAWN_HTML > /dev/null 2>&1
else
$DAEMON -s $FCGI_HTML_SOCK -U $WWW_USER -u $FCGI_USER -g $FCGI_GROUP -P $PIDFILE_HTML $FCGI_SPAWN_HTML > /dev/null 2>&1
echo -e "Starting Munin-HTML\n"
fi
}
stop_graph() {
if [[ $(/bin/ps ax | awk '/munin-cgi-graph$/ {print $1}') ]];then
local RUNNING_PID_GRAPH=$(/bin/ps ax | awk '/munin-cgi-graph$/ {print $1}')
fi
if [[ -s ${PIDFILE_GRAPH} && $(cat ${PIDFILE_GRAPH}) = ${RUNNING_PID_GRAPH} ]];then
kill -QUIT $(cat ${PIDFILE_GRAPH})
echo -e "\nMunin-Graph stopped"
elif [[ -z ${RUNNING_PID_GRAPH} && -s ${PIDFILE_GRAPH} ]];then
echo -e "\nGraph PID not found :: Cleaning up PID file"
rm ${PIDFILE_GRAPH}
elif [[ -s ${PIDFILE_GRAPH} && $(cat ${PIDFILE_GRAPH}) != ${RUNNING_PID_GRAPH} ]];then
kill -QUIT ${RUNNING_PID_GRAPH}
rm ${PIDFILE_GRAPH}
echo -e "\nMunin-Graph stopped :: Cleaning up PID file"
else
echo -e "\nNo Munin-Graph process found"
fi
}
stop_html() {
if [[ $(/bin/ps ax | awk '/munin-cgi-html$/ {print $1}') ]];then
local RUNNING_PID_HTML=$(/bin/ps ax | awk '/munin-cgi-html$/ {print $1}')
fi
if [[ -s ${PIDFILE_HTML} && $(cat ${PIDFILE_HTML}) = ${RUNNING_PID_HTML} ]];then
kill -QUIT $(cat ${PIDFILE_HTML})
echo -e "\nMunin-HTML stopped"
elif [[ -z ${RUNNING_PID_HTML} && -s ${PIDFILE_HTML} ]];then
echo -e "\nHTML PID not found :: Cleaning up PID file"
rm ${PIDFILE_HTML}
elif [[ -s ${PIDFILE_HTML} && $(cat ${PIDFILE_HTML}) != ${RUNNING_PID_HTML} ]];then
kill -QUIT ${RUNNING_PID_HTML}
rm ${PIDFILE_HTML}
echo -e "\nMunin-HTML stopped :: Cleaning up PID file"
else
echo -e "\nNo Munin-HTML process found"
fi
}
case "$1" in
start)
echo "Starting $DESC: "
start_graph
start_html
;;
start_graph)
echo "Starting Munin-Graph"
start_graph
;;
start_html)
echo "Starting Munin-HTML"
start_html
;;
stop_graph)
echo "Stopping Munin_Graph"
stop_graph
;;
stop_html)
echo "Stopping Munin-HTML"
stop_html
;;
stop)
echo "Stopping $DESC: "
stop_graph
stop_html
;;
restart|reload)
echo "Restarting $DESC: "
stop_html
stop_graph
# One second might not be time enough for a daemon to stop,
# if this happens, d_start will fail (and dpkg will break if
# the package is being upgraded). Change the timeout if needed
# be, or change d_stop to have start-stop-daemon use --retry.
# Notice that using --retry slows down the shutdown process somewhat.
sleep 5
start_graph
start_html
;;
*)
echo "$(tput setaf 2)Usage: $SCRIPTNAME $(tput setaf 7)$(tput setab 0){start_graph|start_html|stop_graph|stop_html|start|stop|restart|reload}$(tput sgr0) " >&2
exit 3
;;
esac
exit $?