31 lines
668 B
Bash
31 lines
668 B
Bash
#!/bin/bash
|
|
|
|
LOCK_DIR="/run/lock" # Standard für systemweite Locks
|
|
if [[ ! -w "$LOCK_DIR" ]]; then
|
|
LOCK_DIR="/tmp" # Fallback für benutzerspezifische Locks
|
|
fi
|
|
|
|
LOCK_FILE="$LOCK_DIR/$(basename "$0").lock"
|
|
|
|
create_lock() {
|
|
if [[ -e "$LOCK_FILE" ]]; then
|
|
log "Ein anderer Prozess läuft bereits. Lock-File gefunden: $LOCK_FILE"
|
|
exit 1
|
|
fi
|
|
touch "$LOCK_FILE"
|
|
log "Lock-File erstellt: $LOCK_FILE"
|
|
}
|
|
|
|
remove_lock() {
|
|
if [[ -e "$LOCK_FILE" ]]; then
|
|
rm -f "$LOCK_FILE"
|
|
log "Lock-File entfernt: $LOCK_FILE"
|
|
fi
|
|
}
|
|
|
|
trap_remove_lock() {
|
|
log "Signal empfangen. Lock-File wird entfernt."
|
|
remove_lock
|
|
exit 1
|
|
}
|