@@ -30,7 +30,7 @@ const internalCertificate = {
30
30
intervalTimeout : 1000 * 60 * 60 , // 1 hour
31
31
interval : null ,
32
32
intervalProcessing : false ,
33
- renewBeforeExpirationBy : [ 7 , 'days' ] ,
33
+ renewBeforeExpirationBy : [ 30 , 'days' ] ,
34
34
35
35
initTimer : ( ) => {
36
36
logger . info ( 'Let\'s Encrypt Renewal Timer initialized' ) ;
@@ -49,7 +49,7 @@ const internalCertificate = {
49
49
50
50
const expirationThreshold = moment ( ) . add ( internalCertificate . renewBeforeExpirationBy [ 0 ] , internalCertificate . renewBeforeExpirationBy [ 1 ] ) . format ( 'YYYY-MM-DD HH:mm:ss' ) ;
51
51
52
- // Fetch all the letsencrypt certs from the db that will expire within 7 days
52
+ // Fetch all the letsencrypt certs from the db that will expire within N days
53
53
certificateModel
54
54
. query ( )
55
55
. where ( 'is_deleted' , 0 )
@@ -60,28 +60,32 @@ const internalCertificate = {
60
60
return null ;
61
61
}
62
62
63
- let promises = [ ] ;
63
+ /**
64
+ * Renews must be run sequentially or we'll get an error 'Another
65
+ * instance of Certbot is already running.'
66
+ */
67
+ let sequence = Promise . resolve ( ) ;
64
68
65
69
certificates . forEach ( function ( certificate ) {
66
- const promise = internalCertificate
67
- . renew (
68
- {
69
- can : ( ) =>
70
- Promise . resolve ( {
71
- permission_visibility : 'all' ,
72
- } ) ,
73
- } ,
74
- { id : certificate . id } ,
75
- )
76
- . catch ( ( err ) => {
77
- // Don't want to stop the train here, just log the error
78
- logger . error ( err . message ) ;
79
- } ) ;
80
-
81
- promises . push ( promise ) ;
70
+ sequence = sequence . then ( ( ) =>
71
+ internalCertificate
72
+ . renew (
73
+ {
74
+ can : ( ) =>
75
+ Promise . resolve ( {
76
+ permission_visibility : 'all' ,
77
+ } ) ,
78
+ } ,
79
+ { id : certificate . id } ,
80
+ )
81
+ . catch ( ( err ) => {
82
+ // Don't want to stop the train here, just log the error
83
+ logger . error ( err . message ) ;
84
+ } ) ,
85
+ ) ;
82
86
} ) ;
83
87
84
- return Promise . all ( promises ) ;
88
+ return sequence ;
85
89
} )
86
90
. then ( ( ) => {
87
91
internalCertificate . intervalProcessing = false ;
0 commit comments