From 3f72b18a48432a19a8203df61bcc8386e165f594 Mon Sep 17 00:00:00 2001 From: Esteban Carnevale Date: Sat, 27 Dec 2014 15:21:04 -0300 Subject: parabola-mirror-repos: Remove logging and mail sending To simplify the script. Also, rsync output now does not use --progress by default so the output can be logged and mailed by a wrapper. Configuration variable "terminal" can be set to 1 to enable --progress. --- parabola-mirror-repos | 65 ++++----------------------------------------------- 1 file changed, 5 insertions(+), 60 deletions(-) diff --git a/parabola-mirror-repos b/parabola-mirror-repos index 2574803..65776b3 100755 --- a/parabola-mirror-repos +++ b/parabola-mirror-repos @@ -7,9 +7,6 @@ script_filename="$(basename "$0")" -# Create temporary log file -log_tmp="$(mktemp -p /var/tmp)" - # Default configuration values. # They can be overridden by setting the variables in the calling environment. # 1 to set, 0 to unset @@ -24,23 +21,20 @@ log_tmp="$(mktemp -p /var/tmp)" : ${max_delete:=10000} # maximum amount of files to delete in the local directory [[ ! ${bw_limit} ]] && \ : ${bw_limit:=1300} # KB/s -: ${log_file:=${script_filename}.log} -: ${options:=-rltvH --no-p --no-g --max-delete=$max_delete --exclude=.* --bwlimit=${bw_limit} --no-motd --chmod=Dug=srwx,Fug=rw --log-file=${log_tmp}} +: ${options:=-rltvH --no-p --no-g --max-delete=$max_delete --exclude=.* --bwlimit=${bw_limit} --no-motd --chmod=Dug=srwx,Fug=rw} : ${oldest_version:=100} # delete versions older than this version : ${link_dest[0]:=${base_dir}/archlinux} #: ${link_dest[1]:=${base_dir}/parabola.secondary_mirror.tmp} # link-dest does not support any network URI like rsync://... -[[ ! ${mail_to} ]] && \ - : ${mail_to:=your@mail.com} # set to enable mailing log file, or comment out to disable it : ${date_exclude:=2014.06.19} # disable running this script this date (see next line) : ${force_run:=0} # set to 1 to force running on excluded date -: ${terminal:=1} # outputs to stdout using rsync --progress (and logs to a file) +#: ${terminal:=1} # outputs to stdout using rsync --progress : ${alternative_mirror:=0} # use alternative mirror; forces no_snapshot_delete and disables snapshot_symlink_update; synchronized files end up in ${local_dir}.tmp : ${no_snapshot_delete:=0} # disable deletion of oldest snapshots; alternative_mirror enables it forcefully : ${leave_tmp:=0} # leave updated tree in {project}.tmp instead of creating a dated snapshot directory : ${snapshot_symlink_update:=1} # update symlink to last snapshot # does nothing if leave_tmp is enabled -: ${TZ:=UTC} # set timezone to UTC (affects rsync log output) +: ${TZ:=UTC} # set timezone to UTC : ${db_and_symlinks_update:=1} # update DB files and package symlinks # disabling this uses existing file /tmp/parabola-mirror which can be left over the last invocation of parabola-mirror-repos with this option set : ${pools_update:=1} # update files in package pools @@ -75,56 +69,24 @@ remote_pool_files="/tmp/${project}-remote-files" local_pool_files="/tmp/${project}-local-files" pool_files_to_delete="/tmp/${project}-to-delete-files" -# Lock with flock (provided by util-linux), save to log file and send email on exit +# Lock with flock (provided by util-linux) lockfile="/var/lock/${script_filename}" lockfd=99 _lock() { flock -$1 $lockfd; } -# Wait until there is no process writing to ${log_tmp} -# Waiting can be necessary if command groups are not executed until the end -_wait_log_tmp() { - if [[ -e "${log_tmp}" ]] ; then - while fuser -s "${log_tmp}" ; do - sleep 0.2 - done - fi -} - _no_more_locking() { set +e # Save exit status es=$? - _wait_log_tmp - cat "${log_tmp}" >> "${log_file}" - - if [[ $? == 0 ]] ; then - log_written=1 - else - echo "=> ERROR: Failed to write to log file: ${log_file}" >&2 - fi - if [[ -e ${local_dir}.tmp ]] ; then echo "=> WARNING: Temporary directory ${local_dir}.tmp remains in file system" fi - if [[ ${mail_to} ]] ; then - echo "=> Sending output to ${mail_to}" - mail -s "[$(hostname)] ${script_filename}" "${mail_to}" < "${log_tmp}" - fi - - if [[ ${log_written} == 1 ]] ; then - rm -f "${log_tmp}" - fi - if [[ $es != 0 ]] ; then - echo "=> WARNING: Unsuccessful script termination. Exit status: $es" - if [[ ${mail_to} ]] ; then - echo "=> Sending error notification to ${mail_to}" - mail -s "[$(hostname)] ${script_filename} failed. See logged output." "${mail_to}" < /dev/null - fi + echo "=> ERROR: Unsuccessful script termination. Exit status: $es" fi _lock u @@ -166,8 +128,6 @@ error() { exit 1 } -{ - if [[ ${date_exclude} && ${force_run} != 1 ]] ; then if [[ $date == ${date_exclude} ]] ; then echo "Manually disabled: ${date}. Exiting." @@ -332,10 +292,6 @@ fi echo "=> List of local repositories. Existing files will be hard linked from these instead of being fetched from the remote server." printf -- '%s\n' "${link_dest[@]}" -} &> >(tee -a "${log_tmp}") - -_wait_log_tmp - if [[ ${db_and_symlinks_update} == 1 ]] ; then echo "=> Starting to synchronize repository directories (symlinks and db.* files)" @@ -344,17 +300,12 @@ rsync $options --stats --exclude 'mips64el' --delete-after --safe-links "${link_ fi -{ - if [[ ${pools_update} == 1 ]] ; then echo "=> Starting to synchronize package pools from remote server $server" fi # end "if [[ ${pools_update} == 1 ]]" -} &> >(tee -a "${log_tmp}") - -_wait_log_tmp if [[ ${pools_update} == 1 ]] ; then @@ -367,8 +318,6 @@ if [[ ${path_list} ]] ; then rsync $options --stats --safe-links "${link_dest_option[@]/%//$path}" --link-dest="$local_dir"/"$path" ${path_list_array[@]/#/${server}/} "${local_dir}".tmp/ || error " => ERROR: rsync terminated with an error code: $?" fi -{ - if [[ ${no_snapshot_delete} != 1 ]] ; then echo "=> DRY-RUN: Delete versions older than the version number: ${oldest_version}." @@ -417,7 +366,3 @@ echo "=> Disk space report" df -h "${base_dir}" echo "=> ${script_filename} finished successfully. Finish time: $(date --rfc-3339=seconds)" - -} &> >(tee -a "${log_tmp}") - -_wait_log_tmp -- cgit v1.2.3