Skip to content

Commit

Permalink
Add a regular ping job
Browse files Browse the repository at this point in the history
  • Loading branch information
evenh committed Apr 27, 2019
1 parent 4d4391e commit d1f7123
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
7 changes: 4 additions & 3 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func StartClient(config *config.ClientConfig, userAgent string) {
}

// Set up scheduled tasks
tasks := configureTasks(config, certStorage)
tasks := configureTasks(client, config, certStorage)

// Handle termination
configureTermination(tasks)
Expand Down Expand Up @@ -114,12 +114,13 @@ func validateConfig(c *config.ClientConfig) error {
return nil
}

func configureTasks(config *config.ClientConfig, storage *CertStorage) []Job {
func configureTasks(client api.CertificateIssuerClient, config *config.ClientConfig, storage *CertStorage) []Job {
var tasks []Job

pinger := *Register(pingServer(client), "Ping intercert host", 10*time.Minute, false)
desiredCheck := *Register(ensureCertsFromConfig(storage, config.Domains), "Ensure configured domains is present", 1*time.Hour, true)

tasks = append(tasks, desiredCheck)
tasks = append(tasks, pinger, desiredCheck)

return tasks
}
12 changes: 12 additions & 0 deletions client/tasks.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
package client

import (
"context"
"github.com/evenh/intercert/api"
"github.com/go-acme/lego/log"
)

func pingServer(client api.CertificateIssuerClient) func() {
return func() {
_, err := client.Ping(context.Background(), &api.PingRequest{Msg: "ping"})

if err != nil {
log.Warnf("Could not ping intercert host: %v", err)
}
}
}

// Check that every cert from the config is present in the file system
func ensureCertsFromConfig(storage *CertStorage, wantedDomains []string) func() {
return func() {
Expand Down

0 comments on commit d1f7123

Please sign in to comment.