|
|
|
@ -11,6 +11,7 @@ import ( |
|
|
|
"path" |
|
|
|
"path" |
|
|
|
"path/filepath" |
|
|
|
"path/filepath" |
|
|
|
"os/user" |
|
|
|
"os/user" |
|
|
|
|
|
|
|
"os/exec" |
|
|
|
"strconv" |
|
|
|
"strconv" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
@ -23,7 +24,7 @@ type Cert struct { |
|
|
|
type Config struct { |
|
|
|
type Config struct { |
|
|
|
Source Cert |
|
|
|
Source Cert |
|
|
|
Target Cert |
|
|
|
Target Cert |
|
|
|
Reload string |
|
|
|
Reload []string |
|
|
|
WatchDelay string |
|
|
|
WatchDelay string |
|
|
|
watcher *fsnotify.Watcher |
|
|
|
watcher *fsnotify.Watcher |
|
|
|
delay_time time.Duration |
|
|
|
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() { |
|
|
|
func (cfg *Config) SyncCerts() { |
|
|
|
log.Println("SYNC CERTS CALLED") |
|
|
|
log.Println("SYNC CERTS CALLED") |
|
|
|
// copy the files, also changes ownership of target
|
|
|
|
// copy the files, also changes ownership of target
|
|
|
|
Copy(cfg.Source.PrivateKey, cfg.Target.PrivateKey, cfg.Target.Owner) |
|
|
|
Copy(cfg.Source.PrivateKey, cfg.Target.PrivateKey, cfg.Target.Owner) |
|
|
|
Copy(cfg.Source.PublicKey, cfg.Target.PublicKey, cfg.Target.Owner) |
|
|
|
Copy(cfg.Source.PublicKey, cfg.Target.PublicKey, cfg.Target.Owner) |
|
|
|
|
|
|
|
|
|
|
|
// restart the service
|
|
|
|
cfg.RunReload() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (cfg *Config) HandleEvents() { |
|
|
|
func (cfg *Config) HandleEvents() { |
|
|
|
|