diff options
Diffstat (limited to 'sys-process/cronbase')
-rw-r--r-- | sys-process/cronbase/Manifest | 5 | ||||
-rw-r--r-- | sys-process/cronbase/cronbase-0.3.7-r6.ebuild | 32 | ||||
-rwxr-xr-x | sys-process/cronbase/files/run-crons-0.3.7 | 180 | ||||
-rw-r--r-- | sys-process/cronbase/metadata.xml | 8 |
4 files changed, 225 insertions, 0 deletions
diff --git a/sys-process/cronbase/Manifest b/sys-process/cronbase/Manifest new file mode 100644 index 000000000000..087c709d265d --- /dev/null +++ b/sys-process/cronbase/Manifest @@ -0,0 +1,5 @@ +AUX run-crons-0.3.7 4942 SHA256 754031268ed164151214cdc97d02037e6820d0233b9e16fc9f433ad481737b76 SHA512 eb4f298fb67d7ff3e82d19e6a27f3f1df4b1abab86bd78f3ea85aecaead42a6c194773c21d63d081b62b0eb45cf2bdeb78b43b58906500e6bb52613f7e6bf164 WHIRLPOOL 397f9a4fbf5c711876683c8defc0f926cce9c924b481dfd542b43e6bb6ed2249adfec1446261a254aef215db39fe09c430e27b26fbad200b525a071875b2476f +EBUILD cronbase-0.3.7-r6.ebuild 674 SHA256 687e7fffb3e8aeeb17cc2df41cca588e4b677bf5d7b7f272b97c3cceca8da408 SHA512 521c30e7e1f15e03dd219c71db14f4059e7da09b480ab89aa7d7bda63eade23d7e233ae0d20bb1867155d20a9fd192a5396d9468305bd9216e8e821e53b404ef WHIRLPOOL 0a5b55587c41820b3b164423dacf5b6adfbd734972d610055000b2d15ccc4412195e9bccb3ba0b48186a80d834e9bfc9b8f378b4c1475ec8b6a8c06b320756da +MISC ChangeLog 7428 SHA256 0058771019043b1abd1c5be4392beb79e2ab7284bf9a40f40e39a319e61bf12d SHA512 660db6cb578cfdeaa7bb7d31dd48fab556d5100ee86d69d55bbde6c551c3ec88899dddf8790d27141066c2873ae5b5ba2b1d7a6e88b924cc818c1d3bd8856400 WHIRLPOOL 805b2bf4fad8966b17d6931224098965583eabd8926c7f0ab6d978a866de6739294d30ffdcefa23a711e10f961794f3eeee8291ccab151f30a51c7cc530bf4aa +MISC ChangeLog-2015 10155 SHA256 6ca4671a8fdcea64b815e49041f04b8c26f094bd068ef458d023e75641a112f2 SHA512 d6f3a9c42782f219f20ba07206a468e3f741ec1438bf5cf5cd769248df14c515ecd6d4f3291dfce78bf935aa56e48d096081285ce495dd684417d6f3bd87d0ac WHIRLPOOL 9a0008fe146ca2285a116aa9c9fde8fb681772f14c3c4c8ad735e21ace90442faae31dc39b700e7e372953ebb87c5f0923ac12c34225f76900663940ec704ed0 +MISC metadata.xml 256 SHA256 cbca1ae57df68811dc0f0eeceb7449e69bc046966ad0feff3279e148f7db2f18 SHA512 155f3cbb14ae54e9dfb98e954f6bdf7f23bf5654ae2d00549f7722085a7243d934dfd99d6f1325b00dcaeb50c5344e818e602dc4e2fe47dc7aeb1fdb77668521 WHIRLPOOL 37d54b13f923df58d35217014422b6b484597ce1f80f39a4c6d8a4906d3c5dff6d8c4e14972abb5bdc3a041006c5b691d1d284dbcab35bdffd0e6a013c110215 diff --git a/sys-process/cronbase/cronbase-0.3.7-r6.ebuild b/sys-process/cronbase/cronbase-0.3.7-r6.ebuild new file mode 100644 index 000000000000..f571702f9ed7 --- /dev/null +++ b/sys-process/cronbase/cronbase-0.3.7-r6.ebuild @@ -0,0 +1,32 @@ +# Copyright 1999-2015 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +EAPI="5" + +inherit user + +DESCRIPTION="base for all cron ebuilds" +HOMEPAGE="https://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.7 b/sys-process/cronbase/files/run-crons-0.3.7 new file mode 100755 index 000000000000..42c88100df1c --- /dev/null +++ b/sys-process/cronbase/files/run-crons-0.3.7 @@ -0,0 +1,180 @@ +#!/bin/sh +# Copyright 1999-2015 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# +# 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/lock" +CRONSPOOLDIR="/var/spool/cron" +LASTRUNDIR="${CRONSPOOLDIR}/lastrun" +# This is the legacy lockfile that we need to clean up. +GLOBAL_LOCKFILE="${LASTRUNDIR}/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 "$@" +} + +# Usage: grab_lock <class> +# Grab the lock for <class> to make sure we are the only instance. +grab_lock() { + local i cronpid cmdline1 cmdline2 + local lockfile + + # Free whatever previous lock (if any) we held. + free_lock + + # For the legacy global lock, don't try to create a full path. + case $1 in + /*) lockfile=$1 ;; + *) lockfile="${LOCKDIR}/cron.$1" ;; + esac + + # Try twice to lock, otherwise give up. + i=0 + while [ $(( i += 1 )) -le 2 ] ; do + # Normally we should be able to grab the lock and get out of here fast. + if ln -sn $$ "${lockfile}" 2>/dev/null ; then + break + fi + + # Locking failed, so check for a running process. + # Handle both old- and new-style locking. + # Delete the cat logic when GLOBAL_LOCKFILE is purged. + # Note: Does not handle PID namespaces ... + if ! cronpid=$(readlink "${lockfile}" 2>/dev/null) ; then + if ! cronpid=$(cat "${lockfile}" 2>/dev/null) ; then + # The lockfile disappeared? Try the whole thing again ... + continue + fi + fi + + # This is better than kill -0 because we can verify that it's really + # another run-crons process. + # We have to send stderr to /dev/null for two reasons: + # - If the process disappears, the cmdline file might not exist. + # - The cmdline file contains NUL bytes, but bash-4.4+ warns when + # you try to assign NUL bytes to variables. + # It'd be nice to not do it for a lot of code, but there's not easy + # alternative in shell code. We could `cat | tr`, but that'd waste + # a bit more than just a simple cat. + if ( + cmdline1=$(cat "/proc/${cronpid}/cmdline") || : + cmdline2=$(cat "/proc/$$/cmdline") + [ "${cmdline1}" = "${cmdline2}" ] + ) 2>/dev/null ; then + # Whoa, another run-crons is really running. + return 1 + fi + + # The lockfile is pointing to a dead process so break it. + # TODO: This is still racy if we're running more than one run-crons. + rm -f "${lockfile}" + 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 the lock file for free_lock to clean up. + _LOCKFILE="${lockfile}" + + return 0 +} +# Prevent random env vars from messing with us. +_LOCKFILE= +# Set a trap to release the lockfile when we're finished. +trap 'free_lock' EXIT HUP INT QUIT TERM + +# Usage: free_lock +# Release the lock that we last grabbed. This does not nest! +free_lock() { + if [ -n "${_LOCKFILE}" ] ; then + rm -f "${_LOCKFILE}" + # Only break the lock once. + _LOCKFILE= + fi +} + + +EXIT_STATUS=0 + +# Grab the legacy global lock to smoothly handle upgrades. +# We should drop this after like Dec 2016. +if [ -L "${GLOBAL_LOCKFILE}" -o -f "${GLOBAL_LOCKFILE}" ] ; then + if ! grab_lock "${GLOBAL_LOCKFILE}" ; then + # An old process is still running -- abort. + exit 0 + fi + # Now release the lock since we no longer care about it. + free_lock +fi + +for BASE in hourly daily weekly monthly ; do + CRONDIR=/etc/cron.${BASE} + + test -d $CRONDIR || continue + + # Grab the lock for this specific dir. + if ! grab_lock "${BASE}" ; then + # Someone else is processing this dir, so skip it. + continue + fi + + # Blow away stale states for this particular dir. + lastrunfile="${LASTRUNDIR}/cron.${BASE}" + if [ -e "${lastrunfile}" ] ; 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 "${LASTRUNDIR}/" -name cron.$BASE $TIME -exec rm {} \; 2>/dev/null || : + fi + + # if there is no state file, make one, then run the scripts. + if [ ! -e "${lastrunfile}" ] ; then + touch "${lastrunfile}" + + 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 state files with future times. +touch "${LASTRUNDIR}" +find "${LASTRUNDIR}/" -newer "${LASTRUNDIR}" -exec /bin/rm -f {} \; 2>/dev/null || : + +exit ${EXIT_STATUS} diff --git a/sys-process/cronbase/metadata.xml b/sys-process/cronbase/metadata.xml new file mode 100644 index 000000000000..a22ac52b016b --- /dev/null +++ b/sys-process/cronbase/metadata.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd"> +<pkgmetadata> + <maintainer type="project"> + <email>cron-bugs@gentoo.org</email> + <name>Gentoo Cron Project</name> + </maintainer> +</pkgmetadata> |