remove flag if older as 12h
This commit is contained in:
1 parent
1a35052ee7
commit
f5ce954318
1 file changed
+12
-1
@@ -6,6 +6,7 @@
|
|||||||
FLAG_FILE="/root/photoprism-auto-index.flag"
|
FLAG_FILE="/root/photoprism-auto-index.flag"
|
||||||
LOG_FILE="/root/photoprism-auto-index.log"
|
LOG_FILE="/root/photoprism-auto-index.log"
|
||||||
MAX_LOG_SIZE=$((10 * 1024 * 1024)) # 10 MB in Bytes
|
MAX_LOG_SIZE=$((10 * 1024 * 1024)) # 10 MB in Bytes
|
||||||
|
MAX_FLAG_AGE=$((12 * 60 * 60)) # 12 Stunden in Sekunden
|
||||||
|
|
||||||
# Log-Funktion
|
# Log-Funktion
|
||||||
log() {
|
log() {
|
||||||
@@ -40,10 +41,20 @@ log "Script gestartet (PID: $$)"
|
|||||||
|
|
||||||
# Prüfe ob ein anderer Prozess bereits läuft
|
# Prüfe ob ein anderer Prozess bereits läuft
|
||||||
if [ -f "$FLAG_FILE" ]; then
|
if [ -f "$FLAG_FILE" ]; then
|
||||||
log "Abbruch: Prozess läuft bereits"
|
# Prüfe Alter der Flag-Datei
|
||||||
|
FLAG_MTIME=$(stat -f %m "$FLAG_FILE" 2>/dev/null || echo 0)
|
||||||
|
CURRENT_TIME=$(date +%s)
|
||||||
|
FLAG_AGE=$((CURRENT_TIME - FLAG_MTIME))
|
||||||
|
|
||||||
|
if [ $FLAG_AGE -gt $MAX_FLAG_AGE ]; then
|
||||||
|
log "Flag-Datei ist älter als 12h ($((FLAG_AGE / 3600))h) - lösche sie und starte neu"
|
||||||
|
cleanup
|
||||||
|
else
|
||||||
|
log "Abbruch: Prozess läuft bereits (seit $((FLAG_AGE / 60)) Minuten)"
|
||||||
trap - EXIT INT TERM ERR
|
trap - EXIT INT TERM ERR
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
log "Erstelle Flag-Datei"
|
log "Erstelle Flag-Datei"
|
||||||
echo "Started: $(date '+%Y-%m-%d %H:%M:%S') | PID: $$" > "$FLAG_FILE"
|
echo "Started: $(date '+%Y-%m-%d %H:%M:%S') | PID: $$" > "$FLAG_FILE"
|
||||||
|
|||||||
Reference in new issue
Block a user