From 693de8055d60cf758543da295991fff5f7082046 Mon Sep 17 00:00:00 2001 From: medina474 Date: Thu, 2 Oct 2025 10:16:03 +0200 Subject: [PATCH] etc/cron --- etc/cron.d/.placeholder | 2 + etc/cron.d/e2scrub_all | 2 + etc/cron.d/php | 14 ++ etc/cron.d/popularity-contest | 3 + etc/cron.daily/.placeholder | 2 + etc/cron.daily/apache2 | 25 +++ etc/cron.daily/apt-compat | 55 +++++ etc/cron.daily/backup-mariadb | 34 +++ etc/cron.daily/dpkg | 8 + etc/cron.daily/logrotate | 18 ++ etc/cron.daily/popularity-contest | 200 ++++++++++++++++++ .../prestashop-rebuild-search-index | 1 + etc/cron.hourly/.placeholder | 2 + etc/cron.monthly/.placeholder | 2 + etc/cron.weekly/.placeholder | 2 + etc/cron.yearly/.placeholder | 2 + 16 files changed, 372 insertions(+) create mode 100644 etc/cron.d/.placeholder create mode 100644 etc/cron.d/e2scrub_all create mode 100644 etc/cron.d/php create mode 100644 etc/cron.d/popularity-contest create mode 100644 etc/cron.daily/.placeholder create mode 100644 etc/cron.daily/apache2 create mode 100644 etc/cron.daily/apt-compat create mode 100644 etc/cron.daily/backup-mariadb create mode 100644 etc/cron.daily/dpkg create mode 100644 etc/cron.daily/logrotate create mode 100644 etc/cron.daily/popularity-contest create mode 100644 etc/cron.daily/prestashop-rebuild-search-index create mode 100644 etc/cron.hourly/.placeholder create mode 100644 etc/cron.monthly/.placeholder create mode 100644 etc/cron.weekly/.placeholder create mode 100644 etc/cron.yearly/.placeholder diff --git a/etc/cron.d/.placeholder b/etc/cron.d/.placeholder new file mode 100644 index 0000000..76cb8d0 --- /dev/null +++ b/etc/cron.d/.placeholder @@ -0,0 +1,2 @@ +# DO NOT EDIT OR REMOVE +# This file is a simple placeholder to keep dpkg from removing this directory diff --git a/etc/cron.d/e2scrub_all b/etc/cron.d/e2scrub_all new file mode 100644 index 0000000..7af25f1 --- /dev/null +++ b/etc/cron.d/e2scrub_all @@ -0,0 +1,2 @@ +30 3 * * 0 root test -e /run/systemd/system || SERVICE_MODE=1 /usr/libexec/e2fsprogs/e2scrub_all_cron +10 3 * * * root test -e /run/systemd/system || SERVICE_MODE=1 /sbin/e2scrub_all -A -r diff --git a/etc/cron.d/php b/etc/cron.d/php new file mode 100644 index 0000000..84e5d10 --- /dev/null +++ b/etc/cron.d/php @@ -0,0 +1,14 @@ +# /etc/cron.d/php@PHP_VERSION@: crontab fragment for PHP +# This purges session files in session.save_path older than X, +# where X is defined in seconds as the largest value of +# session.gc_maxlifetime from all your SAPI php.ini files +# or 24 minutes if not defined. The script triggers only +# when session.save_handler=files. +# +# WARNING: The scripts tries hard to honour all relevant +# session PHP options, but if you do something unusual +# you have to disable this script and take care of your +# sessions yourself. + +# Look for and purge old sessions every 30 minutes +09,39 * * * * root [ -x /usr/lib/php/sessionclean ] && if [ ! -d /run/systemd/system ]; then /usr/lib/php/sessionclean; fi diff --git a/etc/cron.d/popularity-contest b/etc/cron.d/popularity-contest new file mode 100644 index 0000000..9fcabf0 --- /dev/null +++ b/etc/cron.d/popularity-contest @@ -0,0 +1,3 @@ +SHELL=/bin/sh +PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin +46 20 * * * root test -x /etc/cron.daily/popularity-contest && /etc/cron.daily/popularity-contest --crond diff --git a/etc/cron.daily/.placeholder b/etc/cron.daily/.placeholder new file mode 100644 index 0000000..76cb8d0 --- /dev/null +++ b/etc/cron.daily/.placeholder @@ -0,0 +1,2 @@ +# DO NOT EDIT OR REMOVE +# This file is a simple placeholder to keep dpkg from removing this directory diff --git a/etc/cron.daily/apache2 b/etc/cron.daily/apache2 new file mode 100644 index 0000000..6461f07 --- /dev/null +++ b/etc/cron.daily/apache2 @@ -0,0 +1,25 @@ +#!/bin/sh + +# run htcacheclean if set to 'cron' mode + +set -e +set -u + +type htcacheclean > /dev/null 2>&1 || exit 0 +[ -e /etc/default/apache-htcacheclean ] || exit 0 + + +# edit /etc/default/apache-htcacheclean to change this +HTCACHECLEAN_MODE=daemon +HTCACHECLEAN_RUN=auto +HTCACHECLEAN_SIZE=300M +HTCACHECLEAN_PATH=/var/cache/apache2/mod_cache_disk +HTCACHECLEAN_OPTIONS="" + +. /etc/default/apache-htcacheclean + +[ "$HTCACHECLEAN_MODE" = "cron" ] || exit 0 + +htcacheclean ${HTCACHECLEAN_OPTIONS} \ + -p${HTCACHECLEAN_PATH} \ + -l${HTCACHECLEAN_SIZE} diff --git a/etc/cron.daily/apt-compat b/etc/cron.daily/apt-compat new file mode 100644 index 0000000..bde3237 --- /dev/null +++ b/etc/cron.daily/apt-compat @@ -0,0 +1,55 @@ +#!/bin/sh + +set -e + +# Systemd systems use a systemd timer unit which is preferable to +# run. We want to randomize the apt update and unattended-upgrade +# runs as much as possible to avoid hitting the mirrors all at the +# same time. The systemd time is better at this than the fixed +# cron.daily time +if [ -d /run/systemd/system ]; then + exit 0 +fi + +check_power() +{ + # laptop check, on_ac_power returns: + # 0 (true) System is on main power + # 1 (false) System is not on main power + # 255 (false) Power status could not be determined + # Desktop systems always return 255 it seems + if command -v on_ac_power >/dev/null; then + if on_ac_power; then + : + elif [ $? -eq 1 ]; then + return 1 + fi + fi + return 0 +} + +# sleep for a random interval of time (default 30min) +# (some code taken from cron-apt, thanks) +random_sleep() +{ + RandomSleep=1800 + eval $(apt-config shell RandomSleep APT::Periodic::RandomSleep) + if [ $RandomSleep -eq 0 ]; then + return + fi + if [ -z "$RANDOM" ] ; then + # A fix for shells that do not have this bash feature. + RANDOM=$(( $(dd if=/dev/urandom bs=2 count=1 2> /dev/null | cksum | cut -d' ' -f1) % 32767 )) + fi + TIME=$(($RANDOM % $RandomSleep)) + sleep $TIME +} + +# delay the job execution by a random amount of time +random_sleep + +# ensure we don't do this on battery +check_power || exit 0 + +# run daily job +exec /usr/lib/apt/apt.systemd.daily diff --git a/etc/cron.daily/backup-mariadb b/etc/cron.daily/backup-mariadb new file mode 100644 index 0000000..22e2ffc --- /dev/null +++ b/etc/cron.daily/backup-mariadb @@ -0,0 +1,34 @@ +#!/bin/bash +# Sauvegarde quotidienne des bases de données MariaDB +# Basé sur le nom de la base : *_utilisateur + +BACKUP_DIR="/var/backups/mysql" +RETENTION_DAYS=21 +DATE=$(date +%F) + +mkdir -p "$BACKUP_DIR" + +# Liste toutes les bases sauf celles internes +DBS=$(mysql -N -B -e "SHOW DATABASES;" | grep -Ev "^(information_schema|performance_schema|mysql|sys)$") + +for db in $DBS; do + # Récupère l'utilisateur = partie après le dernier "_" + user=$(echo "$db" | awk -F'_' '{print $NF}') + + # Si jamais pas d'underscore, on met dans "unknown" + [ -z "$user" ] && user="unknown" + + USER_DIR="$BACKUP_DIR/$user" + mkdir -p "$USER_DIR" + + FILE="$USER_DIR/${db}_$DATE.sql.gz" + + # Sauvegarde + if ! mysqldump --single-transaction "$db" | gzip > "$FILE"; then + echo "Erreur lors de la sauvegarde de $db" >&2 + rm -f "$FILE" + fi +done + +# Nettoyage des fichiers plus vieux que 21 jours +find "$BACKUP_DIR" -type f -name "*.sql.gz" -mtime +$RETENTION_DAYS -delete diff --git a/etc/cron.daily/dpkg b/etc/cron.daily/dpkg new file mode 100644 index 0000000..899572d --- /dev/null +++ b/etc/cron.daily/dpkg @@ -0,0 +1,8 @@ +#!/bin/sh + +# Skip if systemd is running. +if [ -d /run/systemd/system ]; then + exit 0 +fi + +/usr/libexec/dpkg/dpkg-db-backup diff --git a/etc/cron.daily/logrotate b/etc/cron.daily/logrotate new file mode 100644 index 0000000..1ac1570 --- /dev/null +++ b/etc/cron.daily/logrotate @@ -0,0 +1,18 @@ +#!/bin/sh + +# skip in favour of systemd timer +if [ -d /run/systemd/system ]; then + exit 0 +fi + +# this cronjob persists removals (but not purges) +if [ ! -x /usr/sbin/logrotate ]; then + exit 0 +fi + +/usr/sbin/logrotate /etc/logrotate.conf +EXITVALUE=$? +if [ $EXITVALUE != 0 ]; then + /usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]" +fi +exit $EXITVALUE diff --git a/etc/cron.daily/popularity-contest b/etc/cron.daily/popularity-contest new file mode 100644 index 0000000..26a3693 --- /dev/null +++ b/etc/cron.daily/popularity-contest @@ -0,0 +1,200 @@ +#!/bin/sh +set -e + +# don't run if this package is removed but not purged +if [ ! -f /usr/sbin/popularity-contest ]; then + exit 0 +fi + +MODE="$1" + +unset MAILFROM +unset MAILTO +unset MY_HOSTID +unset PARTICIPATE +unset SUBMITURLS +unset USEHTTP +unset USETOR +unset MTAOPS + +TORIFY_PATH=/usr/bin/torify + +torify_enabled() { + # Return 1 to enable torify for HTTP submission, otherwise 0; exit on error + TORSOCKS_PATH=/usr/bin/torsocks + [ -f "$TORIFY_PATH" ] && [ -f "$TORSOCKS_PATH" ] && TOR_AVAILABLE=1 + + case "$USETOR" in + "yes") + if [ -z $TOR_AVAILABLE ]; then + echo "popularity-contest: USETOR is set but torify is not available." 2>&1 + echo "popularity-contest: Please install the tor and torsocks packages." 2>&1 + exit 1 + fi + if [ "yes" != "$USEHTTP" ]; then + echo "popularity-contest: when USETOR is set USEHTTP must be set as well" 2>&1 + exit 1 + fi + return 0 + ;; + "maybe") + [ "yes" = "$USEHTTP" ] && [ ! -z $TOR_AVAILABLE ] && return 0 + return 1 + ;; + "no") + return 1 + ;; + esac +} + +# get configuration information +. /usr/share/popularity-contest/default.conf +. /etc/popularity-contest.conf + +if test -d /etc/popularity-contest.d/; then + for file in `run-parts --list --regex '\.conf$' /etc/popularity-contest.d/`; + do + . $file + done +fi + +# don't run if MAILTO address is blank, and not configured to use HTTP POST! +if [ -z "$MAILTO" ] && [ "yes" != "$USEHTTP" ]; then exit 0; fi + +# don't run if PARTICIPATE is "no" or unset! +if [ "$PARTICIPATE" = "no" ] || [ -z "$PARTICIPATE" ]; then exit 0; fi + +# enable torify +if torify_enabled; then + TORIFY=$TORIFY_PATH +else + TORIFY='' +fi + + +if [ -n "$HTTP_PROXY" ]; then + export http_proxy="$HTTP_PROXY"; +fi + +POPCONVAR="/var/lib/popularity-contest" +POPCONOLD="/var/log/popularity-contest" +POPCONNEW="/var/log/popularity-contest.$$" +POPCON="$POPCONNEW" + +last_sub() +{ + if [ -r "$POPCONVAR/lastsub" ] ; then + cat "$POPCONVAR/lastsub" + else + date -r "$POPCONOLD" +%s + fi +} +set_sub() +{ + test -d "$POPCONVAR" || mkdir -p "$POPCONVAR" + date +%s > "$POPCONVAR/lastsub" +} + +# Only run on the given day, to spread the load on the server a bit +if [ "$MODE" != "--crond" ] || ( [ "$DAY" ] && [ "$DAY" != "$(date +%w)" ] ) ; then + # Ensure that popcon runs at least once in the last week + if [ -f "$POPCONOLD" ] ; then + now=$(date +%s) + lastrun=$(last_sub) + if [ "$MODE" = "--crond" ]; then + # 7.5 days, in seconds + week=648000 + else + # 6.5 days, in seconds + week=561600 + fi + if [ "$(( $now - $lastrun ))" -le "$week" ]; then + exit 0 + fi + fi +fi + +# keep old logs +cd /var/log +umask 022 +savelog -c 7 popularity-contest >/dev/null + +do_sendmail() +{ + if [ -n "$MAILFROM" ]; then + sendmail -oi $MTAOPS -f "$MAILFROM" $MAILTO + else + sendmail -oi $MTAOPS $MAILTO + fi +} + +# generate the popularity contest data + +/usr/sbin/popularity-contest --su-nobody > $POPCON + +GPG=/usr/bin/gpg + +if [ "$ENCRYPT" = "yes" ] && ! [ -x "$GPG" ]; then + logger -t popularity-contest "encryption required but gpg is not available." + echo "popularity-contest: encryption required but gpg is not available." 2>&1 + exit 1 +fi + +if [ -x "$GPG" ] && [ "$ENCRYPT" = "maybe" ] || [ "$ENCRYPT" = "yes" ]; then + POPCONGPG="$POPCON.gpg" + rm -f "$POPCONGPG" + GPGHOME=`mktemp -d` + $GPG --batch --no-options --no-default-keyring --trust-model=always \ + --homedir "$GPGHOME" --keyring $KEYRING --quiet \ + --armor -o "$POPCONGPG" -r $POPCONKEY --encrypt "$POPCON" + rm -rf "$GPGHOME" + POPCON="$POPCONGPG" +fi + +SUBMITTED=no + +# try to post the report through http POST +if [ "$SUBMITURLS" ] && [ "yes" = "$USEHTTP" ]; then + for URL in $SUBMITURLS ; do + if setsid $TORIFY /usr/share/popularity-contest/popcon-upload \ + -u $URL -f $POPCON 2>/dev/null ; then + SUBMITTED=yes + set_sub + else + logger -t popularity-contest "unable to submit report to $URL." + fi + done +fi + +# try to email the popularity contest data +# skip emailing if USETOR is set + +if [ "$MODE" = "--crond" ] && [ yes != "$SUBMITTED" ] && [ yes != "$USETOR" ] && [ "$MAILTO" ]; then + if [ -x "`which sendmail 2>/dev/null`" ]; then + ( + if [ -n "$MAILFROM" ]; then + echo "From: <$MAILFROM>" + echo "Sender: <$MAILFROM>" + fi + echo "To: $MAILTO" + echo "Subject: popularity-contest submission" + echo "MIME-Version: 1.0" + echo "Content-Type: text/plain" + echo + cat $POPCON + ) | do_sendmail + SUBMITTED=yes + else + logger -t popularity-contest "unable to submit report using sendmail." + fi +fi + +if [ "yes" != "$SUBMITTED" ] ; then + logger -t popularity-contest "unable to submit report." + rm -f $POPCONNEW $POPCONNEW.gpg +else + mv $POPCONNEW $POPCONOLD + if [ -n "$POPCONGPG" ]; then + mv $POPCONNEW.gpg $POPCONOLD.gpg + fi +fi diff --git a/etc/cron.daily/prestashop-rebuild-search-index b/etc/cron.daily/prestashop-rebuild-search-index new file mode 100644 index 0000000..c9d55b4 --- /dev/null +++ b/etc/cron.daily/prestashop-rebuild-search-index @@ -0,0 +1 @@ +curl -s " https://boutique.eureka-informatique.fr/admin592z328wv39xy4bdnvz/?controller=AdminSearch&action=searchCron&ajax=1&full=1&token=hCXLIxFy&id_shop=1 " >/dev/null 2>&1 \ No newline at end of file diff --git a/etc/cron.hourly/.placeholder b/etc/cron.hourly/.placeholder new file mode 100644 index 0000000..76cb8d0 --- /dev/null +++ b/etc/cron.hourly/.placeholder @@ -0,0 +1,2 @@ +# DO NOT EDIT OR REMOVE +# This file is a simple placeholder to keep dpkg from removing this directory diff --git a/etc/cron.monthly/.placeholder b/etc/cron.monthly/.placeholder new file mode 100644 index 0000000..76cb8d0 --- /dev/null +++ b/etc/cron.monthly/.placeholder @@ -0,0 +1,2 @@ +# DO NOT EDIT OR REMOVE +# This file is a simple placeholder to keep dpkg from removing this directory diff --git a/etc/cron.weekly/.placeholder b/etc/cron.weekly/.placeholder new file mode 100644 index 0000000..76cb8d0 --- /dev/null +++ b/etc/cron.weekly/.placeholder @@ -0,0 +1,2 @@ +# DO NOT EDIT OR REMOVE +# This file is a simple placeholder to keep dpkg from removing this directory diff --git a/etc/cron.yearly/.placeholder b/etc/cron.yearly/.placeholder new file mode 100644 index 0000000..76cb8d0 --- /dev/null +++ b/etc/cron.yearly/.placeholder @@ -0,0 +1,2 @@ +# DO NOT EDIT OR REMOVE +# This file is a simple placeholder to keep dpkg from removing this directory