Created
February 23, 2022 02:35
-
-
Save lstellway/29825ee8c68eeb8c2f9247d1e6e1fbf8 to your computer and use it in GitHub Desktop.
Helper script to update MySQL / MariaDB TLS after renewing LetsEncrypt certificate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
DOMAIN="$1" | |
SOURCE="/etc/letsencrypt/live/${DOMAIN}" | |
DESTINATION="/var/lib/mysql/pki" | |
USER="mysql." | |
# Validate provided domain | |
if [ -z "${DOMAIN}" ] || [ ! -d "${SOURCE}" ]; then | |
printf "Please enter a valid domain (provided '%s')\n" "${DOMAIN}" | |
exit 1 | |
fi | |
# Create files | |
mkdir -p "${DESTINATION}" | |
cp "${SOURCE}/cert.pem" "${DESTINATION}" | |
openssl x509 -in "${SOURCE}/chain.pem" > "${DESTINATION}/chain.pem" | |
openssl rsa -in "${SOURCE}/privkey.pem" -out "${DESTINATION}/privkey.pem" | |
# Set permissions | |
chown -R "${USER}" "${DESTINATION}" | |
chmod 600 $DESTINATION/*.pem | |
# Reload TLS | |
mysql --user=root --execute="FLUSH SSL" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example usage:
(where
example.com
represents the directory in/etc/letsencrypt/live/*
)