1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
8 inherit java-pkg-opt-2 systemd
12 DESCRIPTION="Munin Server Monitoring Tool"
13 HOMEPAGE="http://munin-monitoring.org/"
15 https://github.com/munin-monitoring/munin/archive/${PV}.tar.gz -> ${P}.tar.gz
16 https://dev.gentoo.org/~graaff/munin/${P}-gentoo-${PATCHSET}.tar.xz"
20 KEYWORDS="~amd64 ~arm ~arm64 ppc ~ppc64 ~x86"
21 IUSE="asterisk irc java ldap memcached minimal mysql postgres selinux ssl test cgi ipv6 syslog ipmi http dhcpd doc apache2"
22 REQUIRED_USE="cgi? ( !minimal ) apache2? ( cgi )"
23 RESTRICT="!test? ( test )"
25 # Upstream's listing of required modules is NOT correct!
26 # Some of the postgres plugins use DBD::Pg, while others call psql directly.
27 # Some of the mysql plugins use DBD::mysql, while others call mysqladmin directly.
28 # We replace the original ipmi plugins with the freeipmi_ plugin which at least works.
33 dev-lang/perl:=[berkdb]
36 dev-perl/File-Copy-Recursive
37 dev-perl/List-MoreUtils
43 dev-perl/Net-Server[ipv6(-)?]
44 virtual/perl-Digest-MD5
45 virtual/perl-Getopt-Long
46 virtual/perl-MIME-Base64
48 virtual/perl-Text-Balanced
49 virtual/perl-Time-HiRes
50 apache2? ( www-servers/apache[apache2_modules_cgi,apache2_modules_cgid,apache2_modules_rewrite] )
51 asterisk? ( dev-perl/Net-Telnet )
57 >=net-misc/dhcp-3[server]
61 doc? ( dev-python/sphinx )
62 http? ( dev-perl/libwww-perl )
63 irc? ( dev-perl/Net-IRC )
64 ldap? ( dev-perl/perl-ldap )
65 kernel_linux? ( sys-process/procps )
66 memcached? ( dev-perl/Cache-Memcached )
72 postgres? ( dev-perl/DBD-Pg dev-db/postgresql:* )
73 ssl? ( dev-perl/Net-SSLeay )
74 syslog? ( virtual/perl-Sys-Syslog )
76 dev-perl/HTML-Template
77 dev-perl/IO-Socket-INET6
79 >=net-analyzer/rrdtool-1.3[graph,perl]
84 # Keep this seperate, as previous versions have had other deps here
87 java? ( >=virtual/jdk-1.5 )
90 dev-perl/Test-Exception
91 dev-perl/Test-LongString
92 dev-perl/Test-Differences
93 dev-perl/Test-MockModule
94 dev-perl/Test-MockObject
97 dev-perl/IO-Socket-INET6
99 RDEPEND="${DEPEND_COM}
101 ipmi? ( >=sys-libs/freeipmi-1.1.6-r1 )
104 || ( net-analyzer/netcat net-analyzer/openbsd-netcat )
110 selinux? ( sec-policy/selinux-munin )"
112 S="${WORKDIR}/${MY_P}"
115 java-pkg-opt-2_pkg_setup
119 echo ${PV} > RELEASE || die
121 eapply "${WORKDIR}"/patches/*.patch
125 java-pkg-opt-2_src_prepare
129 local cgidir='$(DESTDIR)/usr/libexec/munin/cgi'
130 use cgi || cgidir="${T}/useless/cgi-bin"
132 local cgiuser=$(usex apache2 apache munin)
134 cat >> "${S}"/Makefile.config <<- EOF
135 PREFIX=\$(DESTDIR)/usr
136 CONFDIR=\$(DESTDIR)/etc/munin
137 DOCDIR=${T}/useless/doc
138 MANDIR=\$(PREFIX)/share/man
139 LIBDIR=\$(PREFIX)/libexec/munin
140 HTMLDIR=\$(DESTDIR)/var/www/localhost/htdocs/munin
142 CGITMPDIR=\$(DESTDIR)/var/cache/munin-cgi
144 DBDIR=\$(DESTDIR)/var/lib/munin
145 DBDIRNODE=\$(DESTDIR)/var/lib/munin-node
146 SPOOLDIR=\$(DESTDIR)/var/spool/munin-async
147 LOGDIR=\$(DESTDIR)/var/log/munin
148 PERLLIB=\$(DESTDIR)$(perl -V:vendorlib | cut -d"'" -f2)
149 JCVALID=$(usex java yes no)
150 STATEDIR=\$(DESTDIR)/run/munin
154 # parallel make and install need to be fixed before, and I haven't
155 # gotten around to do so yet.
158 use doc && emake -C doc html
162 if [[ ${EUID} == 0 ]]; then
163 eerror "You cannot run tests as root."
164 eerror "Please enable FEATURES=userpriv before proceeding."
168 local testtargets="test-common test-node test-plugins"
169 use minimal || testtargets+=" test-master"
171 LC_ALL=C emake -j1 ${testtargets}
177 /var/lib/munin/plugin-state
178 /var/lib/munin-node/plugin-state
179 /var/www/localhost/htdocs/munin
180 /etc/munin/plugin-conf.d
182 use minimal || dirs+=" /etc/munin/munin-conf.d/"
185 fowners munin:munin ${dirs}
187 # parallel install doesn't work and it's also pointless to have this
188 # run in parallel for now (because it uses internal loops).
189 emake -j1 CHOWN=true DESTDIR="${D}" $(usex minimal "install-minimal install-man" install)
191 # we remove /run from the install, as it's not the package's to deal
193 rm -rf "${D}"/run || die
195 # remove the plugins for non-Gentoo package managers; use -f so that
196 # it doesn't fail when installing on non-Linux platforms.
197 rm -f "${D}"/usr/libexec/munin/plugins/{apt{,_all},yum} || die
199 insinto /etc/munin/plugin-conf.d/
200 newins "${FILESDIR}"/${PN}-1.3.2-plugins.conf munin-node
202 newinitd "${FILESDIR}"/munin-node_init.d_2.0.19 munin-node
203 newconfd "${FILESDIR}"/munin-node_conf.d_1.4.6-r2 munin-node
205 newinitd "${FILESDIR}"/munin-asyncd.init.2 munin-asyncd
207 dodir /usr/lib/tmpfiles.d
208 cat > "${D}"/usr/lib/tmpfiles.d/${CATEGORY}:${PN}:${SLOT}.conf <<- EOF
209 d /run/munin 0700 munin munin - -
212 systemd_dounit "${FILESDIR}"/munin-async.service
213 systemd_dounit "${FILESDIR}"/munin-graph.{service,socket}
214 systemd_dounit "${FILESDIR}"/munin-html.{service,socket}
215 systemd_dounit "${FILESDIR}"/munin-node.service
217 cat >> "${T}"/munin.env <<- EOF
218 CONFIG_PROTECT=/var/spool/munin-async/.ssh
220 newenvd "${T}"/munin.env 50munin
222 dodoc README ChangeLog INSTALL
224 cd "${S}"/doc/_build/html || die
230 dodir /etc/logrotate.d/
231 sed -e "s:@CGIUSER@:$(usex apache2 apache munin):g" \
232 "${FILESDIR}"/logrotate.d-munin.3 > "${D}"/etc/logrotate.d/munin
234 dosym ipmi_ /usr/libexec/munin/plugins/ipmi_sensor_
237 sed -i -e '/log_file/s| .*| Sys::Syslog|' \
238 "${D}"/etc/munin/munin-node.conf || die
241 # Use a simpler pid file to avoid trouble with /run in tmpfs. The
242 # munin-node service is ran as user root, and only later drops
244 sed -i -e 's:/run/munin/munin-node.pid:/run/munin-node.pid:' \
245 "${D}"/etc/munin/munin-node.conf || die
247 keepdir /var/spool/munin-async/.ssh
248 touch "${D}"/var/spool/munin-async/.ssh/authorized_keys
249 fowners munin-async:munin /var/spool/munin-async{,/.ssh/{,authorized_keys}}
250 fperms 0750 /var/spool/munin-async{,/.ssh}
251 fperms 0600 /var/spool/munin-async/.ssh/authorized_keys
254 # This requires the presence of munin-update, which is part of
255 # the non-minimal install...
256 rm "${D}"/usr/libexec/munin/plugins/munin_stats
258 # remove font files so that we don't have to keep them around
259 rm "${D}"/usr/libexec/${PN}/*.ttf || die
262 sed -i -e '/#graph_strategy cgi/s:^#::' "${D}"/etc/munin/munin.conf || die
264 keepdir /var/cache/munin-cgi
265 touch "${D}"/var/log/munin/munin-cgi-{graph,html}.log
266 fowners $(usex apache2 apache munin) \
267 /var/cache/munin-cgi \
268 /var/log/munin/munin-cgi-{graph,html}.log
271 insinto /etc/apache2/vhosts.d
272 newins "${FILESDIR}"/munin.apache.include munin.include
273 newins "${FILESDIR}"/munin.apache.include-2.4 munin-2.4.include
277 -e '/#graph_strategy cgi/s:#graph_strategy cgi:graph_strategy cron:' \
278 -i "${D}"/etc/munin/munin.conf || die
281 keepdir /var/lib/munin/.ssh
282 cat >> "${D}"/var/lib/munin/.ssh/config <<- EOF
283 IdentityFile /var/lib/munin/.ssh/id_ecdsa
284 IdentityFile /var/lib/munin/.ssh/id_rsa
287 fowners munin:munin /var/lib/munin/.ssh/{,config}
288 fperms go-rwx /var/lib/munin/.ssh/{,config}
290 dodir /usr/share/${PN}
291 cat >> "${D}"/usr/share/${PN}/crontab <<- EOF
292 # Force the shell to bash
294 # Mail reports to root@, not munin@
297 # This runs the munin task every 5 minutes.
298 */5 * * * * /usr/bin/munin-cron
300 # Alternatively, this route works differently
301 # Update once a minute (for busy sites)
302 #*/1 * * * * /usr/libexec/munin/munin-update
303 ## Check for limit excess every 2 minutes
304 #*/2 * * * * /usr/libexec/munin/munin-limits
305 ## Update graphs every 5 minutes
306 #*/5 * * * * nice /usr/libexec/munin/munin-graph
307 ## Update HTML pages every 15 minutes
308 #*/15 * * * * nice /usr/libexec/munin/munin-html
311 cat >> "${D}"/usr/share/${PN}/fcrontab <<- EOF
312 # Mail reports to root@, not munin@, only execute one at a time
313 !mailto(root),serial(true)
315 # This runs the munin task every 5 minutes.
316 @ 5 /usr/bin/munin-cron
318 # Alternatively, this route works differently
319 # Update once a minute (for busy sites)
320 #@ 1 /usr/libexec/munin/munin-update
321 ## Check for limit excess every 2 minutes
322 #@ 2 /usr/libexec/munin/munin-limits
323 ## Update graphs every 5 minutes
324 #@ 5 nice /usr/libexec/munin/munin-graph
325 ## Update HTML pages every 15 minutes
326 #@ 15 nice /usr/libexec/munin/munin-html
329 # remove .htaccess file
330 find "${D}" -name .htaccess -delete || die
336 einfo "Nothing to do."
340 einfo "Press enter to install the default crontab for the munin master"
341 einfo "installation from /usr/share/${PN}/f?crontab"
342 einfo "If you have a large site, you may wish to customize it."
345 ebegin "Setting up cron ..."
346 if has_version sys-process/fcron; then
347 fcrontab - -u munin < /usr/share/${PN}/fcrontab
349 # dcron is very fussy about syntax
350 # the following is the only form that works in BOTH dcron and vixie-cron
351 crontab - -u munin < /usr/share/${PN}/crontab
355 einfo "Press enter to set up the SSH keys used for SSH transport"
358 # generate one rsa (for legacy) and one ecdsa (for new systems)
360 -f /var/lib/munin/.ssh/id_rsa -N '' \
361 -C "created by portage for ${CATEGORY}/${PN}" || die
362 ssh-keygen -t ecdsa \
363 -f /var/lib/munin/.ssh/id_ecdsa -N '' \
364 -C "created by portage for ${CATEGORY}/${PN}" || die
365 chown -R munin:munin /var/lib/munin/.ssh || die
366 chmod 0600 /var/lib/munin/.ssh/id_{rsa,ecdsa} || die
368 einfo "Your public keys are available in "
369 einfo " /var/lib/munin/.ssh/id_rsa.pub"
370 einfo " /var/lib/munin/.ssh/id_ecdsa.pub"
371 einfo "and follows for convenience"
373 cat /var/lib/munin/.ssh/id_*.pub
377 elog "Please follow the munin documentation to set up the plugins you"
378 elog "need, afterwards start munin-node."
380 elog "To make use of munin-async, make sure to set up the corresponding"
381 elog "SSH key in /var/lib/munin-async/.ssh/authorized_keys"
383 if ! use minimal; then
385 elog " emerge --config net-analyzer/munin"
386 elog "to automatically configure munin's cronjobs as well as generate"
387 elog "passwordless SSH keys to be used with munin-async."
390 elog "Further information about setting up Munin in Gentoo can be found"
391 elog "in the Gentoo Wiki: https://wiki.gentoo.org/wiki/Munin"
394 chown $(usex apache2 apache munin) \
395 "${ROOT}"/var/cache/munin-cgi \
396 "${ROOT}"/var/log/munin/munin-cgi-{graph,html}.log
399 elog "To use Munin with CGI you should include /etc/apache2/vhosts.d/munin.include"
400 elog "or /etc/apache2/vhosts.d/munin-2.4.include (for Apache 2.4) from the virtual"
401 elog "host you want it to be served."
402 elog "If you want to enable CGI-based HTML as well, you have to add to"
403 elog "/etc/conf.d/apache2 the option -D MUNIN_HTML_CGI."
405 elog "Effective CGI support has just been added in 2.0.7-r6."
406 elog "Documentation on how to use it is still sparse."
410 # we create this here as we don't want Portage to check /run
411 # symlinks but we still need this to be present before the reboot.
412 if ! use minimal && ! [[ -d "${ROOT}"/run/munin ]]; then
413 mkdir "${ROOT}"/run/munin
414 chown munin:munin "${ROOT}"/run/munin
415 chmod 0700 "${ROOT}"/run/munin