Use https by default
[gentoo.git] / net-analyzer / munin / munin-2.0.19.ebuild
1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 EAPI=5
6
7 PATCHSET=1
8
9 inherit eutils user java-pkg-opt-2 systemd
10
11 MY_P=${P/_/-}
12
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"
17
18 LICENSE="GPL-2"
19 SLOT="0"
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 )"
23
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
34                                          dev-perl/Cache-Cache
35                                          dev-perl/DBD-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 )
43                         dhcpd? (
44                                 >=net-misc/dhcp-3[server]
45                                 dev-perl/Net-IP
46                                 dev-perl/HTTP-Date
47                         )
48                         dev-perl/DBI
49                         dev-perl/DateManip
50                         dev-perl/File-Copy-Recursive
51                         dev-perl/List-MoreUtils
52                         dev-perl/Log-Log4perl
53                         dev-perl/Net-CIDR
54                         dev-perl/Net-DNS
55                         dev-perl/Net-Netmask
56                         dev-perl/Net-SNMP
57                         dev-perl/net-server[ipv6(-)?]
58                         virtual/perl-Digest-MD5
59                         virtual/perl-Getopt-Long
60                         virtual/perl-MIME-Base64
61                         virtual/perl-Storable
62                         virtual/perl-Text-Balanced
63                         virtual/perl-Time-HiRes
64                         !minimal? (
65                                 dev-perl/HTML-Template
66                                 dev-perl/IO-Socket-INET6
67                                 dev-perl/URI
68                                 >=net-analyzer/rrdtool-1.3[graph,perl]
69                                 virtual/ssh
70                         )"
71
72 # Keep this seperate, as previous versions have had other deps here
73 DEPEND="${DEPEND_COM}
74         dev-perl/Module-Build
75         java? ( >=virtual/jdk-1.5 )
76         test? (
77                 dev-perl/Test-Deep
78                 dev-perl/Test-LongString
79                 dev-perl/Test-Differences
80                 dev-perl/Test-MockModule
81                 dev-perl/Test-MockObject
82                 dev-perl/File-Slurp
83                 dev-perl/IO-stringy
84                 dev-perl/IO-Socket-INET6
85         )"
86 RDEPEND="${DEPEND_COM}
87                 virtual/awk
88                 ipmi? ( >=sys-libs/freeipmi-1.1.6-r1 )
89                 java? (
90                         >=virtual/jre-1.5
91                         || ( net-analyzer/netcat6 net-analyzer/netcat )
92                 )
93                 !minimal? (
94                         virtual/cron
95                         media-fonts/dejavu
96                 )
97                 !<sys-apps/openrc-0.11.8"
98
99 S="${WORKDIR}/${MY_P}"
100
101 pkg_setup() {
102         enewgroup munin
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
107 }
108
109 src_prepare() {
110         epatch "${WORKDIR}"/patches/*.patch
111
112         java-pkg-opt-2_src_prepare
113 }
114
115 src_configure() {
116         local cgidir='$(DESTDIR)/usr/libexec/munin/cgi'
117         use cgi || cgidir="${T}/useless/cgi-bin"
118
119         local cgiuser=$(usex apache apache munin)
120
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
128 CGIDIR=${cgidir}
129 CGITMPDIR=\$(DESTDIR)/var/cache/munin-cgi
130 CGIUSER=${cgiuser}
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
138 EOF
139 }
140
141 # parallel make and install need to be fixed before, and I haven't
142 # gotten around to do so yet.
143 src_compile() {
144         emake -j1
145         if use doc; then
146                 emake -C doc html
147         fi
148 }
149
150 src_test() {
151         if [[ ${EUID} == 0 ]]; then
152                 eerror "You cannot run tests as root."
153                 eerror "Please enable FEATURES=userpriv before proceeding."
154                 return 1
155         fi
156
157         local testtargets="test-common test-node test-plugins"
158         use minimal || testtargets+=" test-master"
159
160         LC_ALL=C emake -j1 ${testtargets}
161 }
162
163 src_install() {
164         local dirs="
165                 /var/log/munin
166                 /var/lib/munin/plugin-state
167                 /etc/munin/plugin-conf.d
168                 /etc/munin/plugins"
169         use minimal || dirs+=" /etc/munin/munin-conf.d/"
170
171         keepdir ${dirs}
172         fowners munin:munin ${dirs}
173
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)
177
178         # we remove /run from the install, as it's not the package's to deal
179         # with.
180         rm -rf "${D}"/run
181
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
185
186         insinto /etc/munin/plugin-conf.d/
187         newins "${FILESDIR}"/${PN}-1.3.2-plugins.conf munin-node
188
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
191
192         newinitd "${FILESDIR}"/munin-asyncd.init.2 munin-asyncd
193
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 - -
197 EOF
198
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
203
204         cat - >> "${T}"/munin.env <<EOF
205 CONFIG_PROTECT=/var/spool/munin-async/.ssh
206 EOF
207         newenvd "${T}"/munin.env 50munin
208
209         dodoc README ChangeLog INSTALL
210         if use doc; then
211                 cd "${S}"/doc/_build/html
212                 dohtml -r *
213                 cd "${S}"
214         fi
215
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
219
220         dosym ipmi_ /usr/libexec/munin/plugins/ipmi_sensor_
221
222         if use syslog; then
223                 sed -i -e '/log_file/s| .*| Sys::Syslog|' \
224                         "${D}"/etc/munin/munin-node.conf || die
225         fi
226
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
229         # privileges.
230         sed -i -e 's:/run/munin/munin-node.pid:/run/munin-node.pid:' \
231                 "${D}"/etc/munin/munin-node.conf || die
232
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
238
239         if use minimal; then
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
243         else
244                 # remove font files so that we don't have to keep them around
245                 rm "${D}"/usr/libexec/${PN}/*.ttf || die
246
247                 if use cgi; then
248                         sed -i -e '/#graph_strategy cgi/s:^#::' "${D}"/etc/munin/munin.conf || die
249
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
255
256                         if use apache; then
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
260                         fi
261                 else
262                         sed -i -e '/#graph_strategy cgi/s:#graph_strategy cgi:graph_strategy cron:' "${D}"/etc/munin/munin.conf || die
263                 fi
264
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
269 EOF
270
271                 fowners munin:munin /var/lib/munin/.ssh/{,config}
272                 fperms go-rwx /var/lib/munin/.ssh/{,config}
273
274                 dodir /usr/share/${PN}
275                 cat - >> "${D}"/usr/share/${PN}/crontab <<EOF
276 # Force the shell to bash
277 SHELL=/bin/bash
278 # Mail reports to root@, not munin@
279 MAILTO=root
280
281 # This runs the munin task every 5 minutes.
282 */5     * * * *         /usr/bin/munin-cron
283
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
293 EOF
294
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)
298
299 # This runs the munin task every 5 minutes.
300 @ 5             /usr/bin/munin-cron
301
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
311 EOF
312
313                 # remove .htaccess file
314                 find "${D}" -name .htaccess -delete || die
315         fi
316 }
317
318 pkg_config() {
319         if use minimal; then
320                 einfo "Nothing to do."
321                 return 0
322         fi
323
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."
327         read
328
329         ebegin "Setting up cron ..."
330         if has_version sys-process/fcron; then
331                 fcrontab - -u munin < /usr/share/${PN}/fcrontab
332         else
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
336         fi
337         eend $?
338
339         einfo "Press enter to set up the SSH keys used for SSH transport"
340         read
341
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
347
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"
352         echo
353         cat /var/lib/munin/.ssh/id_*.pub
354 }
355
356 pkg_postinst() {
357         elog "Please follow the munin documentation to set up the plugins you"
358         elog "need, afterwards start munin-node."
359         elog ""
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"
362         elog ""
363         if ! use minimal; then
364                 elog "Please run"
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."
368         fi
369         elog ""
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"
372
373         if use cgi; then
374                 chown $(usex apache apache munin) \
375                         "${ROOT}"/var/cache/munin-cgi \
376                         "${ROOT}"/var/log/munin/munin-cgi-{graph,html}.log
377
378                 if use apache; then
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."
384                 else
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."
387                 fi
388         fi
389
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
396         fi
397 }