repo-cloner/old/dockerbin/cron-command

45 lines
791 B
Plaintext
Raw Normal View History

#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
2018-10-28 15:12:34 +01:00
# try to include laminar env
if [ -f /etc/profile.d/laminar.sh ]
then
source /etc/profile.d/laminar.sh
fi
2018-02-23 11:28:45 +01:00
# if started as root
if [ $UID -eq 0 ]
then
find /data \! -user executor -exec chown executor:executor {} \;
su executor -c cron-command
exit $?
fi
# check lock
lock=/var/run/cloner.pid
dir_prefix=cloner
max_jobs=${JOBS:-3}
function die(){
echo $@ 1>&2
exit 1
}
# first, check process
if [ -f $lock ]
then
pid=$(cat $lock)
# if it still runs, die not so quietly
[ -n "$pid" ] && [ -d /proc/$pid ] && die "Another process running!"
fi
# else make some mess and setup trap
echo $BASHPID > $lock
find /data -maxdepth 1 -type d -name "${dir_prefix}-*" | \
parallel --lb -j $max_jobs -n 1 run-mirror-update
2018-02-25 20:56:17 +01:00
echo "Cron Finished"