Skip to content

Commit 8b0e1ad

Browse files
committed
try to fix ssl generation and configration scripts
1 parent 8e369db commit 8b0e1ad

File tree

4 files changed

+23
-18
lines changed

4 files changed

+23
-18
lines changed

application/share/bin/ssl-activate-renewal.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ check_ssl_certificates() {
105105
local cert_dirs
106106

107107
# Look for any SSL certificates in the expected location
108-
if docker compose exec proxy find /etc/letsencrypt/live -name "fullchain.pem" -type f 2>/dev/null | grep -q "fullchain.pem"; then
108+
if docker compose --env-file /var/lib/torrust/compose/.env exec proxy find /etc/letsencrypt/live -name "fullchain.pem" -type f 2>/dev/null | grep -q "fullchain.pem"; then
109109
cert_found=true
110-
cert_dirs=$(docker compose exec proxy find /etc/letsencrypt/live -name "fullchain.pem" -type f 2>/dev/null | sed 's|/fullchain.pem||' | sed 's|.*/||')
110+
cert_dirs=$(docker compose --env-file /var/lib/torrust/compose/.env exec proxy find /etc/letsencrypt/live -name "fullchain.pem" -type f 2>/dev/null | sed 's|/fullchain.pem||' | sed 's|.*/||')
111111

112112
log_info "Found SSL certificates for:"
113113
while IFS= read -r domain; do
@@ -116,7 +116,7 @@ check_ssl_certificates() {
116116

117117
# Check certificate expiration
118118
local expiry
119-
expiry=$(docker compose exec proxy openssl x509 -in "/etc/letsencrypt/live/${domain}/cert.pem" -noout -enddate 2>/dev/null | cut -d= -f2 || echo "Unable to determine")
119+
expiry=$(docker compose --env-file /var/lib/torrust/compose/.env exec proxy openssl x509 -in "/etc/letsencrypt/live/${domain}/cert.pem" -noout -enddate 2>/dev/null | cut -d= -f2 || echo "Unable to determine")
120120
log_info " Expires: ${expiry}"
121121
fi
122122
done <<< "${cert_dirs}"
@@ -244,7 +244,7 @@ remove_renewal_cronjob() {
244244
test_ssl_renewal() {
245245
log_info "Testing SSL certificate renewal (dry run)..."
246246

247-
if docker compose run --rm certbot renew --dry-run; then
247+
if docker compose --env-file /var/lib/torrust/compose/.env run --rm certbot renew --dry-run; then
248248
log_success "SSL renewal test passed"
249249
log_info "Automatic renewal should work correctly"
250250
else
@@ -286,7 +286,7 @@ show_renewal_info() {
286286
log_info " tail -f /var/log/ssl-renewal.log"
287287
log_info ""
288288
log_info "To test renewal manually:"
289-
log_info " docker compose run --rm certbot renew --dry-run"
289+
log_info " docker compose --env-file /var/lib/torrust/compose/.env run --rm certbot renew --dry-run"
290290
}
291291

292292
# Main function
@@ -321,9 +321,9 @@ main() {
321321
fi
322322

323323
# Check if Docker services are running
324-
if ! docker compose ps | grep -q "Up"; then
324+
if ! docker compose --env-file /var/lib/torrust/compose/.env ps | grep -q "Up"; then
325325
log_error "Docker Compose services are not running"
326-
log_error "Please start services first: docker compose up -d"
326+
log_error "Please start services first: docker compose --env-file /var/lib/torrust/compose/.env up -d"
327327
exit 1
328328
fi
329329

application/share/bin/ssl-configure-nginx.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ check_prerequisites() {
4848
log_info "Checking prerequisites for nginx HTTPS configuration..."
4949

5050
# Check if nginx is running
51-
if ! docker compose ps proxy | grep -q "Up"; then
51+
if ! docker compose --env-file /var/lib/torrust/compose/.env ps proxy | grep -q "Up"; then
5252
log_error "Nginx proxy service is not running"
53-
log_error "Please start services first: docker compose up -d"
53+
log_error "Please start services first: docker compose --env-file /var/lib/torrust/compose/.env up -d"
5454
exit 1
5555
fi
5656

application/share/bin/ssl-generate.sh

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ check_prerequisites() {
8888
fi
8989

9090
# Check if required services are running
91-
if ! docker compose ps proxy | grep -q "Up"; then
91+
if ! docker compose --env-file /var/lib/torrust/compose/.env ps proxy | grep -q "Up"; then
9292
log_error "Proxy service is not running"
93-
log_error "Please start services first: docker compose up -d"
93+
log_error "Please start services first: docker compose --env-file /var/lib/torrust/compose/.env up -d"
9494
exit 1
9595
fi
9696

@@ -102,13 +102,18 @@ generate_dhparam() {
102102
log_info "Checking DH parameters..."
103103

104104
# Check if DH parameters already exist
105-
if docker compose exec proxy test -f "/etc/ssl/certs/dhparam.pem" 2>/dev/null; then
105+
if docker compose --env-file /var/lib/torrust/compose/.env exec proxy test -f "/etc/ssl/certs/dhparam.pem" 2>/dev/null; then
106106
log_info "DH parameters already exist, skipping generation"
107107
return 0
108108
fi
109109

110110
log_info "Generating DH parameters (this may take several minutes)..."
111-
if docker compose exec proxy openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048; then
111+
# Generate DH parameters on the host and copy to container
112+
local temp_dhparam="/tmp/dhparam.pem"
113+
if openssl dhparam -out "${temp_dhparam}" 2048; then
114+
# Copy to container
115+
docker cp "${temp_dhparam}" "$(docker compose --env-file /var/lib/torrust/compose/.env ps -q proxy):/etc/ssl/certs/dhparam.pem"
116+
rm -f "${temp_dhparam}"
112117
log_success "DH parameters generated successfully"
113118
else
114119
log_error "Failed to generate DH parameters"
@@ -193,9 +198,9 @@ show_certificate_info() {
193198
log_info " Type: Let's Encrypt ${MODE_NAME} certificate"
194199

195200
# Try to show certificate expiration
196-
if docker compose exec proxy test -f "/etc/letsencrypt/live/${subdomain}/cert.pem" 2>/dev/null; then
201+
if [[ -f "/var/lib/torrust/certbot/etc/letsencrypt/live/${subdomain}/cert.pem" ]]; then
197202
local expiry
198-
expiry=$(docker compose exec proxy openssl x509 -in "/etc/letsencrypt/live/${subdomain}/cert.pem" -noout -enddate 2>/dev/null | cut -d= -f2 || echo "Unable to determine")
203+
expiry=$(openssl x509 -in "/var/lib/torrust/certbot/etc/letsencrypt/live/${subdomain}/cert.pem" -noout -enddate 2>/dev/null | cut -d= -f2 || echo "Unable to determine")
199204
log_info " Expires: ${expiry}"
200205
fi
201206
}

application/share/bin/ssl-setup.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ source "${PROJECT_ROOT}/scripts/shell-utils.sh"
3434
DOMAIN=""
3535
EMAIL=""
3636
MODE="staging"
37-
SKIP_DNS_VALIDATION=false
37+
SKIP_DNS_VALIDATION=true
3838
HELP=false
3939

4040
# Parse command line arguments
@@ -178,9 +178,9 @@ check_prerequisites() {
178178
fi
179179

180180
# Check if main services are running
181-
if ! docker compose ps | grep -q "Up"; then
181+
if ! docker compose --env-file /var/lib/torrust/compose/.env ps | grep -q "Up"; then
182182
log_error "Docker Compose services are not running"
183-
log_error "Please run 'docker compose up -d' first"
183+
log_error "Please run 'docker compose --env-file /var/lib/torrust/compose/.env up -d' first"
184184
exit 1
185185
fi
186186

0 commit comments

Comments
 (0)