51 lines
1.3 KiB
Bash
Executable file
51 lines
1.3 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
cd "$(dirname "$0")"
|
|
|
|
echo "=== RESET s175js ==="
|
|
echo "Directory: $(pwd)"
|
|
|
|
# Verifica i PID registrati nei lock prima di rimuoverli.
|
|
for file in face-scan-daemon.lock prototype-worker-daemon.lock geocode-daemon.lock; do
|
|
[ -f "$file" ] || continue
|
|
|
|
pid=""
|
|
if [[ "$file" == "prototype-worker-daemon.lock" ]]; then
|
|
pid=$(tr -cd '0-9' < "$file")
|
|
else
|
|
pid=$(node -e '
|
|
try {
|
|
const x = JSON.parse(require("fs").readFileSync(process.argv[1], "utf8"));
|
|
console.log(x.pid || "");
|
|
} catch {}
|
|
' "$file")
|
|
fi
|
|
|
|
if [[ -n "$pid" && -d "/proc/$pid" ]]; then
|
|
echo "ERRORE: $file segnala il PID attivo $pid. Reset annullato."
|
|
exit 1
|
|
fi
|
|
done
|
|
|
|
# Backup del database prima della cancellazione.
|
|
if [ -f api_v1/database.sqlite ]; then
|
|
backup="api_v1/database.sqlite.pre-clear-$(date +%Y%m%d-%H%M%S)"
|
|
cp api_v1/database.sqlite "$backup"
|
|
echo "Backup creato: $backup"
|
|
fi
|
|
|
|
rm -f \
|
|
face-scan-daemon.lock \
|
|
prototype-worker-daemon.lock \
|
|
geocode-daemon.lock \
|
|
api_v1/database.sqlite \
|
|
api_v1/database.sqlite-wal \
|
|
api_v1/database.sqlite-shm
|
|
|
|
echo "=== INIZIALIZZAZIONE DATABASE ==="
|
|
node db/init.js
|
|
|
|
echo "=== CONTROLLO INTEGRITÀ ==="
|
|
sqlite3 api_v1/database.sqlite "PRAGMA integrity_check;"
|
|
|
|
echo "=== RESET COMPLETATO ==="
|