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