-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathstart.sh
More file actions
executable file
·134 lines (115 loc) · 4.48 KB
/
start.sh
File metadata and controls
executable file
·134 lines (115 loc) · 4.48 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/env bash
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$SCRIPT_DIR"
# Colors
RED=$'\033[0;31m'
GREEN=$'\033[0;32m'
YELLOW=$'\033[1;33m'
CYAN=$'\033[0;36m'
BOLD=$'\033[1m'
DIM=$'\033[2m'
NC=$'\033[0m'
# Docker permission check
if ! docker info > /dev/null 2>&1; then
if sudo docker info > /dev/null 2>&1; then
printf "\n ${YELLOW}⚠${NC} Docker needs sudo.\n"
printf " ${DIM}→${NC} Run: ${BOLD}sudo bash start.sh${NC}\n\n"
exit 1
else
printf "\n ${RED}✗${NC} Docker not running.\n"
exit 1
fi
fi
# .env check
if [ ! -f "$SCRIPT_DIR/.env" ]; then
printf "\n ${RED}✗${NC} No .env found.\n"
printf " ${DIM}→${NC} Run setup first: "
printf "${BOLD}bash setup.sh${NC}\n\n"
exit 1
fi
# Auto-detect compose file (absolute path so docker compose finds it
# regardless of where the user invoked the script from)
if [ -f "$SCRIPT_DIR/infra/docker-compose.yml" ]; then
COMPOSE_FILE="$SCRIPT_DIR/infra/docker-compose.yml"
elif [ -f "$SCRIPT_DIR/docker-compose.yml" ]; then
COMPOSE_FILE="$SCRIPT_DIR/docker-compose.yml"
else
printf "\n ${RED}✗${NC} docker-compose.yml not found\n\n"
exit 1
fi
# Use absolute paths for --project-directory and --env-file. Compose resolves
# --env-file relative to the current working directory; an absolute path means
# the variables (POSTGRES_PASSWORD, JWT_SECRET, etc.) always reach containers
# even if the user invokes start.sh from outside the repo root.
COMPOSE_CMD="docker compose -f $COMPOSE_FILE \
--project-directory $SCRIPT_DIR \
--env-file $SCRIPT_DIR/.env"
# Banner
printf "\n"
printf " ${CYAN}╔═══════════════════════════════════╗${NC}\n"
printf " ${CYAN}║${NC} ${BOLD}VoidAccess${NC} · Starting up "
printf "${CYAN}║${NC}\n"
printf " ${CYAN}╚═══════════════════════════════════╝${NC}\n\n"
printf " ${DIM}→${NC} Building and starting containers...\n"
printf " ${DIM}→${NC} First run takes 3-5 min. "
printf "Cached after that.\n\n"
# Run with output visible
$COMPOSE_CMD up --build -d
BUILD_EXIT=$?
if [ $BUILD_EXIT -ne 0 ]; then
printf "\n ${RED}✗${NC} Failed to start.\n"
printf " ${DIM}→${NC} Run for full output:\n"
printf " ${DIM} $COMPOSE_CMD up --build${NC}\n\n"
exit 1
fi
printf "\n ${DIM}→${NC} Checking services...\n\n"
ALL_OK=true
for SVC in postgres tor fastapi nextjs; do
LABEL="$SVC"
case $SVC in
postgres) LABEL="PostgreSQL" ;;
tor) LABEL="Tor" ;;
fastapi) LABEL="FastAPI" ;;
nextjs) LABEL="Next.js" ;;
esac
HEALTHY=false
for attempt in $(seq 1 40); do
STATE=$(docker inspect \
--format='{{.State.Status}}' \
"voidaccess-${SVC}" 2>/dev/null \
|| echo "missing")
HEALTH=$(docker inspect \
--format='{{if .State.Health}}{{.State.Health.Status}}{{else}}none{{end}}' \
"voidaccess-${SVC}" 2>/dev/null \
|| echo "none")
if [ "$HEALTH" = "healthy" ] || \
{ [ "$STATE" = "running" ] && \
[ "$HEALTH" = "none" ]; }; then
printf " ${GREEN}✓${NC} $LABEL\n"
HEALTHY=true
break
fi
printf "\r ${CYAN}·${NC} $LABEL (${attempt}/40)... "
sleep 3
done
printf "\r%-60s\r" " "
if [ "$HEALTHY" = "false" ]; then
printf " ${YELLOW}⚠${NC} $LABEL — not healthy\n"
ALL_OK=false
fi
done
printf "\n"
if [ "$ALL_OK" = "true" ]; then
printf " ${GREEN}╔═══════════════════════════════════╗${NC}\n"
printf " ${GREEN}║${NC} ${BOLD}✓ VoidAccess is ready!${NC} "
printf "${GREEN}║${NC}\n"
printf " ${GREEN}╠═══════════════════════════════════╣${NC}\n"
printf " ${GREEN}║${NC} UI → http://localhost:3001 "
printf "${GREEN}║${NC}\n"
printf " ${GREEN}║${NC} API → http://localhost:8000 "
printf "${GREEN}║${NC}\n"
printf " ${GREEN}╚═══════════════════════════════════╝${NC}\n\n"
else
printf " ${YELLOW}⚠${NC} Some services slow — check:\n"
printf " ${DIM} $COMPOSE_CMD logs -f${NC}\n\n"
fi