-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_nginx.sh
More file actions
executable file
·45 lines (36 loc) · 1.41 KB
/
start_nginx.sh
File metadata and controls
executable file
·45 lines (36 loc) · 1.41 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
#!/bin/bash
source "$(dirname "$0")/conf.sh"
# Define the name of the Docker/Podman container
CONTAINER_NAME="nginx_container"
NGINX_CONFIG_SRC="$(dirname "$0")/nginx.conf.src"
NGINX_CONFIG_COMPILED="$(dirname "$0")/nginx.conf"
# Copy certs from Let's Encrypt live directory to current_certs.
# The live directory is owned by root (created by certbot container),
# so we use a container to perform the copy.
if [ -d "${SSL_CERT_DIR}/live" ]; then
$CONTAINER_ENGINE run --rm \
-v "${SSL_CERT_DIR}:/etc/letsencrypt:ro" \
-v "${SSL_CERT_CURRENT}:/out" \
alpine sh -c 'cp /etc/letsencrypt/live/*/* /out/ 2>/dev/null'
else
echo "Warning: Couldn't find letsencrypt certs under ${SSL_CERT_DIR}/live"
fi
# Process nginx.conf.template with environment variables
export DOMAIN
envsubst '$DOMAIN' < ${NGINX_CONFIG_SRC} > ${NGINX_CONFIG_COMPILED}
# Stop and remove the Docker/Podman container if it already exists
if [ $($CONTAINER_ENGINE ps -a -f name=$CONTAINER_NAME | grep -w $CONTAINER_NAME | wc -l) -eq 1 ]; then
echo "Stopping and removing existing container..."
$CONTAINER_ENGINE stop $CONTAINER_NAME
$CONTAINER_ENGINE rm $CONTAINER_NAME
fi
# Start a new Docker/Podman container with the Nginx image
echo "Starting new Nginx container..."
$CONTAINER_ENGINE run --name $CONTAINER_NAME \
-d \
-p 80:80 \
-p 443:443 \
-v $NGINX_CONFIG:/etc/nginx/nginx.conf:ro \
-v $SSL_CERT_CURRENT:/ssl:ro \
-v $SSL_WEBROOT:/webroot \
nginx