diff options
author | Mike Frysinger <vapier@gentoo.org> | 2015-07-23 02:57:41 +0000 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2015-07-23 02:57:41 +0000 |
commit | e2f06c2f1af398f5b2023980801938bab046ed8a (patch) | |
tree | 3f068a89996e497aa117d2373cc691308518f6cb /sys-process | |
parent | Use err level when logging failed scripts #540274 by Tobias Klausmann. (diff) | |
download | gentoo-2-e2f06c2f1af398f5b2023980801938bab046ed8a.tar.gz gentoo-2-e2f06c2f1af398f5b2023980801938bab046ed8a.tar.bz2 gentoo-2-e2f06c2f1af398f5b2023980801938bab046ed8a.zip |
Rewrite run-crons in POSIX shell #530416 by Alexander Hof.
(Portage version: 2.2.20/cvs/Linux x86_64, signed Manifest commit with key D2E96200)
Diffstat (limited to 'sys-process')
-rw-r--r-- | sys-process/cronbase/ChangeLog | 8 | ||||
-rw-r--r-- | sys-process/cronbase/cronbase-0.3.6.ebuild | 33 | ||||
-rwxr-xr-x | sys-process/cronbase/files/run-crons-0.3.6 | 133 |
3 files changed, 173 insertions, 1 deletions
diff --git a/sys-process/cronbase/ChangeLog b/sys-process/cronbase/ChangeLog index 051b114c74fd..afcffe2fdf33 100644 --- a/sys-process/cronbase/ChangeLog +++ b/sys-process/cronbase/ChangeLog @@ -1,6 +1,12 @@ # ChangeLog for sys-process/cronbase # Copyright 1999-2015 Gentoo Foundation; Distributed under the GPL v2 -# $Header: /var/cvsroot/gentoo-x86/sys-process/cronbase/ChangeLog,v 1.45 2015/07/23 02:53:54 vapier Exp $ +# $Header: /var/cvsroot/gentoo-x86/sys-process/cronbase/ChangeLog,v 1.46 2015/07/23 02:57:41 vapier Exp $ + +*cronbase-0.3.6 (23 Jul 2015) + + 23 Jul 2015; Mike Frysinger <vapier@gentoo.org> +cronbase-0.3.6.ebuild, + +files/run-crons-0.3.6: + Rewrite run-crons in POSIX shell #530416 by Alexander Hof. *cronbase-0.3.5-r1 (23 Jul 2015) diff --git a/sys-process/cronbase/cronbase-0.3.6.ebuild b/sys-process/cronbase/cronbase-0.3.6.ebuild new file mode 100644 index 000000000000..f55599bc6681 --- /dev/null +++ b/sys-process/cronbase/cronbase-0.3.6.ebuild @@ -0,0 +1,33 @@ +# Copyright 1999-2015 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Header: /var/cvsroot/gentoo-x86/sys-process/cronbase/cronbase-0.3.6.ebuild,v 1.1 2015/07/23 02:57:41 vapier Exp $ + +EAPI="5" + +inherit user + +DESCRIPTION="base for all cron ebuilds" +HOMEPAGE="http://www.gentoo.org/" + +LICENSE="GPL-2" +SLOT="0" +KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86 ~amd64-fbsd ~sparc-fbsd ~x86-fbsd" +IUSE="" + +S=${WORKDIR} + +pkg_setup() { + enewgroup cron 16 + enewuser cron 16 -1 /var/spool/cron cron +} + +src_install() { + newsbin "${FILESDIR}"/run-crons-${PV} run-crons + + diropts -m0750 + keepdir /etc/cron.{hourly,daily,weekly,monthly} + + keepdir /var/spool/cron/lastrun + diropts -m0750 -o root -g cron + keepdir /var/spool/cron +} diff --git a/sys-process/cronbase/files/run-crons-0.3.6 b/sys-process/cronbase/files/run-crons-0.3.6 new file mode 100755 index 000000000000..fdd54753d5cd --- /dev/null +++ b/sys-process/cronbase/files/run-crons-0.3.6 @@ -0,0 +1,133 @@ +#!/bin/sh +# +# $Header: /var/cvsroot/gentoo-x86/sys-process/cronbase/files/run-crons-0.3.6,v 1.1 2015/07/23 02:57:41 vapier Exp $ +# +# 12 Oct 2008; Thilo Bangert <bangert@gentoo.org> run-crons: +# ignore emacs backup files (bug #237200) +# include logging patch (bug #140869) +# +# 08 Mar 2005; Aaron Walker <ka0ttic@gentoo.org> run-crons: +# Ignore the error messages from find caused by race conditions, since +# we could care less about the error as long as the file has been removed. +# See bug 8506. +# +# 06 May 2004; Aron Griffis <agriffis@gentoo.org> run-crons: +# Make the locking actually work. The old code was racy. +# Thanks to Mathias Gumz in bug 45155 for some cleanups. +# +# 23 Jun 2002; Jon Nelson <jnelson@gentoo.org> run-crons: +# fixed a race condition, where cron jobs and run-crons wanted to +# delete touch files +# +# 20 Apr 2002; Thilo Bangert <bangert@gentoo.org> run-crons: +# moved lastrun directory to /var/spool/cron/lastrun +# +# Author: Achim Gottinger <achim@gentoo.org> +# +# Mostly copied from SuSE +# +# this script looks into /etc/cron.[hourly|daily|weekly|monthly] +# for scripts to be executed. The info about last run is stored in +# /var/spool/cron/lastrun + +LOCKDIR=/var/spool/cron/lastrun +LOCKFILE=${LOCKDIR}/lock + +# Usage: log <level> <args to logger> +# Log a message via syslog. +log() { + local level="$1" + shift + logger -i -p "cron.${level}" -t run-crons "$@" +} + +mkdir -p ${LOCKDIR} + +# Make sure we're not running multiple instances at once. +# Try twice to lock, otherwise give up. +i=0 +while [ $(( i += 1 )) -le 2 ] ; do + ln -sn $$ ${LOCKFILE} 2>/dev/null && break + + # lock failed, check for a running process. + # handle both old- and new-style locking. + cronpid=$(readlink ${LOCKFILE} 2>/dev/null) || + cronpid=$(cat ${LOCKFILE} 2>/dev/null) || + continue # lockfile disappeared? try again + + # better than kill -0 because we can verify that it's really + # another run-crons process + cmdline1=$(cat /proc/${cronpid}/cmdline 2>/dev/null) || : + cmdline2=$(cat /proc/$$/cmdline) + if [ "${cmdline1}" = "${cmdline2}" ] ; then + # whoa, another process is really running + exit 0 + else + rm -f ${LOCKFILE} + fi +done + +# Check to make sure locking was successful +if [ ! -L "${LOCKFILE}" ] ; then + echo "Can't create or read existing ${LOCKFILE}, giving up" + exit 1 +fi + +# Set a trap to remove the lockfile when we're finished +trap "rm -f ${LOCKFILE}" EXIT HUP INT QUIT TERM + + +EXIT_STATUS=0 +for BASE in hourly daily weekly monthly ; do + CRONDIR=/etc/cron.${BASE} + + test -d $CRONDIR || continue + + if [ -e ${LOCKDIR}/cron.$BASE ] ; then + case $BASE in + hourly) + #>= 1 hour, 5 min -=> +65 min + TIME="-cmin +65" ;; + daily) + #>= 1 day, 5 min -=> +1445 min + TIME="-cmin +1445" ;; + weekly) + #>= 1 week, 5 min -=> +10085 min + TIME="-cmin +10085" ;; + monthly) + #>= 31 days, 5 min -=> +44645 min + TIME="-cmin +44645" ;; + esac + + find ${LOCKDIR} -name cron.$BASE $TIME -exec rm {} \; 2>/dev/null || : + fi + + # if there is no touch file, make one then run the scripts + if [ ! -e ${LOCKDIR}/cron.$BASE ] ; then + touch ${LOCKDIR}/cron.$BASE + + set +e + for SCRIPT in $CRONDIR/* ; do + if [ -x "${SCRIPT}" ] && [ ! -d "${SCRIPT}" ] ; then + # Filter out files people do not expect to be executed. + case ${SCRIPT} in + .*|*~) continue ;; + esac + + log info "($(whoami)) CMD (${SCRIPT})" + $SCRIPT + ret=$? + if [ ${ret} -ne 0 ] ; then + log err "CMD (${SCRIPT}) failed with exit status ${ret}" + EXIT_STATUS=1 + fi + fi + done + fi +done + +# Clean out bogus cron.$BASE files with future times +touch ${LOCKDIR} +find ${LOCKDIR} -newer ${LOCKDIR} -exec /bin/rm -f {} \; 2>/dev/null || : + +exit ${EXIT_STATUS} |