Add a server context that gets canceled when a server is deleted

This commit is contained in:
Dane Everitt
2020-12-25 11:21:09 -08:00
parent f7f5623c71
commit c0523df696
9 changed files with 93 additions and 104 deletions

View File

@@ -127,14 +127,11 @@ func NewInstallationProcess(s *Server, script *api.InstallationScript) (*Install
Server: s,
}
ctx, cancel := context.WithCancel(context.Background())
s.installer.cancel = &cancel
if c, err := environment.DockerClient(); err != nil {
return nil, err
} else {
proc.client = c
proc.context = ctx
proc.context = s.Context()
}
return proc, nil
@@ -171,21 +168,6 @@ func (s *Server) IsInstalling() bool {
return true
}
// Aborts the server installation process by calling the cancel function on the installer
// context.
func (s *Server) AbortInstallation() {
if !s.IsInstalling() {
return
}
if s.installer.cancel != nil {
cancel := *s.installer.cancel
s.Log().Warn("aborting running installation process")
cancel()
}
}
// Removes the installer container for the server.
func (ip *InstallationProcess) RemoveContainer() {
err := ip.client.ContainerRemove(ip.context, ip.Server.Id()+"_installer", types.ContainerRemoveOptions{
@@ -215,7 +197,6 @@ func (ip *InstallationProcess) Run() error {
defer func() {
ip.Server.Log().Debug("releasing installation process lock")
ip.Server.installer.sem.Release(1)
ip.Server.installer.cancel = nil
}()
if err := ip.BeforeExecute(); err != nil {