occ_maintenance.sh: don't start if script is already running.
This commit is contained in:
@@ -11,7 +11,8 @@ snippet_dir="${script_dir}/snippets"
|
|||||||
declare -a unsorted_website_arr
|
declare -a unsorted_website_arr
|
||||||
declare -a website_arr
|
declare -a website_arr
|
||||||
|
|
||||||
log_file="$(mktemp)"
|
LOCK_DIR="/tmp/${script_name%%.*}.LOCK"
|
||||||
|
log_file="${LOCK_DIR}/${script_name%%.*}.log"
|
||||||
|
|
||||||
backup_date=$(date +%Y-%m-%d-%H%M)
|
backup_date=$(date +%Y-%m-%d-%H%M)
|
||||||
|
|
||||||
@@ -61,7 +62,7 @@ usage() {
|
|||||||
clean_up() {
|
clean_up() {
|
||||||
|
|
||||||
# Perform program exit housekeeping
|
# Perform program exit housekeeping
|
||||||
rm -f $log_file
|
rm -f "$LOCK_DIR"
|
||||||
blank_line
|
blank_line
|
||||||
exit $1
|
exit $1
|
||||||
}
|
}
|
||||||
@@ -191,10 +192,53 @@ fi
|
|||||||
# - Jobhandling
|
# - Jobhandling
|
||||||
# ----------
|
# ----------
|
||||||
|
|
||||||
# - Run 'clean_up' for signals SIGHUP SIGINT SIGTERM
|
if pgrep -f "$(basename $0)" | grep -v $$ ; then
|
||||||
|
|
||||||
|
msg="A previos instance of script \"`basename $0`\" seems already be running."
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
if $terminal ; then
|
||||||
|
echo -e "[ \033[31m\033[1mFatal\033[m ]: $msg"
|
||||||
|
echo ""
|
||||||
|
echo -e " \033[31m\033[1mScript was interupted\033[m!"
|
||||||
|
else
|
||||||
|
echo " [ Fatal ]: $msg"
|
||||||
|
echo ""
|
||||||
|
echo " Script was interupted!"
|
||||||
|
fi
|
||||||
|
echo
|
||||||
|
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# - If job already runs, stop execution..
|
||||||
|
# -
|
||||||
|
if mkdir "$LOCK_DIR" 2> /dev/null ; then
|
||||||
|
|
||||||
|
# - Remove lockdir when the script finishes, or when it receives a signal
|
||||||
# -
|
# -
|
||||||
trap clean_up SIGHUP SIGINT SIGTERM
|
trap clean_up SIGHUP SIGINT SIGTERM
|
||||||
|
|
||||||
|
else
|
||||||
|
|
||||||
|
msg="A previos instance of script \"`basename $0`\" seems already be running."
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
if $terminal ; then
|
||||||
|
echo -e "[ \033[31m\033[1mFatal\033[m ]: $msg"
|
||||||
|
echo ""
|
||||||
|
echo -e " \033[31m\033[1mScript was interupted\033[m!"
|
||||||
|
else
|
||||||
|
echo " [ Fatal ]: $msg"
|
||||||
|
echo ""
|
||||||
|
echo " Script was interupted!"
|
||||||
|
fi
|
||||||
|
echo
|
||||||
|
|
||||||
|
exit 1
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
# -------------
|
# -------------
|
||||||
|
|||||||
Reference in New Issue
Block a user