-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.sh
More file actions
executable file
·82 lines (71 loc) · 2.31 KB
/
update.sh
File metadata and controls
executable file
·82 lines (71 loc) · 2.31 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash
set -e
# Colors
GREEN='\033[0;32m'
CYAN='\033[0;36m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
BOLD='\033[1m'
echo ""
echo -e "${CYAN}${BOLD} ⚡ Voltgres Updater${NC}"
echo ""
# Ensure swap exists on low-memory VPS (prevents OOM during Docker builds)
if [[ "$OSTYPE" == "linux-gnu"* ]] && [ "$(id -u)" -eq 0 ]; then
if [ "$(swapon --show --noheadings | wc -l)" -eq 0 ]; then
total_mem_mb=$(awk '/MemTotal/ {printf "%d", $2/1024}' /proc/meminfo)
if [ "$total_mem_mb" -lt 4096 ]; then
echo -e "${YELLOW}Low memory detected. Creating 2GB swap file...${NC}"
fallocate -l 2G /swapfile 2>/dev/null || dd if=/dev/zero of=/swapfile bs=1M count=2048 status=none
chmod 600 /swapfile
mkswap /swapfile >/dev/null
swapon /swapfile
if ! grep -q '/swapfile' /etc/fstab 2>/dev/null; then
echo '/swapfile none swap sw 0 0' >> /etc/fstab
fi
echo -e "${GREEN}Swap enabled.${NC}"
fi
fi
fi
# Must be run from the voltgres directory
if [ ! -f docker-compose.yml ]; then
echo -e "${RED}Error: docker-compose.yml not found.${NC}"
echo " Run this script from your voltgres directory."
exit 1
fi
if [ ! -f .env ]; then
echo -e "${RED}Error: .env not found. Run install.sh first.${NC}"
exit 1
fi
# Check for local changes
if ! git diff --quiet 2>/dev/null; then
echo -e "${YELLOW}You have local changes. Stashing them...${NC}"
git stash
STASHED=true
fi
# Pull latest
echo "Pulling latest version..."
git pull --ff-only || {
echo -e "${RED}Failed to pull. You may have diverged from the remote.${NC}"
if [ "$STASHED" = true ]; then
git stash pop
fi
exit 1
}
if [ "$STASHED" = true ]; then
echo "Restoring local changes..."
git stash pop || echo -e "${YELLOW}Warning: Could not restore stashed changes. Run 'git stash pop' manually.${NC}"
fi
# Ensure entrypoint script is executable
chmod +x pg-entrypoint.sh
# Rebuild and restart
echo "Rebuilding and restarting..."
existing_domain=$(grep '^DOMAIN=' .env | cut -d= -f2-)
if [ -n "$existing_domain" ]; then
docker compose --profile https up -d --build --force-recreate
else
docker compose up -d --build --force-recreate
fi
echo ""
echo -e "${GREEN}${BOLD}Voltgres updated and running!${NC}"
echo ""