Repository navigation
Expand file tree
/
Copy pathlist-projects.sh
More file actions
180 lines (150 loc) · 5.69 KB
/
Copy pathlist-projects.sh
File metadata and controls
180 lines (150 loc) · 5.69 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/bin/bash
#
# List all deployed projects in /var/www
#
set -euo pipefail
# Output colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
WWW_DIR="/var/www"
# Information output function
info() {
echo -e "${CYAN}[INFO]${NC} $1"
}
warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
error() {
echo -e "${RED}[ERROR]${NC} $1"
}
success() {
echo -e "${GREEN}[OK]${NC} $1"
}
# Check root privileges
if [[ $EUID -ne 0 ]]; then
error "This script must be run with root privileges (sudo)"
exit 1
fi
# Header
echo ""
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE} Deployed projects${NC}"
echo -e "${BLUE}========================================${NC}"
echo ""
# Check that the directory exists
if [[ ! -d "$WWW_DIR" ]]; then
error "Directory ${WWW_DIR} does not exist"
exit 1
fi
# Project counter
PROJECT_COUNT=0
RUNNING_COUNT=0
# Scan directories in /var/www (excluding nginxproxy)
for PROJECT_DIR in "${WWW_DIR}"/*; do
# Skip non-directories
if [[ ! -d "$PROJECT_DIR" ]]; then
continue
fi
# Get the project name (slug)
SLUG=$(basename "$PROJECT_DIR")
# Skip nginxproxy
if [[ "$SLUG" == "nginxproxy" ]]; then
continue
fi
# Check for docker-compose.yml
if [[ ! -f "${PROJECT_DIR}/docker-compose.yml" ]]; then
continue
fi
PROJECT_COUNT=$((PROJECT_COUNT + 1))
# Read the domain from .env
DOMAIN="N/A"
if [[ -f "${PROJECT_DIR}/.env" ]]; then
DOMAIN=$(grep "^SITE_HOST=" "${PROJECT_DIR}/.env" 2>/dev/null | cut -d'=' -f2 || echo "N/A")
fi
# Read ports from .env
PORT_HTTP=$(grep "^SITE_PORT_HTTP=" "${PROJECT_DIR}/.env" 2>/dev/null | cut -d'=' -f2 || echo "N/A")
PORT_HTTPS=$(grep "^SITE_PORT_HTTPS=" "${PROJECT_DIR}/.env" 2>/dev/null | cut -d'=' -f2 || echo "N/A")
PORT_PHP=$(grep "^PHP_PORT=" "${PROJECT_DIR}/.env" 2>/dev/null | cut -d'=' -f2 || echo "N/A")
# Get the database type
DB_TYPE="N/A"
if grep -q "^DB_POSTGRES_NAME=" "${PROJECT_DIR}/.env" 2>/dev/null; then
DB_TYPE="PostgreSQL"
DB_PORT=$(grep "^DB_PORT=" "${PROJECT_DIR}/.env" 2>/dev/null | cut -d'=' -f2 || echo "N/A")
elif grep -q "^DB_MYSQL_NAME=" "${PROJECT_DIR}/.env" 2>/dev/null; then
DB_TYPE="MySQL"
DB_PORT=$(grep "^DB_PORT=" "${PROJECT_DIR}/.env" 2>/dev/null | cut -d'=' -f2 || echo "N/A")
else
DB_PORT="N/A"
fi
# Check container status
cd "$PROJECT_DIR" || continue
TOTAL_CONTAINERS=$(docker compose ps -a --format "{{.Name}}" 2>/dev/null | wc -l)
RUNNING_CONTAINERS=$(docker compose ps --format "{{.Name}}" --status running 2>/dev/null | wc -l)
# Determine project status
if [[ $RUNNING_CONTAINERS -gt 0 ]]; then
STATUS="${GREEN}RUNNING${NC} (${RUNNING_CONTAINERS}/${TOTAL_CONTAINERS})"
RUNNING_COUNT=$((RUNNING_COUNT + 1))
elif [[ $TOTAL_CONTAINERS -gt 0 ]]; then
STATUS="${YELLOW}STOPPED${NC} (0/${TOTAL_CONTAINERS})"
else
STATUS="${RED}NO CONTAINERS${NC}"
fi
# Check for an SSL certificate (stored in Docker volume <slug>_ssl_certificates)
SSL_STATUS="${RED}NO${NC}"
SSL_VOLUME_DIR=$(docker volume inspect -f '{{.Mountpoint}}' "${SLUG}_ssl_certificates" 2>/dev/null || true)
if [[ -n "$SSL_VOLUME_DIR" && -e "${SSL_VOLUME_DIR}/live/${DOMAIN}/fullchain.pem" ]]; then
SSL_STATUS="${GREEN}YES${NC}"
fi
# Display project information
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${CYAN}Project:${NC} ${SLUG}"
echo -e "${CYAN}Domain:${NC} ${DOMAIN}"
echo -e "${CYAN}Status:${NC} ${STATUS}"
echo -e "${CYAN}SSL:${NC} ${SSL_STATUS}"
echo -e "${CYAN}Database:${NC} ${DB_TYPE} (port: ${DB_PORT})"
echo -e "${CYAN}Ports:${NC} HTTP: ${PORT_HTTP}, HTTPS: ${PORT_HTTPS}, PHP: ${PORT_PHP}"
echo -e "${CYAN}Path:${NC} ${PROJECT_DIR}"
# Show the main containers
if [[ $TOTAL_CONTAINERS -gt 0 ]]; then
echo -e "${CYAN}Containers:${NC}"
docker compose ps -a --format " - {{.Name}}: {{.Status}}" 2>/dev/null | head -n 5
if [[ $TOTAL_CONTAINERS -gt 5 ]]; then
echo " ... and $((TOTAL_CONTAINERS - 5)) more containers"
fi
fi
# Management commands
if [[ $RUNNING_CONTAINERS -gt 0 ]]; then
echo -e "${CYAN}Deactivate:${NC} sudo bash deactivate.sh --slug ${SLUG}"
else
echo -e "${CYAN}Activate:${NC} sudo bash activate.sh --slug ${SLUG}"
fi
echo -e "${CYAN}Remove:${NC} sudo bash remove.sh --slug ${SLUG} --domain ${DOMAIN}"
echo ""
done
# Summary statistics
echo -e "${BLUE}========================================${NC}"
echo -e "${CYAN}Total projects:${NC} ${PROJECT_COUNT}"
echo -e "${CYAN}Running:${NC} ${GREEN}${RUNNING_COUNT}${NC}"
echo -e "${CYAN}Stopped:${NC} ${YELLOW}$((PROJECT_COUNT - RUNNING_COUNT))${NC}"
echo -e "${BLUE}========================================${NC}"
echo ""
# Check nginxproxy
if [[ -d "${WWW_DIR}/nginxproxy" ]]; then
echo -e "${CYAN}Nginx Proxy:${NC}"
cd "${WWW_DIR}/nginxproxy" || exit 0
PROXY_STATUS=$(docker compose ps --format "{{.Status}}" 2>/dev/null | head -n 1 || echo "Not running")
if [[ "$PROXY_STATUS" == *"Up"* ]]; then
echo -e " Status: ${GREEN}RUNNING${NC}"
else
echo -e " Status: ${RED}STOPPED${NC}"
fi
# Show the number of sites in nginxproxy
SITES_COUNT=$(ls -1 "${WWW_DIR}/nginxproxy/sites"/*.conf 2>/dev/null | wc -l)
echo -e " Configured sites: ${SITES_COUNT}"
echo ""
fi
exit 0