sysutils/munin-{master,node}: change cron job install

Don't rely on directly calling crontab(1) to install the cron job, use
the etc/cron.d directory for which we've had support for a while. This
fixes installing munin-master using pkg -r as crontab(1) installed the
cron job on the host system not in the specified alternative root
otherwise.

Completely remove pkg-install, that also removes the automatic migration
for newsyslog files after src revision r340318 it's been 4 years and a
bit.

Leave the pkg-deinstall script for a while to make sure that the
automatically installed cron jobs via crontab(1) are removed.

PR:		258072
Reported by:	Tassilo Philipp <tphilipp@potion-studios.com>
Tested by:	Tassilo Philipp <tphilipp@potion-studios.com>
This commit is contained in:
Florian Smeets 2023-01-29 23:17:24 +01:00
parent 32a94e5a53
commit 02388ae491
7 changed files with 6 additions and 183 deletions

View File

@ -1,5 +1,6 @@
PORTNAME= munin
PORTVERSION= ${MUNIN_VERSION}
PORTREVISION= 1
CATEGORIES= sysutils perl5
MASTER_SITES= ${MUNIN_SITES}
PKGNAMESUFFIX= -master
@ -57,5 +58,7 @@ post-install:
(cd ${STAGEDIR}${ETCDIR}; for i in `find . -type f`; do mv $$i $$i.sample; done)
${MV} ${STAGEDIR}${WWWDIR}/.htaccess ${STAGEDIR}${WWWDIR}/.htaccess.sample
${INSTALL_DATA} ${FILESDIR}/newsyslog ${STAGEDIR}${ETCDIR}/munin-master.newsyslog
${MKDIR} ${STAGEDIR}${LOCALBASE}/etc/cron.d
${INSTALL_DATA} ${FILESDIR}/cron ${STAGEDIR}${ETCDIR}/munin-master.cron
.include <bsd.port.mk>

View File

@ -0,0 +1 @@
*/5 * * * * munin /usr/local/bin/munin-cron

View File

@ -8,29 +8,7 @@ Please edit it according to your needs.
The Munin server will be run from cron under the user 'munin'.
If you need to customize the munin crontab, remove the lines
containing #BEGIN_MUNIN_MAIN and #END_MUNIN_MAIN, and add a line
with #MANUAL_MUNIN_CRONTAB.
EOT
type: install
}
{
message: <<EOT
The munin-master newsyslog.conf(5) filename has been changed:
OLD: ${PREFIX}/etc/newsyslog.conf.d/munin-master
NEW: ${PREFIX}/etc/newsyslog.conf.d/munin-master.conf
Any file found at the old location has been automatically moved to
the new location. This was done to ensure log rotation continued to
work after change r340318 made to FreeBSD base, where the default
newsyslog configuration now only includes filenames that end with
'.conf' and do not begin with '.'.
If you use provisioning/configuration management tools to create or
edit this file, you will need to change their configuration to use
the new filename.
EOT
type: upgrade
maximum_version: "2.0.43_1"
}
]

View File

