Skip to main content

2 posts tagged with "TLS"

View all tags

Cert Alert Every Day? cPanel Keeps Stale Cert Generations

Β· 6 min read

A certificate expiry monitor reported the same service certificate at "20 days left" every single day, while a live port probe showed the certificate actually in service was valid until 2027-02-08 β€” the alert and reality were more than two years apart.

Tracked this down while running managed hosting for a leading manufacturer's China site β€” certificate expiry monitoring is a standing patrol item on that cPanel server.

TL;DR​

The root of the false alarm is "shortest days β‰  live certificate": cPanel's service certificate directory (/var/cpanel/ssl/system/certs/) accumulates past generations β€” multiple generations coexist, nothing prunes them. A monitor that scans PEM files one by one counts the expired-but-unreferenced old generation too, whose negative remaining days stay under the 21-day threshold forever, so the alert repeats daily. The path out: check the *-NOT_AFTER markers in the directory plus a live s_client probe to identify the live cert, delete the unreferenced stale generation (crt and .cache), and the alert heals on the next scan with services untouched.

Symptoms: the cert alert fires daily, the live certificate has two years left​

The alert reported the minimum remaining days across certificates: some service certificate expiring in 20 days, repeating daily β€” as if a certificate were simultaneously expired and about to expire, forever.

Checking the alert against reality didn't add up. Live probes across the four service ports (s_client, reading the presented certificate) all pointed to the same current-generation certificate: NOT_AFTER marker 1802123049, which converts to 2027-02-08. The "20 days left" certificate β€” a Let's Encrypt past generation issued September 11, expiring December 10 β€” was referenced by no service at all. Long expired, it had disturbed no online service, only the monitor.

Root cause: generations coexist, file scans don't follow references​

cPanel installs service certificates by accumulating them into system/certs/: each renewal or reissue adds a new generation, and older generations stay where they are. The directory therefore holds several generations at any time.

The monitor scans by PEM file sniffing: it reads each file and computes remaining days per file, without checking which service actually references which certificate. The hostname filter is substring-based β€” every generation of the same hostname shares the same CN, so the filter cannot separate live from expired. The oldest expired generation thus sits permanently below the 21-day alert threshold and gets reported every scan. The monitor wasn't lying β€” it faithfully reported the oldest file in the directory. What lied was the default assumption "shortest-days file = live certificate."

Fix: NOT_AFTER plus a live probe identify the live cert; delete unreferenced generations​

Four steps, evidence first:

