1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
9 inherit eutils user java-pkg-opt-2 systemd
13 DESCRIPTION="Munin Server Monitoring Tool"
14 HOMEPAGE="http://munin-monitoring.org/"
15 SRC_URI="mirror://sourceforge/munin/${MY_P}.tar.gz
16 https://dev.gentoo.org/~flameeyes/${PN}/${P}-gentoo-${PATCHSET}.tar.xz"
20 KEYWORDS="amd64 ~arm ~mips ppc x86"
21 IUSE="asterisk irc java memcached minimal mysql postgres ssl test cgi ipv6 syslog ipmi http dhcpd doc apache"
22 REQUIRED_USE="cgi? ( !minimal ) apache? ( cgi )"
24 # Upstream's listing of required modules is NOT correct!
25 # Some of the postgres plugins use DBD::Pg, while others call psql directly.
26 # Some of the mysql plugins use DBD::mysql, while others call mysqladmin directly.
27 # We replace the original ipmi plugins with the freeipmi_ plugin which at least works.
28 DEPEND_COM="dev-lang/perl[berkdb]
29 kernel_linux? ( sys-process/procps )
30 doc? ( dev-python/sphinx )
31 asterisk? ( dev-perl/Net-Telnet )
32 irc? ( dev-perl/Net-IRC )
33 mysql? ( virtual/mysql
36 ssl? ( dev-perl/Net-SSLeay )
37 postgres? ( dev-perl/DBD-Pg dev-db/postgresql )
38 memcached? ( dev-perl/Cache-Memcached )
39 cgi? ( dev-perl/FCGI )
40 apache? ( www-servers/apache[apache2_modules_cgi,apache2_modules_cgid,apache2_modules_rewrite] )
41 syslog? ( virtual/perl-Sys-Syslog )
42 http? ( dev-perl/libwww-perl )
44 >=net-misc/dhcp-3[server]
50 dev-perl/File-Copy-Recursive
51 dev-perl/List-MoreUtils
57 dev-perl/net-server[ipv6(-)?]
58 virtual/perl-Digest-MD5
59 virtual/perl-Getopt-Long
60 virtual/perl-MIME-Base64
62 virtual/perl-Text-Balanced
63 virtual/perl-Time-HiRes
65 dev-perl/HTML-Template
66 dev-perl/IO-Socket-INET6
68 >=net-analyzer/rrdtool-1.3[graph,perl]
72 # Keep this seperate, as previous versions have had other deps here
75 java? ( >=virtual/jdk-1.5 )
78 dev-perl/Test-LongString
79 dev-perl/Test-Differences
80 dev-perl/Test-MockModule
81 dev-perl/Test-MockObject
84 dev-perl/IO-Socket-INET6
86 RDEPEND="${DEPEND_COM}
88 ipmi? ( >=sys-libs/freeipmi-1.1.6-r1 )
91 || ( net-analyzer/netcat6 net-analyzer/netcat )
97 !<sys-apps/openrc-0.11.8"
99 S="${WORKDIR}/${MY_P}"
103 enewuser munin 177 -1 /var/lib/munin munin
104 enewuser munin-async -1 /bin/sh /var/spool/munin-async
105 esethome munin-async /var/spool/munin-async
106 java-pkg-opt-2_pkg_setup
110 epatch "${WORKDIR}"/patches/*.patch
112 java-pkg-opt-2_src_prepare
116 local cgidir='$(DESTDIR)/usr/libexec/munin/cgi'
117 use cgi || cgidir="${T}/useless/cgi-bin"
119 local cgiuser=$(usex apache apache munin)
121 cat - >> "${S}"/Makefile.config <<EOF
122 PREFIX=\$(DESTDIR)/usr
123 CONFDIR=\$(DESTDIR)/etc/munin
124 DOCDIR=${T}/useless/doc
125 MANDIR=\$(PREFIX)/share/man
126 LIBDIR=\$(PREFIX)/libexec/munin
127 HTMLDIR=\$(DESTDIR)/var/www/localhost/htdocs/munin
129 CGITMPDIR=\$(DESTDIR)/var/cache/munin-cgi
131 DBDIR=\$(DESTDIR)/var/lib/munin
132 DBDIRNODE=\$(DESTDIR)/var/lib/munin-node
133 SPOOLDIR=\$(DESTDIR)/var/spool/munin-async
134 LOGDIR=\$(DESTDIR)/var/log/munin
135 PERLSITELIB=$(perl -V:vendorlib | cut -d"'" -f2)
136 JCVALID=$(usex java yes no)
137 STATEDIR=\$(DESTDIR)/run/munin
141 # parallel make and install need to be fixed before, and I haven't
142 # gotten around to do so yet.
151 if [[ ${EUID} == 0 ]]; then
152 eerror "You cannot run tests as root."
153 eerror "Please enable FEATURES=userpriv before proceeding."
157 local testtargets="test-common test-node test-plugins"
158 use minimal || testtargets+=" test-master"
160 LC_ALL=C emake -j1 ${testtargets}
166 /var/lib/munin/plugin-state
167 /etc/munin/plugin-conf.d
169 use minimal || dirs+=" /etc/munin/munin-conf.d/"
172 fowners munin:munin ${dirs}
174 # parallel install doesn't work and it's also pointless to have this
175 # run in parallel for now (because it uses internal loops).
176 emake -j1 DESTDIR="${D}" $(usex minimal install-minimal install)
178 # we remove /run from the install, as it's not the package's to deal
182 # remove the plugins for non-Gentoo package managers; use -f so that
183 # it doesn't fail when installing on non-Linux platforms.
184 rm -f "${D}"/usr/libexec/munin/plugins/{apt{,_all},yum} || die
186 insinto /etc/munin/plugin-conf.d/
187 newins "${FILESDIR}"/${PN}-1.3.2-plugins.conf munin-node
189 newinitd "${FILESDIR}"/munin-node_init.d_2.0.19 munin-node
190 newconfd "${FILESDIR}"/munin-node_conf.d_1.4.6-r2 munin-node
192 newinitd "${FILESDIR}"/munin-asyncd.init.2 munin-asyncd
194 dodir /usr/lib/tmpfiles.d
195 cat - > "${D}"/usr/lib/tmpfiles.d/${CATEGORY}:${PN}:${SLOT}.conf <<EOF
196 d /run/munin 0700 munin munin - -
199 systemd_dounit "${FILESDIR}"/munin-async.service
200 systemd_dounit "${FILESDIR}"/munin-graph.{service,socket}
201 systemd_dounit "${FILESDIR}"/munin-html.{service,socket}
202 systemd_dounit "${FILESDIR}"/munin-node.service
204 cat - >> "${T}"/munin.env <<EOF
205 CONFIG_PROTECT=/var/spool/munin-async/.ssh
207 newenvd "${T}"/munin.env 50munin
209 dodoc README ChangeLog INSTALL
211 cd "${S}"/doc/_build/html
216 dodir /etc/logrotate.d/
217 sed -e "s:@CGIUSER@:$(usex apache apache munin):g" \
218 "${FILESDIR}"/logrotate.d-munin.2 > "${D}"/etc/logrotate.d/munin
220 dosym ipmi_ /usr/libexec/munin/plugins/ipmi_sensor_
223 sed -i -e '/log_file/s| .*| Sys::Syslog|' \
224 "${D}"/etc/munin/munin-node.conf || die
227 # Use a simpler pid file to avoid trouble with /run in tmpfs. The
228 # munin-node service is ran as user root, and only later drops
230 sed -i -e 's:/run/munin/munin-node.pid:/run/munin-node.pid:' \
231 "${D}"/etc/munin/munin-node.conf || die
233 keepdir /var/spool/munin-async/.ssh
234 touch "${D}"/var/spool/munin-async/.ssh/authorized_keys
235 fowners munin-async:munin /var/spool/munin-async{,/.ssh/{,authorized_keys}}
236 fperms 0750 /var/spool/munin-async{,/.ssh}
237 fperms 0600 /var/spool/munin-async/.ssh/authorized_keys
240 # This requires the presence of munin-update, which is part of
241 # the non-minimal install...
242 rm "${D}"/usr/libexec/munin/plugins/munin_stats
244 # remove font files so that we don't have to keep them around
245 rm "${D}"/usr/libexec/${PN}/*.ttf || die
248 sed -i -e '/#graph_strategy cgi/s:^#::' "${D}"/etc/munin/munin.conf || die
250 keepdir /var/cache/munin-cgi
251 touch "${D}"/var/log/munin/munin-cgi-{graph,html}.log
252 fowners $(usex apache apache munin) \
253 /var/cache/munin-cgi \
254 /var/log/munin/munin-cgi-{graph,html}.log
257 insinto /etc/apache2/vhosts.d
258 newins "${FILESDIR}"/munin.apache.include munin.include
259 newins "${FILESDIR}"/munin.apache.include-2.4 munin-2.4.include
262 sed -i -e '/#graph_strategy cgi/s:#graph_strategy cgi:graph_strategy cron:' "${D}"/etc/munin/munin.conf || die
265 keepdir /var/lib/munin/.ssh
266 cat - >> "${D}"/var/lib/munin/.ssh/config <<EOF
267 IdentityFile /var/lib/munin/.ssh/id_ecdsa
268 IdentityFile /var/lib/munin/.ssh/id_rsa
271 fowners munin:munin /var/lib/munin/.ssh/{,config}
272 fperms go-rwx /var/lib/munin/.ssh/{,config}
274 dodir /usr/share/${PN}
275 cat - >> "${D}"/usr/share/${PN}/crontab <<EOF
276 # Force the shell to bash
278 # Mail reports to root@, not munin@
281 # This runs the munin task every 5 minutes.
282 */5 * * * * /usr/bin/munin-cron
284 # Alternatively, this route works differently
285 # Update once a minute (for busy sites)
286 #*/1 * * * * /usr/libexec/munin/munin-update
287 ## Check for limit excess every 2 minutes
288 #*/2 * * * * /usr/libexec/munin/munin-limits
289 ## Update graphs every 5 minutes
290 #*/5 * * * * nice /usr/libexec/munin/munin-graph
291 ## Update HTML pages every 15 minutes
292 #*/15 * * * * nice /usr/libexec/munin/munin-html
295 cat - >> "${D}"/usr/share/${PN}/fcrontab <<EOF
296 # Mail reports to root@, not munin@, only execute one at a time
297 !mailto(root),serial(true)
299 # This runs the munin task every 5 minutes.
300 @ 5 /usr/bin/munin-cron
302 # Alternatively, this route works differently
303 # Update once a minute (for busy sites)
304 #@ 1 /usr/libexec/munin/munin-update
305 ## Check for limit excess every 2 minutes
306 #@ 2 /usr/libexec/munin/munin-limits
307 ## Update graphs every 5 minutes
308 #@ 5 nice /usr/libexec/munin/munin-graph
309 ## Update HTML pages every 15 minutes
310 #@ 15 nice /usr/libexec/munin/munin-html
313 # remove .htaccess file
314 find "${D}" -name .htaccess -delete || die
320 einfo "Nothing to do."
324 einfo "Press enter to install the default crontab for the munin master"
325 einfo "installation from /usr/share/${PN}/f?crontab"
326 einfo "If you have a large site, you may wish to customize it."
329 ebegin "Setting up cron ..."
330 if has_version sys-process/fcron; then
331 fcrontab - -u munin < /usr/share/${PN}/fcrontab
333 # dcron is very fussy about syntax
334 # the following is the only form that works in BOTH dcron and vixie-cron
335 crontab - -u munin < /usr/share/${PN}/crontab
339 einfo "Press enter to set up the SSH keys used for SSH transport"
342 # generate one rsa (for legacy) and one ecdsa (for new systems)
343 ssh-keygen -t rsa -f /var/lib/munin/.ssh/id_rsa -N '' -C "created by portage for ${CATEGORY}/${PN}" || die
344 ssh-keygen -t ecdsa -f /var/lib/munin/.ssh/id_ecdsa -N '' -C "created by portage for ${CATEGORY}/${PN}" || die
345 chown -R munin:munin /var/lib/munin/.ssh || die
346 chmod 0600 /var/lib/munin/.ssh/id_{rsa,ecdsa} || die
348 einfo "Your public keys are available in "
349 einfo " /var/lib/munin/.ssh/id_rsa.pub"
350 einfo " /var/lib/munin/.ssh/id_ecdsa.pub"
351 einfo "and follows for convenience"
353 cat /var/lib/munin/.ssh/id_*.pub
357 elog "Please follow the munin documentation to set up the plugins you"
358 elog "need, afterwards start munin-node."
360 elog "To make use of munin-async, make sure to set up the corresponding"
361 elog "SSH key in /var/lib/munin-async/.ssh/authorized_keys"
363 if ! use minimal; then
365 elog " emerge --config net-analyzer/munin"
366 elog "to automatically configure munin's cronjobs as well as generate"
367 elog "passwordless SSH keys to be used with munin-async."
370 elog "Further information about setting up Munin in Gentoo can be found"
371 elog "in the Gentoo Wiki: https://wiki.gentoo.org/wiki/Munin"
374 chown $(usex apache apache munin) \
375 "${ROOT}"/var/cache/munin-cgi \
376 "${ROOT}"/var/log/munin/munin-cgi-{graph,html}.log
379 elog "To use Munin with CGI you should include /etc/apache2/vhosts.d/munin.include"
380 elog "or /etc/apache2/vhosts.d/munin-2.4.include (for Apache 2.4) from the virtual"
381 elog "host you want it to be served."
382 elog "If you want to enable CGI-based HTML as well, you have to add to"
383 elog "/etc/conf.d/apache2 the option -D MUNIN_HTML_CGI."
385 elog "Effective CGI support has just been added in 2.0.7-r6."
386 elog "Documentation on how to use it is still sparse."
390 # we create this here as we don't want Portage to check /run
391 # symlinks but we still need this to be present before the reboot.
392 if ! use minimal && ! [[ -d "${ROOT}"/run/munin ]]; then
393 mkdir "${ROOT}"/run/munin
394 chown munin:munin "${ROOT}"/run/munin
395 chmod 0700 "${ROOT}"/run/munin