net-analyzer/munin: stable 2.0.59 for ppc, bug #725954
[gentoo.git] / net-analyzer / munin / munin-2.0.59.ebuild
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=7
5
6 PATCHSET=1
7
8 inherit java-pkg-opt-2 systemd
9
10 MY_P=${P/_/-}
11
12 DESCRIPTION="Munin Server Monitoring Tool"
13 HOMEPAGE="http://munin-monitoring.org/"
14 SRC_URI="
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"
17
18 LICENSE="GPL-2"
19 SLOT="0"
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 )"
24
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.
29 DEPEND_COM="
30         acct-user/munin
31         acct-user/munin-async
32         acct-group/munin
33         dev-lang/perl:=[berkdb]
34         dev-perl/DBI
35         dev-perl/Date-Manip
36         dev-perl/File-Copy-Recursive
37         dev-perl/List-MoreUtils
38         dev-perl/Log-Log4perl
39         dev-perl/Net-CIDR
40         dev-perl/Net-DNS
41         dev-perl/Net-Netmask
42         dev-perl/Net-SNMP
43         dev-perl/Net-Server[ipv6(-)?]
44         virtual/perl-Digest-MD5
45         virtual/perl-Getopt-Long
46         virtual/perl-MIME-Base64
47         virtual/perl-Storable
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 )
52         cgi? (
53                 dev-perl/FCGI
54                 dev-perl/CGI-Fast
55                 )
56         dhcpd? (
57                 >=net-misc/dhcp-3[server]
58                 dev-perl/Net-IP
59                 dev-perl/HTTP-Date
60                 )
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 )
67         mysql? (
68                 virtual/mysql
69                 dev-perl/Cache-Cache
70                 dev-perl/DBD-mysql
71                 )
72         postgres? ( dev-perl/DBD-Pg dev-db/postgresql:* )
73         ssl? ( dev-perl/Net-SSLeay )
74         syslog? ( virtual/perl-Sys-Syslog )
75         !minimal? (
76                 dev-perl/HTML-Template
77                 dev-perl/IO-Socket-INET6
78                 dev-perl/URI
79                 >=net-analyzer/rrdtool-1.3[graph,perl]
80                 virtual/ssh
81                 )
82         "
83
84 # Keep this seperate, as previous versions have had other deps here
85 DEPEND="${DEPEND_COM}
86         dev-perl/Module-Build
87         java? ( >=virtual/jdk-1.5 )
88         test? (
89                 dev-perl/Test-Deep
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
95                 dev-perl/File-Slurp
96                 dev-perl/IO-stringy
97                 dev-perl/IO-Socket-INET6
98         )"
99 RDEPEND="${DEPEND_COM}
100                 virtual/awk
101                 ipmi? ( >=sys-libs/freeipmi-1.1.6-r1 )
102                 java? (
103                         >=virtual/jre-1.5
104                         || ( net-analyzer/netcat net-analyzer/openbsd-netcat )
105                 )
106                 !minimal? (
107                         virtual/cron
108                         media-fonts/dejavu
109                 )
110                 selinux? ( sec-policy/selinux-munin )"
111
112 S="${WORKDIR}/${MY_P}"
113
114 pkg_setup() {
115         java-pkg-opt-2_pkg_setup
116 }
117
118 src_prepare() {
119         echo ${PV} > RELEASE || die
120
121         eapply "${WORKDIR}"/patches/*.patch
122
123         eapply_user
124
125         java-pkg-opt-2_src_prepare
126 }
127
128 src_configure() {
129         local cgidir='$(DESTDIR)/usr/libexec/munin/cgi'
130         use cgi || cgidir="${T}/useless/cgi-bin"
131
132         local cgiuser=$(usex apache2 apache munin)
133
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
141         CGIDIR=${cgidir}
142         CGITMPDIR=\$(DESTDIR)/var/cache/munin-cgi
143         CGIUSER=${cgiuser}
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
151         EOF
152 }
153
154 # parallel make and install need to be fixed before, and I haven't
155 # gotten around to do so yet.
156 src_compile() {
157         emake -j1
158         use doc && emake -C doc html
159 }
160
161 src_test() {
162         if [[ ${EUID} == 0 ]]; then
163                 eerror "You cannot run tests as root."
164                 eerror "Please enable FEATURES=userpriv before proceeding."
165                 return 1
166         fi
167
168         local testtargets="test-common test-node test-plugins"
169         use minimal || testtargets+=" test-master"
170
171         LC_ALL=C emake -j1 ${testtargets}
172 }
173
174 src_install() {
175         local dirs="
176                 /var/log/munin
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
181                 /etc/munin/plugins"
182         use minimal || dirs+=" /etc/munin/munin-conf.d/"
183
184         keepdir ${dirs}
185         fowners munin:munin ${dirs}
186
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)
190
191         # we remove /run from the install, as it's not the package's to deal
192         # with.
193         rm -rf "${D}"/run || die
194
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
198
199         insinto /etc/munin/plugin-conf.d/
200         newins "${FILESDIR}"/${PN}-1.3.2-plugins.conf munin-node
201
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
204
205         newinitd "${FILESDIR}"/munin-asyncd.init.2 munin-asyncd
206
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 - -
210         EOF
211
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
216
217         cat >> "${T}"/munin.env <<- EOF
218         CONFIG_PROTECT=/var/spool/munin-async/.ssh
219         EOF
220         newenvd "${T}"/munin.env 50munin
221
222         dodoc README ChangeLog INSTALL
223         if use doc; then
224                 cd "${S}"/doc/_build/html || die
225                 docinto html
226                 dodoc -r *
227                 cd "${S}" || die
228         fi
229
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
233
234         dosym ipmi_ /usr/libexec/munin/plugins/ipmi_sensor_
235
236         if use syslog; then
237                 sed -i -e '/log_file/s| .*| Sys::Syslog|' \
238                         "${D}"/etc/munin/munin-node.conf || die
239         fi
240
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
243         # privileges.
244         sed -i -e 's:/run/munin/munin-node.pid:/run/munin-node.pid:' \
245                 "${D}"/etc/munin/munin-node.conf || die
246
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
252
253         if use minimal; then
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
257         else
258                 # remove font files so that we don't have to keep them around
259                 rm "${D}"/usr/libexec/${PN}/*.ttf || die
260
261                 if use cgi; then
262                         sed -i -e '/#graph_strategy cgi/s:^#::' "${D}"/etc/munin/munin.conf || die
263
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
269
270                         if use apache2; then
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
274                         fi
275                 else
276                         sed \
277                                 -e '/#graph_strategy cgi/s:#graph_strategy cgi:graph_strategy cron:' \
278                                 -i "${D}"/etc/munin/munin.conf || die
279                 fi
280
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
285                 EOF
286
287                 fowners munin:munin /var/lib/munin/.ssh/{,config}
288                 fperms go-rwx /var/lib/munin/.ssh/{,config}
289
290                 dodir /usr/share/${PN}
291                 cat >> "${D}"/usr/share/${PN}/crontab <<- EOF
292                 # Force the shell to bash
293                 SHELL=/bin/bash
294                 # Mail reports to root@, not munin@
295                 MAILTO=root
296
297                 # This runs the munin task every 5 minutes.
298                 */5     * * * *         /usr/bin/munin-cron
299
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
309                 EOF
310
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)
314
315                 # This runs the munin task every 5 minutes.
316                 @ 5             /usr/bin/munin-cron
317
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
327                 EOF
328
329                 # remove .htaccess file
330                 find "${D}" -name .htaccess -delete || die
331         fi
332 }
333
334 pkg_config() {
335         if use minimal; then
336                 einfo "Nothing to do."
337                 return 0
338         fi
339
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."
343         read
344
345         ebegin "Setting up cron ..."
346         if has_version sys-process/fcron; then
347                 fcrontab - -u munin < /usr/share/${PN}/fcrontab
348         else
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
352         fi
353         eend $?
354
355         einfo "Press enter to set up the SSH keys used for SSH transport"
356         read
357
358         # generate one rsa (for legacy) and one ecdsa (for new systems)
359         ssh-keygen -t rsa \
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
367
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"
372         echo
373         cat /var/lib/munin/.ssh/id_*.pub
374 }
375
376 pkg_postinst() {
377         elog "Please follow the munin documentation to set up the plugins you"
378         elog "need, afterwards start munin-node."
379         elog ""
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"
382         elog ""
383         if ! use minimal; then
384                 elog "Please run"
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."
388         fi
389         elog ""
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"
392
393         if use cgi; then
394                 chown $(usex apache2 apache munin) \
395                         "${ROOT}"/var/cache/munin-cgi \
396                         "${ROOT}"/var/log/munin/munin-cgi-{graph,html}.log
397
398                 if use apache2; then
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."
404                 else
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."
407                 fi
408         fi
409
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
416         fi
417 }