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"
|
2024-03-13 03:44:55 +00:00
|
|
|
|
|
|
|
"github.com/pterodactyl/wings/internal/ufs"
|
2019-12-01 02:07:05 +00:00
|
|
|
)
|
|
|
|
|
2024-03-13 03:44:55 +00:00
|
|
|
// UpdateConfigurationFiles updates all the defined configuration files for
|
2022-02-01 00:30:07 +00:00
|
|
|
// a server automatically to ensure that they always use the specified values.
|
2019-12-01 02:07:05 +00:00
|
|
|
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
|
|
|
|
2022-02-01 00:30:07 +00:00
|
|
|
s.Log().Debug("acquiring process configuration files...")
|
2020-07-18 23:03:25 +00:00
|
|
|
files := s.ProcessConfiguration().ConfigurationFiles
|
2022-02-01 00:30:07 +00:00
|
|
|
s.Log().Debug("acquired process configuration files")
|
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() {
|
2024-03-13 03:44:55 +00:00
|
|
|
file, err := s.Filesystem().UnixFS().Touch(f.FileName, ufs.O_RDWR|ufs.O_CREATE, 0o644)
|
2019-12-01 02:07:05 +00:00
|
|
|
if err != nil {
|
2024-03-13 03:44:55 +00:00
|
|
|
s.Log().WithField("file_name", f.FileName).WithField("error", err).Error("failed to open file for configuration")
|
2019-12-01 02:07:05 +00:00
|
|
|
return
|
|
|
|
}
|
2024-03-13 03:44:55 +00:00
|
|
|
defer file.Close()
|
2019-12-01 02:07:05 +00:00
|
|
|
|
2024-03-13 03:44:55 +00:00
|
|
|
if err := f.Parse(file); 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
|
|
|
}
|
2022-02-01 00:30:07 +00:00
|
|
|
|
2024-03-13 03:44:55 +00:00
|
|
|
s.Log().WithField("file_name", f.FileName).Debug("finished processing server configuration file")
|
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
|
|
|
}
|