forked from TrueCloudLab/lego
Merge pull request #42 from xenolf/add-renew-time
Add a way for cronjobs to automatically renew certificates.
This commit is contained in:
commit
3cf9fe610f
2 changed files with 19 additions and 0 deletions
7
cli.go
7
cli.go
|
@ -47,6 +47,13 @@ func main() {
|
||||||
Name: "renew",
|
Name: "renew",
|
||||||
Usage: "Renew a certificate",
|
Usage: "Renew a certificate",
|
||||||
Action: renew,
|
Action: renew,
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
cli.IntFlag{
|
||||||
|
Name: "days",
|
||||||
|
Value: 0,
|
||||||
|
Usage: "The number of days left on a certificate to renew it.",
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/codegangsta/cli"
|
"github.com/codegangsta/cli"
|
||||||
"github.com/xenolf/lego/acme"
|
"github.com/xenolf/lego/acme"
|
||||||
|
@ -181,6 +182,17 @@ func renew(c *cli.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.IsSet("days") {
|
||||||
|
expTime, err := acme.GetPEMCertExpiration(certBytes)
|
||||||
|
if err != nil {
|
||||||
|
logger().Printf("Could not get Certification expiration for domain %s", domain)
|
||||||
|
}
|
||||||
|
|
||||||
|
if int(expTime.Sub(time.Now()).Hours() / 24.0) <= c.Int("days") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
keyBytes, err := ioutil.ReadFile(privPath)
|
keyBytes, err := ioutil.ReadFile(privPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger().Printf("Error while loading the private key for domain %s\n\t%v", domain, err)
|
logger().Printf("Error while loading the private key for domain %s\n\t%v", domain, err)
|
||||||
|
|
Loading…
Reference in a new issue