mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 10:46:58 +08:00
Merge pull request #10850 from yousong/automated-cherry-pick-of-#10849-upstream-release-3.7
Automated cherry pick of #10849: Feature/yousong zombie
This commit is contained in:
@@ -15,9 +15,14 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/ansibleserver/service"
|
||||
"yunion.io/x/onecloud/pkg/util/procutils"
|
||||
)
|
||||
|
||||
func main() {
|
||||
go procutils.WaitZombieLoop(context.TODO())
|
||||
|
||||
service.StartService()
|
||||
}
|
||||
|
||||
@@ -15,12 +15,17 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/baremetal/service"
|
||||
"yunion.io/x/onecloud/pkg/util/atexit"
|
||||
"yunion.io/x/onecloud/pkg/util/procutils"
|
||||
)
|
||||
|
||||
func main() {
|
||||
defer atexit.Handle()
|
||||
|
||||
go procutils.WaitZombieLoop(context.TODO())
|
||||
|
||||
service.New().StartService()
|
||||
}
|
||||
|
||||
@@ -15,12 +15,17 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/esxi/service"
|
||||
"yunion.io/x/onecloud/pkg/util/atexit"
|
||||
"yunion.io/x/onecloud/pkg/util/procutils"
|
||||
)
|
||||
|
||||
func main() {
|
||||
defer atexit.Handle()
|
||||
|
||||
go procutils.WaitZombieLoop(context.TODO())
|
||||
|
||||
service.New().StartService()
|
||||
}
|
||||
|
||||
@@ -15,12 +15,17 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/image/service"
|
||||
"yunion.io/x/onecloud/pkg/util/atexit"
|
||||
"yunion.io/x/onecloud/pkg/util/procutils"
|
||||
)
|
||||
|
||||
func main() {
|
||||
defer atexit.Handle()
|
||||
|
||||
go procutils.WaitZombieLoop(context.TODO())
|
||||
|
||||
service.StartService()
|
||||
}
|
||||
|
||||
@@ -14,9 +14,16 @@
|
||||
|
||||
package main
|
||||
|
||||
import "yunion.io/x/onecloud/pkg/hostman/hostdeployer/deployserver"
|
||||
import (
|
||||
"context"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/hostman/hostdeployer/deployserver"
|
||||
"yunion.io/x/onecloud/pkg/util/procutils"
|
||||
)
|
||||
|
||||
func main() {
|
||||
go procutils.WaitZombieLoop(context.TODO())
|
||||
|
||||
deployer := deployserver.NewDeployService()
|
||||
deployer.StartService()
|
||||
}
|
||||
|
||||
@@ -15,14 +15,19 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/service"
|
||||
"yunion.io/x/onecloud/pkg/hostman"
|
||||
"yunion.io/x/onecloud/pkg/util/atexit"
|
||||
"yunion.io/x/onecloud/pkg/util/procutils"
|
||||
)
|
||||
|
||||
func main() {
|
||||
defer atexit.Handle()
|
||||
|
||||
go procutils.WaitZombieLoop(context.TODO())
|
||||
|
||||
var srv = &hostman.SHostService{}
|
||||
srv.SServiceBase = &service.SServiceBase{
|
||||
Service: srv,
|
||||
|
||||
@@ -26,6 +26,7 @@ import (
|
||||
app_common "yunion.io/x/onecloud/pkg/cloudcommon/app"
|
||||
common_options "yunion.io/x/onecloud/pkg/cloudcommon/options"
|
||||
"yunion.io/x/onecloud/pkg/util/atexit"
|
||||
"yunion.io/x/onecloud/pkg/util/procutils"
|
||||
"yunion.io/x/onecloud/pkg/vpcagent/options"
|
||||
_ "yunion.io/x/onecloud/pkg/vpcagent/ovn"
|
||||
"yunion.io/x/onecloud/pkg/vpcagent/worker"
|
||||
@@ -52,8 +53,12 @@ func main() {
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
ctx := context.Background()
|
||||
ctx, cancelFunc := context.WithCancel(ctx)
|
||||
go procutils.WaitZombieLoop(ctx)
|
||||
|
||||
wg := &sync.WaitGroup{}
|
||||
ctx, cancelFunc := context.WithCancel(context.Background())
|
||||
ctx = context.WithValue(ctx, "wg", wg)
|
||||
wg.Add(1)
|
||||
go w.Start(ctx)
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
@@ -49,7 +48,5 @@ func StartService() {
|
||||
db.EnsureAppInitSyncDB(app, dbOpts, models.InitDB)
|
||||
defer cloudcommon.CloseDB()
|
||||
|
||||
go ReapZomebieLoop(context.TODO())
|
||||
|
||||
common_app.ServeForever(app, baseOpts)
|
||||
}
|
||||
|
||||
@@ -12,11 +12,10 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package service
|
||||
package procutils
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -28,13 +27,13 @@ import (
|
||||
"yunion.io/x/log"
|
||||
)
|
||||
|
||||
func ReapZomebieLoop(ctx context.Context) {
|
||||
func WaitZombieLoop(ctx context.Context) {
|
||||
myPid := os.Getpid()
|
||||
if myPid != 1 {
|
||||
log.Infof("My pid is not 1 and no need to wait zombies")
|
||||
return
|
||||
}
|
||||
myPidStr := fmt.Sprintf("%d", myPid)
|
||||
const myPidStr = "1"
|
||||
|
||||
tick := time.NewTicker(31 * time.Second)
|
||||
for {
|
||||
@@ -69,11 +68,11 @@ func ReapZomebieLoop(ctx context.Context) {
|
||||
dataStr := string(data)
|
||||
items := strings.Split(dataStr, " ")
|
||||
const (
|
||||
idxPid = iota
|
||||
idxName = iota
|
||||
idxState = iota
|
||||
idxPpid = iota
|
||||
idxMinLen = iota
|
||||
idxPid = iota
|
||||
idxName
|
||||
idxState
|
||||
idxPpid
|
||||
idxMinLen
|
||||
)
|
||||
if len(items) < idxMinLen {
|
||||
log.Errorf("%s contains less than %d items: %s", statPath, idxMinLen, dataStr)
|
||||
@@ -97,11 +96,7 @@ func ReapZomebieLoop(ctx context.Context) {
|
||||
log.Errorf("%s: %s has invalid pid number %q: %v", pname, statPath, pidStr, err)
|
||||
continue
|
||||
}
|
||||
var (
|
||||
status syscall.WaitStatus
|
||||
rusage syscall.Rusage
|
||||
)
|
||||
pid1, err := syscall.Wait4(pid, &status, 0, &rusage)
|
||||
pid1, err := syscall.Wait4(pid, nil, 0, nil)
|
||||
if err != nil {
|
||||
log.Errorf("%s: %s: wait error: %v", pname, statPath, err)
|
||||
continue
|
||||
Reference in New Issue
Block a user