-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
45 lines (38 loc) · 1.35 KB
/
run.sh
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
#!/usr/bin/with-contenv bash
# Start the Flask app with SSL
# Enable debug mode for the shell script (optional but helpful for troubleshooting)
#set -x
# Define absolute paths to the SSL certificates
CERT_FILE="/config/pantry_data/keys/cert.pem"
KEY_FILE="/config/pantry_data/keys/key.pem"
# Ensure the keys directory exists
mkdir -p /config/pantry_data/keys
# Function to generate self-signed SSL certificates
generate_certificates() {
echo "Generating self-signed SSL certificates..."
openssl req -x509 -newkey rsa:4096 -nodes \
-keyout "$KEY_FILE" -out "$CERT_FILE" \
-days 365 -subj "/CN=localhost"
if [ $? -eq 0 ]; then
echo "Certificates generated successfully at $CERT_FILE and $KEY_FILE"
else
echo "Failed to generate SSL certificates."
exit 1
fi
}
# Check if certificates already exist
if [ ! -f "$CERT_FILE" ] || [ ! -f "$KEY_FILE" ]; then
generate_certificates
else
echo "SSL certificates already exist. Skipping generation."
fi
# Verify that certificates exist after generation
if [ -f "$CERT_FILE" ] && [ -f "$KEY_FILE" ]; then
echo "SSL certificates are present."
else
echo "Failed to generate SSL certificates."
exit 1
fi
# Start the Flask app with SSL using exec to replace the shell with the Flask process
echo "Starting Flask app with SSL..."
exec python /opt/webapp/app.py