mirror of
https://github.com/Luzifer/dns.git
synced 2024-11-09 22:50:06 +00:00
44 lines
790 B
Go
44 lines
790 B
Go
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()
|
|
|
|
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")
|
|
}
|
|
}
|