1
0
Fork 0
mirror of https://github.com/Luzifer/dns.git synced 2024-12-23 03:11:20 +00:00
dns/cron_generate.go

45 lines
790 B
Go
Raw Normal View History

package main
import (
"context"
"os/exec"
"time"
"github.com/Sirupsen/logrus"
"github.com/robfig/cron"
)
func init() {
c := cron.New()
c.AddFunc("0 * * * * *", generateZonefiles)
c.Start()
go generateZonefiles()
}
func generateZonefiles() {
logger := logrus.WithFields(logrus.Fields{
"fkt": "generateZonefiles",
})
var (
iw = logger.WriterLevel(logrus.InfoLevel)
ew = logger.WriterLevel(logrus.ErrorLevel)
)
defer iw.Close()
defer ew.Close()
ctx, cancel := context.WithTimeout(context.Background(), 59*time.Second)
defer cancel()
2018-02-05 06:34:59 +00:00
cmd := exec.CommandContext(ctx, "/usr/bin/python3", "generateZonefiles.py")
cmd.Stdout = iw
cmd.Stderr = ew
cmd.Dir = "/src"
if err := cmd.Run(); err != nil {
logger.WithError(err).Error("Command execution failed")
}
}