-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauto-deploy.sh
More file actions
executable file
·53 lines (41 loc) · 1.26 KB
/
auto-deploy.sh
File metadata and controls
executable file
·53 lines (41 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
# Auto-deploy script con controllo git
# File: /home/dhwp/auto-deploy.sh
PROJECT_DIR="/home/dhwp/proxy.dh.unica"
LOCK_FILE="/tmp/auto-deploy.lock"
# Evita esecuzioni multiple
if [ -f "$LOCK_FILE" ]; then
echo "Deploy già in corso..."
exit 0
fi
# Crea lock file
touch "$LOCK_FILE"
# Cleanup function
cleanup() {
rm -f "$LOCK_FILE"
}
trap cleanup EXIT
cd "$PROJECT_DIR"
# Controlla se ci sono nuovi commit
git fetch origin >/dev/null 2>&1
LOCAL_COMMIT=$(git rev-parse HEAD)
REMOTE_COMMIT=$(git rev-parse origin/master)
if [ "$LOCAL_COMMIT" != "$REMOTE_COMMIT" ]; then
echo "$(date): 🔄 Nuovi commit trovati - Deploy automatico in corso..."
# Pull dei nuovi commit
echo "$(date): 📥 Eseguendo git reset e pull..."
git reset --hard origin/master
git pull origin master
# Reload nginx
echo "$(date): 🔄 Eseguendo nginx-reload.sh..."
chmod +x nginx-reload.sh
./nginx-reload.sh
# Verifica nginx
echo "$(date): ✅ Verificando configurazione nginx..."
docker exec dhunica_proxypass nginx -t
echo "$(date): 🎉 Deploy automatico completato con successo!"
echo "$(date): 📝 Commit applicato: $REMOTE_COMMIT"
echo "$(date): ---"
else
echo "$(date): 💤 Nessun nuovo commit"
fi