@@ -521,8 +521,8 @@ func (m *Master) Shutdown(ctx context.Context) error {
521521 var wg sync.WaitGroup
522522 m .instances .Range (func (key , value any ) bool {
523523 instance := value .(* Instance )
524- // 如果实例正在运行 ,则停止它
525- if instance .Status == "running " && instance .cmd != nil && instance .cmd .Process != nil {
524+ // 如果实例需要停止 ,则停止它
525+ if instance .Status != "stopped " && instance .cmd != nil && instance .cmd .Process != nil {
526526 wg .Add (1 )
527527 go func (inst * Instance ) {
528528 defer wg .Done ()
@@ -1142,8 +1142,8 @@ func (m *Master) handlePutInstance(w http.ResponseWriter, r *http.Request, id st
11421142 return
11431143 }
11441144
1145- // 如果实例正在运行 ,先停止它
1146- if instance .Status == "running " {
1145+ // 如果实例需要停止 ,先停止它
1146+ if instance .Status != "stopped " {
11471147 m .stopInstance (instance )
11481148 time .Sleep (baseDuration )
11491149 }
@@ -1186,19 +1186,15 @@ func (m *Master) processInstanceAction(instance *Instance, action string) {
11861186 go m .startInstance (instance )
11871187 }
11881188 case "stop" :
1189- if instance .Status == "running " {
1189+ if instance .Status != "stopped " {
11901190 go m .stopInstance (instance )
11911191 }
11921192 case "restart" :
1193- if instance .Status == "running" {
1194- go func () {
1195- m .stopInstance (instance )
1196- time .Sleep (baseDuration )
1197- m .startInstance (instance )
1198- }()
1199- } else {
1200- go m .startInstance (instance )
1201- }
1193+ go func () {
1194+ m .stopInstance (instance )
1195+ time .Sleep (baseDuration )
1196+ m .startInstance (instance )
1197+ }()
12021198 }
12031199}
12041200
@@ -1214,7 +1210,7 @@ func (m *Master) handleDeleteInstance(w http.ResponseWriter, id string, instance
12141210 instance .deleted = true
12151211 m .instances .Store (id , instance )
12161212
1217- if instance .Status == "running " {
1213+ if instance .Status != "stopped " {
12181214 m .stopInstance (instance )
12191215 }
12201216 m .instances .Delete (id )
@@ -1725,7 +1721,7 @@ func (m *Master) startPeriodicCleanup() {
17251721 continue
17261722 }
17271723 inst .deleted = true
1728- if inst .Status == "running " {
1724+ if inst .Status != "stopped " {
17291725 m .stopInstance (inst )
17301726 }
17311727 m .instances .Delete (inst .ID )
0 commit comments