Code cleanup
This commit is contained in:
parent
0cbaad5c72
commit
16467fa7ff
|
@ -80,7 +80,7 @@ func New(data []byte) (*Installer, error) {
|
|||
|
||||
// Create a new server instance using the configuration we wrote to the disk
|
||||
// so that everything gets instantiated correctly on the struct.
|
||||
s, err := server.FromConfiguration(c)
|
||||
s, err := server.FromConfiguration(c, true)
|
||||
|
||||
return &Installer{
|
||||
server: s,
|
||||
|
|
|
@ -43,18 +43,21 @@ func LoadDirectory() error {
|
|||
return errors.New(rerr.String())
|
||||
}
|
||||
|
||||
log.Debug("retrieving cached server states from disk")
|
||||
states, err := getServerStates()
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
log.WithField("total_configs", len(configs)).Debug("looping over received configurations from API")
|
||||
for uuid, data := range configs {
|
||||
wg.Add()
|
||||
|
||||
go func(uuid string, data *api.ServerConfigurationResponse) {
|
||||
defer wg.Done()
|
||||
|
||||
s, err := FromConfiguration(data)
|
||||
log.WithField("uuid", uuid).Debug("creating server object from configuration")
|
||||
s, err := FromConfiguration(data, false)
|
||||
if err != nil {
|
||||
log.WithField("server", uuid).WithField("error", err).Error("failed to load server, skipping...")
|
||||
return
|
||||
|
@ -79,7 +82,7 @@ func LoadDirectory() error {
|
|||
// Initializes a server using a data byte array. This will be marshaled into the
|
||||
// given struct using a YAML marshaler. This will also configure the given environment
|
||||
// for a server.
|
||||
func FromConfiguration(data *api.ServerConfigurationResponse) (*Server, error) {
|
||||
func FromConfiguration(data *api.ServerConfigurationResponse, sync bool) (*Server, error) {
|
||||
cfg := Configuration{}
|
||||
if err := defaults.Set(&cfg); err != nil {
|
||||
return nil, err
|
||||
|
@ -111,9 +114,11 @@ func FromConfiguration(data *api.ServerConfigurationResponse) (*Server, error) {
|
|||
}
|
||||
|
||||
// Forces the configuration to be synced with the panel.
|
||||
if sync {
|
||||
if err := s.SyncWithConfiguration(data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return s, nil
|
||||
}
|
||||
|
|
|
@ -133,5 +133,7 @@ func (s *Server) GetState() string {
|
|||
// environment state, it is simply the tracked state from this daemon instance, and
|
||||
// not the response from Docker.
|
||||
func (s *Server) IsRunning() bool {
|
||||
return s.GetState() == ProcessRunningState || s.GetState() == ProcessStartingState
|
||||
st := s.GetState()
|
||||
|
||||
return st == ProcessRunningState || st == ProcessStartingState
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user