2019-12-01 02:07:05 +00:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
2020-08-01 04:25:57 +00:00
|
|
|
"runtime"
|
2021-01-10 01:22:39 +00:00
|
|
|
|
|
|
|
"github.com/gammazero/workerpool"
|
2019-12-01 02:07:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Parent function that will update all of the defined configuration files for a server
|
|
|
|
// automatically to ensure that they always use the specified values.
|
|
|
|
func (s *Server) UpdateConfigurationFiles() {
|
2020-08-01 04:31:53 +00:00
|
|
|
pool := workerpool.New(runtime.NumCPU())
|
2019-12-01 02:07:05 +00:00
|
|
|
|
2020-07-18 23:03:25 +00:00
|
|
|
files := s.ProcessConfiguration().ConfigurationFiles
|
2020-08-01 04:25:57 +00:00
|
|
|
for _, cf := range files {
|
|
|
|
f := cf
|
2019-12-01 02:07:05 +00:00
|
|
|
|
2020-08-01 04:25:57 +00:00
|
|
|
pool.Submit(func() {
|
2020-09-27 19:24:08 +00:00
|
|
|
p, err := s.Filesystem().SafePath(f.FileName)
|
2019-12-01 02:07:05 +00:00
|
|
|
if err != nil {
|
2020-08-01 04:25:57 +00:00
|
|
|
s.Log().WithField("error", err).Error("failed to generate safe path for configuration file")
|
2019-12-01 02:07:05 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-12-08 00:48:26 +00:00
|
|
|
if err := f.Parse(p, false); err != nil {
|
2020-08-01 04:25:57 +00:00
|
|
|
s.Log().WithField("error", err).Error("failed to parse and update server configuration file")
|
2019-12-01 02:07:05 +00:00
|
|
|
}
|
2020-08-01 04:25:57 +00:00
|
|
|
})
|
2019-12-01 02:07:05 +00:00
|
|
|
}
|
|
|
|
|
2020-08-01 04:25:57 +00:00
|
|
|
pool.StopWait()
|
2020-09-05 19:08:40 +00:00
|
|
|
}
|