internally mark if a server is restoring to restrict actions
This commit is contained in:
@@ -9,6 +9,7 @@ var (
|
||||
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")
|
||||
ErrServerIsRestoring = errors.New("server is currently being restored")
|
||||
)
|
||||
|
||||
type crashTooFrequent struct {
|
||||
|
||||
@@ -151,6 +151,14 @@ func (s *Server) SetTransferring(state bool) {
|
||||
s.transferring.Store(state)
|
||||
}
|
||||
|
||||
func (s *Server) IsRestoring() bool {
|
||||
return s.restoring.Load()
|
||||
}
|
||||
|
||||
func (s *Server) SetRestoring(state bool) {
|
||||
s.restoring.Store(state)
|
||||
}
|
||||
|
||||
// Removes the installer container for the server.
|
||||
func (ip *InstallationProcess) RemoveContainer() error {
|
||||
err := ip.client.ContainerRemove(ip.context, ip.Server.Id()+"_installer", types.ContainerRemoveOptions{
|
||||
|
||||
@@ -70,6 +70,10 @@ func (s *Server) HandlePowerAction(action PowerAction, waitSeconds ...int) error
|
||||
return ErrServerIsTransferring
|
||||
}
|
||||
|
||||
if s.IsRestoring() {
|
||||
return ErrServerIsRestoring
|
||||
}
|
||||
|
||||
if s.powerLock == nil {
|
||||
s.powerLock = semaphore.NewWeighted(1)
|
||||
}
|
||||
|
||||
@@ -60,6 +60,7 @@ type Server struct {
|
||||
// installer process is still running.
|
||||
installing *system.AtomicBool
|
||||
transferring *system.AtomicBool
|
||||
restoring *system.AtomicBool
|
||||
|
||||
// The console throttler instance used to control outputs.
|
||||
throttler *ConsoleThrottler
|
||||
@@ -79,6 +80,7 @@ func New(client remote.Client) (*Server, error) {
|
||||
client: client,
|
||||
installing: system.NewAtomicBool(false),
|
||||
transferring: system.NewAtomicBool(false),
|
||||
restoring: system.NewAtomicBool(false),
|
||||
}
|
||||
if err := defaults.Set(&s); err != nil {
|
||||
return nil, errors.Wrap(err, "server: could not set default values for struct")
|
||||
|
||||
Reference in New Issue
Block a user