2012-09-08 17:32:36 +02:00
|
|
|
#!/bin/bash
|
2014-11-02 09:42:47 +01:00
|
|
|
|
2012-09-08 17:32:36 +02:00
|
|
|
_exec_locked() {
|
2014-11-02 09:42:47 +01:00
|
|
|
local tmp_dir="/var/tmp"
|
|
|
|
local lvm_snapshot_lock_file="/.entropy_locks/vg_chroots-lv_chroots-snapshot.lock"
|
|
|
|
local snapshot_lock_file="${tmp_dir}/.emerge.snapshot.lock"
|
|
|
|
local matter_lock_file="${tmp_dir}/.matter_resource.lock"
|
|
|
|
|
|
|
|
if [ ! -d "${tmp_dir}" ]; then
|
|
|
|
echo "${tmp_dir} is missing, creating it..." >&2
|
|
|
|
mkdir -p "${tmp_dir}"
|
|
|
|
fi
|
2012-09-06 15:36:16 +02:00
|
|
|
|
2011-08-07 18:23:32 +02:00
|
|
|
flock -x -n "${matter_lock_file}" true
|
|
|
|
rc=${?}
|
|
|
|
if [ "${rc}" != "0" ]; then
|
2012-09-06 14:29:11 +02:00
|
|
|
echo >&2
|
|
|
|
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" >&2
|
2012-09-06 15:36:16 +02:00
|
|
|
echo "Matter or the Backup Script is running on this chroot" >&2
|
|
|
|
echo "Please be patient, it will eventually terminate..." >&2
|
|
|
|
echo "Snapshot lock file = ${snapshot_lock_file}" >&2
|
|
|
|
echo "Matter lock file = ${matter_lock_file}" >&2
|
|
|
|
echo >&2
|
2014-11-02 09:42:47 +01:00
|
|
|
echo "This ${1} instance will terminate NOW" >&2
|
2012-09-06 14:29:11 +02:00
|
|
|
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" >&2
|
|
|
|
echo >&2
|
2011-08-07 18:23:32 +02:00
|
|
|
return 1
|
|
|
|
else
|
2012-09-06 14:29:11 +02:00
|
|
|
# acquire snapshot read lock in non-blocking, shared mode
|
|
|
|
(
|
|
|
|
flock -s -n 9 || {
|
|
|
|
echo "Hello there," >&2;
|
2014-11-02 09:42:47 +01:00
|
|
|
echo "a chroot snapshot is in progress..." >&2;
|
2012-09-06 14:29:11 +02:00
|
|
|
echo "Try again later." >&2;
|
|
|
|
exit 1;
|
|
|
|
}
|
2014-11-02 09:42:47 +01:00
|
|
|
|
|
|
|
flock -s --timeout=120 10
|
|
|
|
if [ "${?}" != "0" ]; then
|
|
|
|
echo >&2
|
|
|
|
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" >&2
|
|
|
|
echo "The LVM lock of the Backup Script is being held for 2 minutes" >&2
|
|
|
|
echo "This should not happen. Please contact lxnay@sabayon.org and" >&2
|
|
|
|
echo "stop any activity NOW. However, if you're in an emergency" >&2
|
|
|
|
echo "Just rm ${lvm_snapshot_lock_file} and continue." >&2
|
|
|
|
echo "Please note that this will cause inconsistent backups." >&2
|
|
|
|
echo >&2
|
|
|
|
echo "This instance will terminate NOW" >&2
|
|
|
|
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" >&2
|
|
|
|
echo >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2012-09-08 17:32:36 +02:00
|
|
|
"${@}"
|
2012-09-06 14:29:11 +02:00
|
|
|
exit ${?}
|
2014-11-02 09:42:47 +01:00
|
|
|
|
|
|
|
) 9> "${snapshot_lock_file}" 10>"${lvm_snapshot_lock_file}"
|
|
|
|
return ${?}
|
2011-08-07 18:23:32 +02:00
|
|
|
fi
|
|
|
|
}
|
2012-09-08 17:32:36 +02:00
|
|
|
|
|
|
|
emerge() {
|
2014-11-02 09:42:47 +01:00
|
|
|
_exec_locked "/usr/bin/emerge" --quiet-build=y --oneshot "${@}"
|
2012-09-08 17:32:36 +02:00
|
|
|
return ${?}
|
|
|
|
}
|
|
|
|
|
|
|
|
eit() {
|
|
|
|
_exec_locked "/usr/bin/eit" "${@}"
|
|
|
|
return ${?}
|
|
|
|
}
|
2014-11-02 09:42:47 +01:00
|
|
|
|
|
|
|
# Alias configuration
|
|
|
|
alias cosmos=/particles/cosmos/cosmos
|