Add transfer logging output (#77)

Co-authored-by: Dane Everitt <dane@daneeveritt.com>
This commit is contained in:
Matthew Penner
2020-12-25 14:32:41 -07:00
committed by GitHub
parent 901ab1157d
commit 5c78cb9ab3
16 changed files with 398 additions and 227 deletions

View File

@@ -130,7 +130,7 @@ func (s *S3Backup) generateRemoteRequest(rc io.ReadCloser) error {
}
}
l.Info("backup has been successfully uploaded")
l.WithField("parts", partCount).Info("backup has been successfully uploaded")
return nil
}

View File

@@ -60,6 +60,8 @@ func (c *Collection) Find(filter func(*Server) bool) *Server {
}
// Removes all items from the collection that match the filter function.
//
// TODO: cancel the context?
func (c *Collection) Remove(filter func(*Server) bool) {
c.Lock()
defer c.Unlock()

View File

@@ -4,8 +4,12 @@ import (
"emperror.dev/errors"
)
var ErrIsRunning = errors.New("server is running")
var ErrSuspended = errors.New("server is currently in a suspended state")
var (
ErrIsRunning = errors.New("server is running")
ErrSuspended = errors.New("server is currently in a suspended state")
ErrServerIsInstalling = errors.New("server is currently installing")
ErrServerIsTransferring = errors.New("server is currently being transferred")
)
type crashTooFrequent struct {
}

View File

@@ -15,6 +15,8 @@ const (
StatusEvent = "status"
StatsEvent = "stats"
BackupCompletedEvent = "backup completed"
TransferLogsEvent = "transfer logs"
TransferStatusEvent = "transfer status"
)
// Returns the server's emitter instance.

View File

@@ -144,7 +144,8 @@ func (s *Server) acquireInstallationLock() error {
s.installer.sem = semaphore.NewWeighted(1)
}
ctx, _ := context.WithTimeout(context.Background(), time.Second*10)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()
return s.installer.sem.Acquire(ctx, 1)
}
@@ -168,6 +169,14 @@ func (s *Server) IsInstalling() bool {
return true
}
func (s *Server) IsTransferring() bool {
return s.transferring.Get()
}
func (s *Server) SetTransferring(state bool) {
s.transferring.Set(state)
}
// Removes the installer container for the server.
func (ip *InstallationProcess) RemoveContainer() {
err := ip.client.ContainerRemove(ip.context, ip.Server.Id()+"_installer", types.ContainerRemoveOptions{

View File

@@ -61,6 +61,14 @@ func (s *Server) ExecutingPowerAction() bool {
// function rather than making direct calls to the start/stop/restart functions on the
// environment struct.
func (s *Server) HandlePowerAction(action PowerAction, waitSeconds ...int) error {
if s.IsInstalling() {
return ErrServerIsInstalling
}
if s.IsTransferring() {
return ErrServerIsTransferring
}
if s.powerLock == nil {
s.powerLock = semaphore.NewWeighted(1)
}

View File

@@ -12,6 +12,7 @@ import (
"github.com/pterodactyl/wings/environment/docker"
"github.com/pterodactyl/wings/events"
"github.com/pterodactyl/wings/server/filesystem"
"github.com/pterodactyl/wings/system"
"golang.org/x/sync/semaphore"
"strings"
"sync"
@@ -56,6 +57,8 @@ type Server struct {
// installer process is still running.
installer InstallerDetails
transferring system.AtomicBool
// The console throttler instance used to control outputs.
throttler *ConsoleThrottler