Allow sending a termination signal even if another power action is being processed
This commit is contained in:
parent
cf1c671e68
commit
5fcec86e98
|
@ -53,6 +53,12 @@ func (s *Server) HandlePowerAction(action PowerAction, waitSeconds ...int) error
|
||||||
s.powerLock = semaphore.NewWeighted(1)
|
s.powerLock = semaphore.NewWeighted(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only attempt to acquire a lock on the process if this is not a termination event. We want to
|
||||||
|
// just allow those events to pass right through for good reason. If a server is currently trying
|
||||||
|
// to process a power action but has gotten stuck you still should be able to pass through the
|
||||||
|
// terminate event. The good news here is that doing that oftentimes will get the stuck process to
|
||||||
|
// move again, and naturally continue through the process.
|
||||||
|
if action != PowerActionTerminate {
|
||||||
// Determines if we should wait for the lock or not. If a value greater than 0 is passed
|
// Determines if we should wait for the lock or not. If a value greater than 0 is passed
|
||||||
// into this function we will wait that long for a lock to be acquired.
|
// into this function we will wait that long for a lock to be acquired.
|
||||||
if len(waitSeconds) > 0 && waitSeconds[0] != 0 {
|
if len(waitSeconds) > 0 && waitSeconds[0] != 0 {
|
||||||
|
@ -73,7 +79,18 @@ func (s *Server) HandlePowerAction(action PowerAction, waitSeconds ...int) error
|
||||||
|
|
||||||
// Release the lock once the process being requested has finished executing.
|
// Release the lock once the process being requested has finished executing.
|
||||||
defer s.powerLock.Release(1)
|
defer s.powerLock.Release(1)
|
||||||
|
} else {
|
||||||
|
// Still try to acquire the lock if terminating and it is available, just so that other power
|
||||||
|
// actions are blocked until it has completed. However, if it is unavailable we won't stop
|
||||||
|
// the entire process.
|
||||||
|
if ok := s.powerLock.TryAcquire(1); ok {
|
||||||
|
// If we managed to acquire the lock be sure to released it once this process is completed.
|
||||||
|
defer s.powerLock.Release(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure the server data is properly synced before attempting to start the process, and that there
|
||||||
|
// is enough disk space available.
|
||||||
if action.IsStart() {
|
if action.IsStart() {
|
||||||
s.Log().Info("syncing server configuration with panel")
|
s.Log().Info("syncing server configuration with panel")
|
||||||
if err := s.Sync(); err != nil {
|
if err := s.Sync(); err != nil {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user