2018-02-05 06:03:08 +00:00
|
|
|
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()
|
2018-02-05 06:18:12 +00:00
|
|
|
|
|
|
|
go generateZonefiles()
|
2018-02-05 06:03:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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")
|
2018-02-05 06:03:08 +00:00
|
|
|
cmd.Stdout = iw
|
|
|
|
cmd.Stderr = ew
|
|
|
|
cmd.Dir = "/src"
|
|
|
|
|
|
|
|
if err := cmd.Run(); err != nil {
|
|
|
|
logger.WithError(err).Error("Command execution failed")
|
|
|
|
}
|
|
|
|
}
|