@@ -4984,6 +4984,12 @@ R"x*x*x(<html>
4984
4984
{
4985
4985
walk_certificate (m_option.ssl_cert_path_ , certificates);
4986
4986
4987
+ // 按过期时间排序.
4988
+ std::sort (certificates.begin (), certificates.end (),
4989
+ [](const certificate_file& a, const certificate_file& b) {
4990
+ return a.expire_date_ < b.expire_date_ ;
4991
+ });
4992
+
4987
4993
for (const auto & ctx : certificates)
4988
4994
{
4989
4995
XLOG_DBG << " domain: '" << ctx.domain_
@@ -5063,11 +5069,33 @@ R"x*x*x(<html>
5063
5069
auto self = shared_from_this ();
5064
5070
boost::system ::error_code ec;
5065
5071
5072
+ // 定时检查证书是否过期, 按照过期时间排序, 从最小时间开始检查.
5066
5073
while (!m_abort)
5067
5074
{
5068
- // 每隔 7 天检查一次证书是否过期.
5069
- m_timer.expires_from_now (std::chrono::days (7 ));
5075
+ auto now = boost::posix_time::second_clock::universal_time ();
5076
+ std::chrono::seconds duration (std::chrono::days (1 ));
5077
+
5078
+ auto & certificates = *m_certificates;
5079
+
5080
+ for (const auto & ctx : certificates)
5081
+ {
5082
+ if (now > ctx.expire_date_ )
5083
+ {
5084
+ XLOG_WARN << " domain: '" << ctx.domain_
5085
+ << " ', cert: '" << ctx.cert_ .filepath_ .string ()
5086
+ << " ', key: '" << ctx.key_ .filepath_ .string ()
5087
+ << " ', dhparam: '" << ctx.dhparam_ .filepath_ .string ()
5088
+ << " ', pwd: '" << ctx.pwd_ .filepath_ .string ()
5089
+ << " ', expired: '" << ctx.expire_date_ << " '" ;
5090
+ continue ;
5091
+ }
5092
+
5093
+ duration = std::chrono::seconds ((ctx.expire_date_ - now).total_seconds ());
5094
+ break ;
5095
+ }
5070
5096
5097
+ // 每隔 duration 检查一次证书是否过期.
5098
+ m_timer.expires_from_now (duration);
5071
5099
co_await m_timer.async_wait (net_awaitable[ec]);
5072
5100
if (ec)
5073
5101
break ;
0 commit comments