Add a server context that gets canceled when a server is deleted
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user