> ## Content Index
> Fetch the complete content index at: https://blog.sudowl.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# KeyHelp Let's Encrypt Race: Two Cert Jobs Took Apache Down for 21 Minutes
- URL: https://blog.sudowl.com/keyhelp-letsencrypt-race-apache-down/
- Published: 2026-11-12T09:30:00.000Z
- Updated: 2026-11-18T12:34:02.000Z
- Description: I ran KeyHelp's ssl-maintenance by hand while its own job ran. Key and cert from two runs got mixed and a graceful reload killed Apache.
- Author: Lukas
- Tags: Linux, Security

Last night every website on my own KeyHelp server was down for about 21 minutes, from 23:08 to 23:29\. Mail kept working. Web, the panel, everything on port 443 was gone. Nothing alerted me. I found it by accident while checking something unrelated.

The cause was me being impatient with a Let's Encrypt job.

**TL;DR:** Adding a mail subdomain with Let's Encrypt made KeyHelp create a `www.` alias for it, which failed validation. I deleted the alias and started `ssl-maintenance` by hand. KeyHelp's own job ran at the same time. The result was a `complete.pem` where the private key did not belong to the certificate. The next graceful reload killed Apache. The syntax check said everything was fine. Fix: fresh cert with certbot standalone, copy the files into KeyHelp's folder, start Apache. Lesson: never run `ssl-maintenance` by hand while the panel might be running it, and compare key and cert before any reload.

## The check that would have caught it

This compares the public key in the certificate with the one derived from the private key. If the hashes differ, Apache won't start with that file.

```bash
# KeyHelp keeps LE files per user and domain
D=/etc/ssl/keyhelp/letsencrypt/alice/mail.example.com

openssl x509 -in "$D/complete.pem" -noout -pubkey | md5sum
openssl pkey -in "$D/complete.pem" -pubout | md5sum

```

`complete.pem` in KeyHelp is the private key plus the full chain in one file, so both commands can read the same file. `openssl x509` takes the first certificate, `openssl pkey` takes the key.

For all domains of one user at once:

```bash
for d in /etc/ssl/keyhelp/letsencrypt/alice/*/; do
  [ -f "$d/complete.pem" ] || continue
  a=$(openssl x509 -in "$d/complete.pem" -noout -pubkey 2>&1 | md5sum | cut -c1-8)
  b=$(openssl pkey -in "$d/complete.pem" -pubout 2>&1 | md5sum | cut -c1-8)
  [ "$a" = "$b" ] && echo "ok       $(basename "$d")" || echo "MISMATCH $(basename "$d") cert=$a key=$b"
done

```

During the outage, the four domains of that user looked like this (names replaced):

```text
example.com cert=9b81b183 key=9b81b183
www.example.com cert=8f66b8ac key=8f66b8ac
cloud.example.com cert=bc43a29a key=bc43a29a
mail.example.com cert=7c609d0c key=0c8e682a

```

Three fine, one broken. That one broken file was enough to take down every site on the server.

## What I actually did

The server had just taken over a client's website, Nextcloud and mailboxes. The last piece was a proper certificate for the mail hostname `mail.example.com`.

In KeyHelp that means: add `mail.example.com` as its own domain, mark it as a mail domain, turn on Let's Encrypt. I did that through the KeyHelp API and then ran the cert job right away instead of waiting for the panel:

```bash
cd /home/keyhelp/www/keyhelp
php bin/keyhelp.php run ssl-maintenance

```

The log came back with this:

```text
ERROR | a Let's Encrypt error occurred: Local resolving checks failed for domain "www.mail.example.com". Please ensure that your domain is locally resolvable!
...
INFO | Apache: syntax ok
INFO | Apache: reloading apache
INFO | <<< job done, releasing lock "ssl-maintenance"

```

## Gotcha: KeyHelp adds www to everything

KeyHelp created `www.mail.example.com` on its own, as an alias of the new domain. That name has no DNS record, so the Let's Encrypt check failed. The other certs of that user were fine.

So I deleted the `www.mail` domain and started `ssl-maintenance` by hand again, about 20 seconds after the first run. This time the cert for `mail.example.com` came through and the SNI config for Postfix and Dovecot got updated. I tested the mail ports from the server, all five gave `Verify return code: 0 (ok)`. Web worked too. I moved on.

## Gotcha: two runs, one folder

What I didn't know: KeyHelp was handling the same domain change in the background at the same time. The Apache journal shows four reloads in under 40 seconds:

```text
23:07:47 Reloaded apache2.service
23:08:02 Reloaded apache2.service
23:08:14 Reloaded apache2.service
23:08:26 Reloaded apache2.service
23:08:26 apache2.service: Main process exited, code=exited, status=1/FAILURE

```

Every file in the mail domain's cert folder had a timestamp of 23:08\. Between my manual run and KeyHelp's own, the folder ended up with a certificate from one run and a private key from the other. The job logs a lock called `ssl-maintenance`, and I had assumed that makes a manual run safe. It didn't save me.

KeyHelp's last reload at 23:08:26 was a graceful restart. Apache re-read the config, couldn't load the key for that vhost, and the main process exited. With a graceful reload there is no "keep the old config running". If the new config fails, Apache is gone.

