Skip to content

Commit 18721e4

Browse files
authored
Cronjob for cleaning up expired SSL certificates in order to improve page load times with many domains (#2410)
Fixes #2316.
1 parent e0b9371 commit 18721e4

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

setup/ssl.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,12 @@ fi
9696
if [ ! -f "$STORAGE_ROOT/ssl/dh2048.pem" ]; then
9797
openssl dhparam -out "$STORAGE_ROOT/ssl/dh2048.pem" 2048
9898
fi
99+
100+
# Cleanup expired SSL certificates from $STORAGE_ROOT/ssl daily
101+
cat > /etc/cron.daily/mailinabox-ssl-cleanup << EOF;
102+
#!/bin/bash
103+
# Mail-in-a-Box
104+
# Cleanup expired SSL certificates
105+
$(pwd)/tools/ssl_cleanup
106+
EOF
107+
chmod +x /etc/cron.daily/mailinabox-ssl-cleanup

tools/ssl_cleanup

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
# Cleanup SSL certificates which expired more than 7 days ago from $STORAGE_ROOT/ssl and move them to $STORAGE_ROOT/ssl.expired
3+
4+
source /etc/mailinabox.conf
5+
shopt -s extglob
6+
7+
retain_after="$(date --date="7 days ago" +%Y%m%d)"
8+
9+
mkdir -p $STORAGE_ROOT/ssl.expired
10+
for file in $STORAGE_ROOT/ssl/*-+([0-9])-+([0-9a-f]).pem; do
11+
pem="$(basename "$file")"
12+
not_valid_after="$(cut -d- -f1 <<< "${pem: -21}")"
13+
14+
if [ "$not_valid_after" -lt "$retain_after" ]; then
15+
mv "$file" "$STORAGE_ROOT/ssl.expired/${pem}"
16+
fi
17+
done

0 commit comments

Comments
 (0)