# 1. Each certificate has a NOT_AFTER marker file beside it (epoch); check markers first
ls /var/cpanel/ssl/system/certs/
cat /var/cpanel/ssl/system/certs/*-NOT_AFTER
# live generation marker 1802123049 β†’ date -r 1802123049 β†’ 2027-02-08

# 2. Live port probe: what certificate does the service actually present?
openssl s_client -connect <hostname>:2083 </dev/null 2>/dev/null \
| openssl x509 -noout -enddate
# output must match the live NOT_AFTER marker
# 3. With markers and probe both saying "not in service" and no references: delete stale generation
rm /var/cpanel/ssl/system/certs/<stale-generation>.crt
rm /var/cpanel/ssl/system/certs/<stale-generation>.cache

# 4. Verify: services intact + alert cleared
openssl s_client -connect <hostname>:2083 </dev/null 2>/dev/null | head -1
openssl s_client -connect <hostname>:993 </dev/null 2>/dev/null | head -1

Result of the actual run (2026-11-22): services on 2083 and 993 unaffected after deletion, and the alert stopped repeating from the next scan β€” the shortest remaining days in the directory became the live certificate's true count, and the monitor's view re-aligned with reality. This "file-scan, conclusion-style alerting" patrol is part of CCLee Server Sentinel's certificate monitoring β€” alerts are merged into conclusions with handling guidance; for the issuance side of certificates (AutoSSL not issuing), see cPanel AutoSSL Not Issuing? Self-Signed Certificate Fix.

Notes

  • Order of judgment for certificate alerts: check NOT_AFTER markers and live port probes before any action β€” the shortest remaining days is not necessarily the live certificate.
  • Delete only confirmed-unreferenced files; the live certificate and its .cache stay.
  • After deletion, verify both ways: port probes intact, alert gone on the next scan β€” both required.
  • Multiple generations of the same hostname share the same CN; substring filters cannot separate them β€” don't rely on filters, check the markers.

FAQ​

A certificate expiry alert keeps firing every day β€” what should I do?​

Identify the live certificate before acting: check the *-NOT_AFTER marker files under /var/cpanel/ssl/ and probe the actual port certificate with s_client. In this incident the alert's '20 days left' came from a stale generation file, while the live certificate was valid until 2027-02-08. Once the alert target is confirmed as an unreferenced stale file, delete it (crt plus .cache) and the alert clears on the next scan β€” no certificate replacement needed.

How do I tell which certificate is the live one?​

Cross-check two sources: the *-NOT_AFTER marker files beside each certificate in the directory (epoch timestamps), and a live port probe (s_client reading the actual expiry). For the live certificate the two values agree. Filenames, issue dates, or the shortest remaining-days figure in a monitor are all unreliable β€” in this case the shortest 20 days belonged precisely to an unreferenced stale generation.

Will deleting old certificate generations disrupt live services?​

Delete only files confirmed to be unreferenced (the crt and its .cache); leave the live certificate untouched. After the deletion, services on ports 2083 and 993 were unaffected and the alert cleared on the next scan. The precondition is evidence first: both the NOT_AFTER marker and the live probe must point to 'not in service' before deleting.

CCLEE

Independent developer, 24 years in e-commerce, focused on grounding AI in real business scenarios.

Work with me

cPanel Crash Loop? mycpanel.pem Needs Cert + Key in One File

Β· 6 min read

After a deploy script replaced the cPanel service certificate, cpanel.service fell into a crash loop: nothing listening on 2083/2087, and both WHM and cPanel were unreachable.

Encountered this while running managed hosting for a leading manufacturer's China site β€” an ongoing engagement covering monitoring, backups, and certificate deployment on a production cPanel/WHM server.

TL;DR​

One cause: /var/cpanel/ssl/cpanel/mycpanel.pem must be a single PEM combining the leaf certificate and the private key (the same shape as the pure-ftpd bundle), with the chain in mycpanel.cabundle; the split crt/key formats used by dovecot/exim are not interchangeable, and writing a fullchain into the pem is exactly the crashing form. A second trap sits in verification: restartsrv_cpsrvd exit 0 and an active unit mean nothing β€” SSL setup fails 1-6 seconds after start, so recovery is proven on port 2083.

Symptoms: panel down, service crash loop​

Right after writing the new certificate and restarting, the panel hostname stopped responding and both 2083/2087 had no listener. The journal and error_log show two faces of the same failure:

cpanel.service: Main process exited, status=25
cpsrvd: Failed to load SSL libraries or certificate from
/var/cpanel/ssl/cpanel/ at cpsrvd.pl line 724

The standard recovery path came first: restartsrv_cpsrvd returned 0 and systemctl is-active cpanel reported active β€” it looked recovered. Seconds later 2083 was still silent and the panel still unreachable, crash loop intact. Those two green lights that aren't green are the second topic of this post.

Root cause: mycpanel.pem is cert + key combined, not the chain​

cPanel's format requirement for cpsrvd (the panel service) differs from most services: mycpanel.pem holds the leaf certificate and private key combined, while the chain lives separately in mycpanel.cabundle. That matches the pure-ftpd bundle shape; dovecot/exim use split crt/key files β€” the three formats are not interchangeable:

ServiceCertificate file shape
cpsrvd (cPanel/WHM panel)mycpanel.pem combined (leaf+key) + mycpanel.cabundle (chain)
pure-ftpdcombined bundle (same shape as cpsrvd)
dovecot / eximsplit crt/key

The failing script wrote a fullchain β€” chain only, no private key β€” into mycpanel.pem. At startup cpsrvd loads SSL, finds no private key, and fails at cpsrvd.pl line 724; systemd starts the unit, the process exits immediately, status 25, and the cycle repeats. The certificate itself was fine; only the file shape was wrong.

One distinction worth making: this is the cPanel service certificate (hostname-level, serving the panel ports). Site domain certificates go through AutoSSL β€” a separate track; when issuance stalls there, check the exclusion list first, see cPanel AutoSSL Not Issuing? Self-Signed Certificate Fix.

The false-success detour: restartsrv exit 0 β‰  cpsrvd alive​

Timing is what makes this misleading. SSL setup fails 1-6 seconds after systemd starts the unit, while restartsrv_cpsrvd returned its 0 at start-up time and is-active sampled the pre-crash window β€” both signals landed before the crash, so both were green.

That pair of green lights is exactly what the triage trusted first: recovery declared on restartsrv 0 + active, then the panel still down, and only a direct curl against 2083 exposed the SSL load failure. Since then, liveness for cpsrvd on this server is judged only by port probes: curl -sv https://hostname:2083 or openssl s_client -connect hostname:2083, requiring a completed handshake with certificate details.

"State signal disconnected from actual usability" is not an one-off β€” the reverse variant, systemctl showing inactive while the process runs, is covered in systemctl Shows inactive But the Process Is Running? Bare-Process Health Check False Negative. The shared conclusion: probe the service through its own port/protocol, not through the process manager's word.

Fix: write per-service formats, verify on the port​

The repair is three steps: combined PEM in place, chain separated, acceptance on the port.

# leaf.pem = server certificate (leaf), privkey.pem = private key, cabundle.pem = chain
cat leaf.pem privkey.pem > /var/cpanel/ssl/cpanel/mycpanel.pem
cp cabundle.pem /var/cpanel/ssl/cpanel/mycpanel.cabundle
chown cpanel:cpanel /var/cpanel/ssl/cpanel/mycpanel*
chmod 660 /var/cpanel/ssl/cpanel/mycpanel*
systemctl restart cpanel

Acceptance ignores status signals and reads the port only:

curl -sv https://<hostname>:2083 -o /dev/null 2>&1 | grep -E 'subject|expire'
curl -sv https://<hostname>:2087 -o /dev/null 2>&1 | grep -E 'subject|expire'

Both commands must print the certificate subject and expiry before the panel ports count as recovered. After this incident the deploy script fixed the combined format in place and gained an end-to-end check: the hook prints DEPLOY-OK with all four service ports green.

For the other services, match the table above: dovecot/exim get split crt/key, pure-ftpd and cpsrvd get combined bundles. One certificate, three file shapes, none interchangeable.

Notes

  • Content order in mycpanel.pem: leaf certificate first, private key after; the chain goes into mycpanel.cabundle, never into the pem.
  • Permissions cpanel:cpanel 660 β€” too wide or too narrow, cpsrvd may refuse to load.
  • Acceptance is port probes only; restartsrv's exit code and is-active are not liveness evidence.
  • More AlmaLinux 10 + cPanel close-out pitfalls (TFA, missing resources, domain mounting): AlmaLinux 10 + cPanel: New-Server Pitfalls from TFA to DNS.

FAQ​

What goes in mycpanel.pem vs mycpanel.cabundle?​

mycpanel.pem is one PEM holding the leaf certificate followed by the private key, owned cpanel:cpanel with 660 permissions; the intermediate chain goes separately into mycpanel.cabundle. Writing a fullchain into mycpanel.pem produces exactly this crash β€” no private key in the file, cpsrvd fails SSL loading, and systemd reports status=25 in a loop.

Can the dovecot/exim certificate files be reused for cpsrvd?​

Not directly. cpsrvd expects a combined PEM (the same shape as the pure-ftpd bundle), while dovecot/exim use separate crt/key files β€” the formats are not interchangeable across the services. The same certificate must be written out in each service's own format.

restartsrv returned 0 and systemctl says active β€” is cpsrvd really alive?​

Neither signal is a liveness proof: SSL setup failed 1-6 seconds after systemd started the unit, long after restartsrv printed its exit 0, and is-active still showed active in that window. Probe port 2083 instead (curl -sv or openssl s_client); a completed TLS handshake is the only evidence that counts.

CCLEE

Independent developer, 24 years in e-commerce, focused on grounding AI in real business scenarios.

Work with me