## Gotcha: the error log doesn't tell you which file

This is what `error.log` showed at that moment, shortened:

```text
AH00493: SIGUSR1 received.  Doing graceful restart
AH02218: ssl_stapling_init_cert: no OCSP URI in certificate ...
AH01906: webmail:443:0 server certificate is a CA certificate ...
AH01909: webmail:443:0 server certificate does NOT include an ID which matches the server name
AH00020: Configuration Failed, exiting

```

Stapling noise, warnings about KeyHelp's self-signed webmail vhost, then "Configuration Failed". No line naming the file. I first went looking for missing cert files and log folders. Both were fine.

And `apache2ctl -t` said the syntax was OK. KeyHelp's own job also logs `Apache: syntax ok` before it reloads. A syntax check is exactly that. It does not tell you that a key and a certificate belong together.

From then on something tried to start Apache once a minute. Every attempt failed the same way, because the file on disk was still broken.

## The fix

First I turned Let's Encrypt off for the mail domain in KeyHelp and tried to start Apache. Still failed. The vhost still pointed at the broken `complete.pem`.

Since Apache was dead anyway, port 80 was free. So I got a fresh cert with certbot in standalone mode and copied it into KeyHelp's layout:

```bash
certbot certonly --standalone --non-interactive --agree-tos \
  --register-unsafely-without-email \
  -d mail.example.com --cert-name mail.example.com

L=/etc/letsencrypt/live/mail.example.com
P=/etc/ssl/keyhelp/letsencrypt/alice/mail.example.com

# keep the broken files for later
mkdir -p /root/backups/mail-broken && cp -a "$P/." /root/backups/mail-broken/

cp "$L/privkey.pem"   "$P/private.pem"
cp "$L/cert.pem"      "$P/cert.pem"
cp "$L/chain.pem"     "$P/chain.pem"
cp "$L/fullchain.pem" "$P/fullchain.pem"
cat "$L/privkey.pem" "$L/fullchain.pem" > "$P/complete.pem"
openssl pkey -in "$P/private.pem" -pubout > "$P/public.pem"
chmod 600 "$P"/*.pem

# compare before starting anything
openssl x509 -in "$P/complete.pem" -noout -pubkey | md5sum
openssl pkey -in "$P/complete.pem" -pubout | md5sum

systemctl start apache2 && systemctl is-active apache2
systemctl reload dovecot postfix

```

Hashes matched, Apache came up at 23:29\. All sites answered with 200 again, the mail ports verified fine.

Then the cleanup. I deleted the certbot copy with `certbot delete --cert-name mail.example.com`, so two renewal systems don't fight over the same name later. I turned Let's Encrypt back on in KeyHelp for the domain. Then I watched the folder for three minutes, one check every 30 seconds: Apache state, key/cert pair, modification time. KeyHelp left the files alone, the pair stayed matched. From now on KeyHelp renews it like every other cert.

If the cert-in-panel vs certbot topic sounds familiar, I wrote about the reverse situation in [moving off expired Plesk certs to certbot](/plesk-letsencrypt-expired-certbot-migration/).

## Gotcha: nobody was watching port 443

The outage started at 23:08\. I noticed at 23:26, because I wanted to see what the server's hostname shows in a browser and got "connection refused". That's 18 minutes of everything being down while I was looking at other things on the same server.

A simple HTTP check every minute would have caught it right away. [Uptime Kuma](/uptime-kuma-self-hosted-monitoring/) does that with almost no setup. Run it somewhere else, not on the box it watches.

## What I do now

1. **Never start `ssl-maintenance` by hand** when KeyHelp might be running it too. After a domain or LE change in the panel or the API, wait for the panel to do its thing.
2. **After any domain or Let's Encrypt change**, run the key/cert loop above and `systemctl is-active apache2`. Takes two seconds.
3. **Don't trust `apache2ctl -t`** for cert problems. It checks syntax, not whether files belong together.
4. **Kill the `www.` alias early.** For subdomains like `mail.`, remove the `www.` version KeyHelp adds before Let's Encrypt runs.
5. **External uptime check on 443** for every server that serves more than one site.
6. **Keep the broken files** before fixing, so you can look at them later.

If you're on KeyHelp too, there are a few more surprises around Docker in [KeyHelp's firewall breaking Docker](/keyhelp-firewall-breaks-docker/), and the reasons I picked it in the first place are in [KeyHelp as a free Plesk alternative](/keyhelp-free-plesk-alternative/).

The panel was right to reload. My manual run was the problem. Let the panel do its job, and check the result before Apache does.

---

### Related posts

- [I Launched a Waitlist Page in One Night. Here's Everything That Broke](https://blog.sudowl.com/waitlist-page-one-night-self-hosted/)
- [Brother Scan to SFTP: Receipts Straight Into a Hetzner Storage Box](https://blog.sudowl.com/brother-scan-to-sftp-storage-box/)
- [T-Online Rejects My Server: "554 Dialup/transient IP not allowed"](https://blog.sudowl.com/t-online-554-dialup-transient-ip-not-allowed/)