diff --git a/main.go b/main.go index f8e4041..98e5afd 100644 --- a/main.go +++ b/main.go @@ -11,6 +11,7 @@ import ( "path" "path/filepath" "os/user" + "os/exec" "strconv" ) @@ -23,7 +24,7 @@ type Cert struct { type Config struct { Source Cert Target Cert - Reload string + Reload []string WatchDelay string watcher *fsnotify.Watcher delay_time time.Duration @@ -130,13 +131,35 @@ func Copy(from string, to string, owner string) { } } +func (cfg *Config) RunReload() { + exe := cfg.Reload[0] + args := cfg.Reload[1:] + + cmd := exec.Command(exe, args...) + + stdout, err := cmd.StdoutPipe() + + go func() { + _, err := io.Copy(os.Stdout, stdout) + + if err != nil { + log.Fatalf("Can't log output") + } + }() + + err = cmd.Run() + if err != nil { + log.Fatalf("failed to run %v: %v", cfg.Reload, err) + } +} + func (cfg *Config) SyncCerts() { log.Println("SYNC CERTS CALLED") // copy the files, also changes ownership of target Copy(cfg.Source.PrivateKey, cfg.Target.PrivateKey, cfg.Target.Owner) Copy(cfg.Source.PublicKey, cfg.Target.PublicKey, cfg.Target.Owner) - // restart the service + cfg.RunReload() } func (cfg *Config) HandleEvents() {