Package init
This commit is contained in:
parent
e6adce48b9
commit
2e3e328707
@ -179,9 +179,7 @@ func waitForLxcfs() error {
|
||||
|
||||
func remountAll(initMountns, initUserns string) error {
|
||||
isulad_lxcfs_log.Info("begin remount All runing container...")
|
||||
atLeastLen := 10
|
||||
index := 9
|
||||
out, err := execCommond("lcrc", []string{"ps"})
|
||||
out, err := execCommond("lcrc", []string{"ps", "--format", "{{.ID}} {{.Pid}}"})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -189,28 +187,23 @@ func remountAll(initMountns, initUserns string) error {
|
||||
var wg sync.WaitGroup
|
||||
for _, value := range out {
|
||||
containerslice := strings.Fields(value)
|
||||
if len(containerslice) < atLeastLen {
|
||||
if len(containerslice) < 2 {
|
||||
continue
|
||||
}
|
||||
|
||||
if containerslice[index] == "ID" {
|
||||
continue
|
||||
}
|
||||
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
res := make(chan struct{}, 1)
|
||||
go func() {
|
||||
if err := remountToContainer(initMountns, initUserns, containerslice[index], containerslice[1], true); err != nil {
|
||||
isulad_lxcfs_log.Errorf("remount lxcfs dir to container(%s) failed: %v", containerslice[index], err)
|
||||
if err := remountToContainer(initMountns, initUserns, containerslice[0], containerslice[1], true); err != nil {
|
||||
isulad_lxcfs_log.Errorf("remount lxcfs dir to container(%s) failed: %v", containerslice[0], err)
|
||||
}
|
||||
res <- struct{}{}
|
||||
}()
|
||||
select {
|
||||
case <-res:
|
||||
case <-time.After(30 * time.Second): // 30s timeout
|
||||
isulad_lxcfs_log.Errorf("remount lxcfs dir to container(%s) timeout", containerslice[index])
|
||||
isulad_lxcfs_log.Errorf("remount lxcfs dir to container(%s) timeout", containerslice[0])
|
||||
}
|
||||
}()
|
||||
}
|
||||
@ -264,32 +257,20 @@ func remountToContainer(initMountns, initUserns, containerid string, pid string,
|
||||
func isContainerExsit(containerid string) (string, error) {
|
||||
isulad_lxcfs_log.Info("begin isContainerExsit...")
|
||||
if containerid == "" {
|
||||
|
||||
return "", fmt.Errorf("Containerid mustn't be empty")
|
||||
}
|
||||
|
||||
index := -2
|
||||
out, err := execCommond("lcrc", []string{"ps"})
|
||||
out, err := execCommond("lcrc", []string{"ps", "--format", "{{.ID}} {{.Pid}}"})
|
||||
if err != nil {
|
||||
onfail(err)
|
||||
}
|
||||
|
||||
for _, value := range out {
|
||||
containerslice := strings.Fields(value)
|
||||
sz := len(containerslice)
|
||||
idx := index
|
||||
if idx < 0 {
|
||||
idx = sz + index
|
||||
}
|
||||
|
||||
if sz == 0 || idx < 0 {
|
||||
if len(containerslice) < 2 {
|
||||
continue
|
||||
}
|
||||
|
||||
if containerslice[idx] == "ID" {
|
||||
continue
|
||||
}
|
||||
if strings.Contains(containerslice[idx], containerid) {
|
||||
if strings.Contains(containerslice[0], containerid) {
|
||||
return containerslice[1], nil
|
||||
}
|
||||
}
|
||||
|
||||
17
umountcmd.go
17
umountcmd.go
@ -85,9 +85,7 @@ var umountContainer = cli.Command{
|
||||
|
||||
func umountAll(initMountns, initUserns string) error {
|
||||
isulad_lxcfs_log.Info("begin umount All runing container...")
|
||||
atLeastLen := 10
|
||||
index := 9
|
||||
out, err := execCommond("lcrc", []string{"ps"})
|
||||
out, err := execCommond("lcrc", []string{"ps", "--format", "{{.ID}} {{.Pid}}"})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -95,28 +93,23 @@ func umountAll(initMountns, initUserns string) error {
|
||||
var wg sync.WaitGroup
|
||||
for _, value := range out {
|
||||
containerslice := strings.Fields(value)
|
||||
if len(containerslice) < atLeastLen {
|
||||
if len(containerslice) < 2 {
|
||||
continue
|
||||
}
|
||||
|
||||
if containerslice[index] == "ID" {
|
||||
continue
|
||||
}
|
||||
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
res := make(chan struct{}, 1)
|
||||
go func() {
|
||||
if err := umountForContainer(initMountns, initUserns, containerslice[index], containerslice[1], true); err != nil {
|
||||
isulad_lxcfs_log.Errorf("umount lxcfs dir from container(%s) failed: %v", containerslice[index], err)
|
||||
if err := umountForContainer(initMountns, initUserns, containerslice[0], containerslice[1], true); err != nil {
|
||||
isulad_lxcfs_log.Errorf("umount lxcfs dir from container(%s) failed: %v", containerslice[0], err)
|
||||
}
|
||||
res <- struct{}{}
|
||||
}()
|
||||
select {
|
||||
case <-res:
|
||||
case <-time.After(30 * time.Second): // 30s timeout
|
||||
isulad_lxcfs_log.Errorf("umount lxcfs dir from container(%s) timeout", containerslice[index])
|
||||
isulad_lxcfs_log.Errorf("umount lxcfs dir from container(%s) timeout", containerslice[0])
|
||||
}
|
||||
}()
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user