Feat: Passt die lock-Funktionen an, dass sie einen Parameter entgegen nimmt.
This commit is contained in:
parent
338bec55e9
commit
65fc9d0c69
@ -5,21 +5,37 @@ if [[ ! -w "$LOCK_DIR" ]]; then
|
|||||||
LOCK_DIR="/tmp" # Fallback für benutzerspezifische Locks
|
LOCK_DIR="/tmp" # Fallback für benutzerspezifische Locks
|
||||||
fi
|
fi
|
||||||
|
|
||||||
LOCK_FILE="$LOCK_DIR/$(basename "$0").lock"
|
# Funktion zur Erstellung des Lock-Dateinamens
|
||||||
|
get_lock_file() {
|
||||||
|
local suffix="$1"
|
||||||
|
if [[ -n "$suffix" ]]; then
|
||||||
|
echo "$LOCK_DIR/$(basename "$0")_$suffix.lock"
|
||||||
|
else
|
||||||
|
echo "$LOCK_DIR/$(basename "$0").lock"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
create_lock() {
|
create_lock() {
|
||||||
if [[ -e "$LOCK_FILE" ]]; then
|
local suffix="$1"
|
||||||
log "Ein anderer Prozess läuft bereits. Lock-File gefunden: $LOCK_FILE"
|
local lock_file
|
||||||
|
lock_file=$(get_lock_file "$suffix")
|
||||||
|
|
||||||
|
if [[ -e "$lock_file" ]]; then
|
||||||
|
log "Ein anderer Prozess läuft bereits. Lock-File gefunden: $lock_file"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
touch "$LOCK_FILE"
|
touch "$lock_file"
|
||||||
log "Lock-File erstellt: $LOCK_FILE"
|
log "Lock-File erstellt: $lock_file"
|
||||||
}
|
}
|
||||||
|
|
||||||
remove_lock() {
|
remove_lock() {
|
||||||
if [[ -e "$LOCK_FILE" ]]; then
|
local suffix="$1"
|
||||||
rm -f "$LOCK_FILE"
|
local lock_file
|
||||||
log "Lock-File entfernt: $LOCK_FILE"
|
lock_file=$(get_lock_file "$suffix")
|
||||||
|
|
||||||
|
if [[ -e "$lock_file" ]]; then
|
||||||
|
rm -f "$lock_file"
|
||||||
|
log "Lock-File entfernt: $lock_file"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user