@ -1,100 +0,0 @@
#! /bin/sh
# ex:sw=4 sts=4
ask() {
local question default answer
question=$1
default=$2
if [ -z "${PACKAGE_BUILDING}" -a -z "${BATCH}" ]
then
read -p "${question} [${default}]? " answer
fi
if [ x${answer} = x ]
then
answer=${default}
fi
echo ${answer}
}
yesno() {
local dflt question answer
question=$1
dflt=$2
while :; do
answer=$(ask "${question}" "${dflt}")
case "${answer}" in
[Yy]*) return 0;;
[Nn]*) return 1;;
esac
echo "Please answer yes or no."
done
}
create_crontab_entries() {
local b e
b=$1
e=$2
if crontab -u munin -l > /dev/null 2>&1
then
if ! crontab -u munin -l | grep -q MANUAL_MUNIN_CRONTAB
then
TMPFILE=`mktemp -t munin` || exit 1
cat > $TMPFILE
crontab -u munin -l | sed -e "/^$b$/,/^$e$/d" | \
cat - $TMPFILE | crontab -u munin -
rm $TMPFILE
fi
else
crontab -u munin -
fi
}
move_www_dir() {
if [ -d ${PKG_PREFIX}/www/data/munin -a ! -d ${PKG_PREFIX}/www/munin ]
then
echo Migrating ${PKG_PREFIX}/www/data/munin to ${PKG_PREFIX}/www/munin
mv ${PKG_PREFIX}/www/data/munin ${PKG_PREFIX}/www/munin
fi
}
move_newsyslog_conf() {
oldfile=${PKG_PREFIX}/etc/newsyslog.conf.d/munin-master
newfile=${PKG_PREFIX}/etc/newsyslog.conf.d/munin-master.conf
samplefile=${PKG_PREFIX}/etc/munin/munin-master.newsyslog
if [ -f ${oldfile} ]; then
echo "Configuration file found in old location: ${oldfile}"
if cmp -s ${samplefile} ${newfile} > /dev/null; then
echo "Configuration file in new location has not been modified from the default: ${newfile}"
echo " => Moving old configuration file to new location"
mv -f ${oldfile} ${newfile}
else
echo "Configuration file in new location has been modified from the default: ${newfile}"
echo " => Deleting old configuration file"
rm ${oldfile}
fi
fi
}
########################################################################
case $2 in
PRE-INSTALL)
move_www_dir # at some point in the installation, the www dir is created
;;
POST-INSTALL)
if [ -z "${PACKAGE_BUILDING}" ]
then
create_crontab_entries '#BEGIN_MUNIN_MAIN' '#END_MUNIN_MAIN' <<EOT
#BEGIN_MUNIN_MAIN
MAILTO=root
*/5 * * * * ${PKG_PREFIX}/bin/munin-cron
#END_MUNIN_MAIN
EOT
fi
move_newsyslog_conf
;;
esac

View File

@ -37,7 +37,9 @@ bin/munin-cron
@comment BSD.local.dist but if not registered here, it will not exist in PREFIX
@comment when the package is installed.
@dir etc/newsyslog.conf.d
@dir etc/cron.d
@sample %%ETCDIR%%/munin-master.newsyslog etc/newsyslog.conf.d/munin-master.conf
@sample %%ETCDIR%%/munin-master.cron etc/cron.d/munin-master.conf
%%SITE_PERL%%/Munin/Master/Config.pm
%%SITE_PERL%%/Munin/Master/GraphOld.pm
%%SITE_PERL%%/Munin/Master/Group.pm

View File

@ -27,23 +27,4 @@ to install the plugins automatically
EOT
type: install
}
{
message: <<EOT
The munin-node newsyslog.conf(5) filename has been changed:
OLD: ${PREFIX}/etc/newsyslog.conf.d/munin-node
NEW: ${PREFIX}/etc/newsyslog.conf.d/munin-node.conf
Any file found at the old location has been automatically moved to
the new location. This was done to ensure log rotation continued to
work after change r340318 made to FreeBSD base, where the default
newsyslog configuration now only includes filenames that end with
'.conf' and do not begin with '.'.
If you use provisioning/configuration management tools to create or
edit this file, you will need to change their configuration to use
the new filename.
EOT
type: upgrade
maximum_version: "2.0.43_1"
}
]

View File

@ -1,42 +0,0 @@
#! /bin/sh
init_plugins() {
if [ -f /tmp/.munin-node.version ]; then
prevver=$(cat /tmp/.munin-node.version)
fi
if [ -n "$prevver" ]; then
echo -n "Initializing new plugins.."
${PKG_PREFIX}/sbin/munin-node-configure --shell --newer "${prevver%-*}" | sh -x
fi
echo "done."
}
move_newsyslog_conf() {
oldfile=${PKG_PREFIX}/etc/newsyslog.conf.d/munin-node
newfile=${PKG_PREFIX}/etc/newsyslog.conf.d/munin-node.conf
samplefile=${PKG_PREFIX}/etc/munin/munin-node.newsyslog
if [ -f ${oldfile} ]; then
echo "Configuration file found in old location: ${oldfile}"
if cmp -s ${samplefile} ${newfile} > /dev/null; then
echo "Configuration file in new location has not been modified from the default: ${newfile}"
echo " => Moving old configuration file to new location"
mv -f ${oldfile} ${newfile}
else
echo "Configuration file in new location has been modified from the default: ${newfile}"
echo " => Deleting old configuration file"
rm ${oldfile}
fi
fi
}
########################################################################
case $2 in
POST-INSTALL)
if [ -z "${PACKAGE_BUILDING}" ]; then
init_plugins
fi
move_newsyslog_conf
;;
esac