From 6608b32157c335e761a0a7b5d8960ba5506eec36 Mon Sep 17 00:00:00 2001 From: Kaitlyn Parkhurst Date: Sat, 19 Nov 2022 22:56:36 -0800 Subject: [PATCH] Real sync ssl task. --- Web/lib/MJB/Web/Task/CreateSSLCert.pm | 8 +++++--- Web/lib/MJB/Web/Task/SyncSSLCerts.pm | 10 ++++++++-- Web/lib/MJB/Web/Task/UpdateSSLCerts.pm | 8 ++++++-- Web/lib/MJB/Web/Task/WildCardSSL.pm | 8 +++++--- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/Web/lib/MJB/Web/Task/CreateSSLCert.pm b/Web/lib/MJB/Web/Task/CreateSSLCert.pm index d302a59..710eda6 100644 --- a/Web/lib/MJB/Web/Task/CreateSSLCert.pm +++ b/Web/lib/MJB/Web/Task/CreateSSLCert.pm @@ -22,9 +22,11 @@ sub run ( $job, $blog_id ) { $job->note( is_create_done => 1 ); # Push the SSL Certs to all hosts - my $result_sync = $job->system_command( [ - qw(sudo letsencrypt-cert-push) - ]); + my $id = $job->app->minion->enqueue( 'sync_ssl_certs', [ ], { + queue => 'certbot', + notes => { '_bid_0' => 1 }, + }); + $job->app->db->admin_jobs->create({ minion_job_id => $id }); $job->note( is_sync_done => 1 ); diff --git a/Web/lib/MJB/Web/Task/SyncSSLCerts.pm b/Web/lib/MJB/Web/Task/SyncSSLCerts.pm index 43c5152..fd02db7 100644 --- a/Web/lib/MJB/Web/Task/SyncSSLCerts.pm +++ b/Web/lib/MJB/Web/Task/SyncSSLCerts.pm @@ -13,8 +13,14 @@ use IPC::Run3; sub run ( $job ) { $job->note( _job_template => 'sync_ssl_certs' ); - # Push the SSL Certificates - my $result = $job->system_command( [ 'sudo', 'letsencrypt-cert-push' ] ); + my $servers = $job->app->db->servers; + my $source = '/etc/letsencrypt/live'; + my $ssh_opt = 'ssh -o StrictHostKeyChecking=no'; + + while ( my $server = $servers->next ) { + my $dest = "root@" . $server->hostname . ":/etc/letsencrypt"; + $job->system_command( [ qw( rsync -vrLptgoD --delete -e ), $ssh_opt, $source, $dest ]); + } $job->note( is_sync_done => 1 ); diff --git a/Web/lib/MJB/Web/Task/UpdateSSLCerts.pm b/Web/lib/MJB/Web/Task/UpdateSSLCerts.pm index 1d2f8f9..a9d5d79 100644 --- a/Web/lib/MJB/Web/Task/UpdateSSLCerts.pm +++ b/Web/lib/MJB/Web/Task/UpdateSSLCerts.pm @@ -17,8 +17,12 @@ sub run ( $job ) { $job->system_command( [ 'sudo', 'certbot', 'renew' ] ); $job->note( is_renew_done => 1 ); - # Push the SSL Certificates - $job->system_command( [ 'sudo', 'letsencrypt-cert-push' ] ); + # Push the SSL Certs to all hosts + my $id = $job->app->minion->enqueue( 'sync_ssl_certs', [ ], { + queue => 'certbot', + notes => { '_bid_0' => 1 }, + }); + $job->app->db->admin_jobs->create({ minion_job_id => $id }); $job->note( is_sync_done => 1 ); diff --git a/Web/lib/MJB/Web/Task/WildCardSSL.pm b/Web/lib/MJB/Web/Task/WildCardSSL.pm index 4e32448..b49d027 100644 --- a/Web/lib/MJB/Web/Task/WildCardSSL.pm +++ b/Web/lib/MJB/Web/Task/WildCardSSL.pm @@ -22,9 +22,11 @@ sub run ( $job, $hosted_domain_id ) { $job->note( is_create_done => 1 ); # Push the SSL Certs to all hosts - my $result_sync = $job->system_command( [ - qw(sudo letsencrypt-cert-push) - ]); + my $id = $job->app->minion->enqueue( 'sync_ssl_certs', [ ], { + queue => 'certbot', + notes => { '_bid_0' => 1 }, + }); + $job->app->db->admin_jobs->create({ minion_job_id => $id }); $job->note( is_sync_done => 1 );