Always rebuild the container when a server is started
This commit is contained in:
		
							parent
							
								
									fabaf21a0d
								
							
						
					
					
						commit
						2d0faadeb6
					
				| 
						 | 
					@ -156,33 +156,12 @@ func (d *DockerEnvironment) OnBeforeStart() error {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// If the server requires a rebuild, go ahead and delete the container from the system which
 | 
						// Always destroy and re-create the server container to ensure that synced data from
 | 
				
			||||||
	// will allow the subsequent Create() call to create a new container instance for the server
 | 
						// the Panel is used.
 | 
				
			||||||
	// to run in.
 | 
						if err := d.Client.ContainerRemove(context.Background(), d.Server.Uuid, types.ContainerRemoveOptions{RemoveVolumes: true}); err != nil {
 | 
				
			||||||
	if d.Server.Container.RebuildRequired {
 | 
							if !client.IsErrNotFound(err) {
 | 
				
			||||||
		if err := d.Client.ContainerRemove(context.Background(), d.Server.Uuid, types.ContainerRemoveOptions{RemoveVolumes: true}); err != nil {
 | 
								return err
 | 
				
			||||||
			if !client.IsErrNotFound(err) {
 | 
					 | 
				
			||||||
				return err
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					 | 
				
			||||||
		// Reset and persist the container rebuild status so that we don't continually
 | 
					 | 
				
			||||||
		// try and rebuild the container when the server is booted.
 | 
					 | 
				
			||||||
		d.Server.Container.RebuildRequired = false
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		// Write the configuration to the disk in a seperate process so that we can rapidly
 | 
					 | 
				
			||||||
		// move on with booting the server without waiting on an IO operation to complete.
 | 
					 | 
				
			||||||
		go func(serv *Server) {
 | 
					 | 
				
			||||||
			if _, err := serv.WriteConfigurationToDisk(); err != nil {
 | 
					 | 
				
			||||||
				// Don't kill the process if there is an error writing the configuration to the disk
 | 
					 | 
				
			||||||
				// but we do want to go ahead and notify the logger about it.
 | 
					 | 
				
			||||||
				zap.S().Warnw(
 | 
					 | 
				
			||||||
					"failed to write server configuration to disk after setting rebuild_required=false in configuration",
 | 
					 | 
				
			||||||
					zap.String("server", serv.Uuid),
 | 
					 | 
				
			||||||
					zap.Error(errors.WithStack(err)),
 | 
					 | 
				
			||||||
				)
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}(d.Server)
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// The Create() function will check if the container exists in the first place, and if
 | 
						// The Create() function will check if the container exists in the first place, and if
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -58,8 +58,6 @@ type Server struct {
 | 
				
			||||||
		// If set to true, OOM killer will be disabled on the server's Docker container.
 | 
							// If set to true, OOM killer will be disabled on the server's Docker container.
 | 
				
			||||||
		// If not present (nil) we will default to disabling it.
 | 
							// If not present (nil) we will default to disabling it.
 | 
				
			||||||
		OomDisabled bool `default:"true" json:"oom_disabled" yaml:"oom_disabled"`
 | 
							OomDisabled bool `default:"true" json:"oom_disabled" yaml:"oom_disabled"`
 | 
				
			||||||
		// Defines if the container needs to be rebuilt on the next boot.
 | 
					 | 
				
			||||||
		RebuildRequired bool `default:"false" json:"rebuild_required,omitempty" yaml:"rebuild_required"`
 | 
					 | 
				
			||||||
	} `json:"container,omitempty"`
 | 
						} `json:"container,omitempty"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Server cache used to store frequently requested information in memory and make
 | 
						// Server cache used to store frequently requested information in memory and make
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -71,7 +71,6 @@ func (s *Server) UpdateDataStructure(data []byte, background bool) error {
 | 
				
			||||||
		s.Allocations.Mappings = src.Allocations.Mappings
 | 
							s.Allocations.Mappings = src.Allocations.Mappings
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	s.Container.RebuildRequired = true
 | 
					 | 
				
			||||||
	if _, err := s.WriteConfigurationToDisk(); err != nil {
 | 
						if _, err := s.WriteConfigurationToDisk(); err != nil {
 | 
				
			||||||
		return errors.WithStack(err)
 | 
							return errors.WithStack(err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user