modify package from iSulad-lxcfs-toolkit to lxcfs-tools

Signed-off-by: zhangsong34 <zhangsong34@huawei.com>
This commit is contained in:
zhangsong34 2020-01-21 17:14:32 +08:00 committed by Grooooot
parent 864470a0f9
commit 57c27bce2e
15 changed files with 81 additions and 78 deletions

View File

@ -1,5 +1,5 @@
# Copyright (c) Huawei Technologies Co., Ltd. 2019. All rights reserved.
# iSulad-lxcfs-toolkit is licensed under the Mulan PSL v1.
# lxcfs-tools is licensed under the Mulan PSL v1.
# You can use this software according to the terms and conditions of the Mulan PSL v1.
# You may obtain a copy of Mulan PSL v1 at:
# http://license.coscl.org.cn/MulanPSL
@ -29,8 +29,8 @@ all: toolkit lxcfs-hook
local: toolkit lxcfs-hook
toolkit: $(SOURCES) | $(DEPS_LINK)
@echo "Making isulad-lxcfs-tools..."
${ENV} go build -mod=vendor -tags ${TAGS} -ldflags ${GO_LDFLAGS} -o build/isulad-lxcfs-toolkit .
@echo "Making lxcfs-tools..."
${ENV} go build -mod=vendor -tags ${TAGS} -ldflags ${GO_LDFLAGS} -o build/lxcfs-tools .
@echo "Done!"
lxcfs-hook: $(SOURCES) | $(DEPS_LINK)

2
go.mod
View File

@ -1,4 +1,4 @@
module isulad-lxcfs-toolkit
module lxcfs-tools
replace (
github.com/docker/docker => github.com/docker/engine v0.0.0-20181106193140-f5749085e9cb

View File

@ -1,5 +1,5 @@
# Copyright (c) Huawei Technologies Co., Ltd. 2019. All rights reserved.
# iSulad-lxcfs-toolkit is licensed under the Mulan PSL v1.
# lxcfs-tools is licensed under the Mulan PSL v1.
# You can use this software according to the terms and conditions of the Mulan PSL v1.
# You may obtain a copy of Mulan PSL v1 at:
# http://license.coscl.org.cn/MulanPSL
@ -14,10 +14,10 @@
#!/bin/bash
ISULAD_LXCFS_TOOLKIT_DIR=/usr/local/bin
LXCFS_TOOLS_DIR=/usr/local/bin
echo "isulad_lxcfs_toolkit will be installed to $ISULAD_LXCFS_TOOLKIT_DIR"
echo "lxcfs-tools will be installed to $LXCFS_TOOLS_DIR"
install -m 0755 -p ../build/isulad_lxcfs_toolkit ${ISULAD_LXCFS_TOOLKIT_DIR}
install -m 0755 -p ../build/lxcfs-tools ${LXCFS_TOOLS_DIR}
echo "isulad_lxcfs_toolkit install done"
echo "lxcfs-tools install done"

View File

@ -2,12 +2,12 @@
%define debug_package %{nil}
#Basic Information
Name: isulad-lxcfs-toolkit
Name: lxcfs-tools
Version: 0.3
Release: 15
Release: 16
Summary: toolkit for lxcfs to remount a running isulad
License: Mulan PSL v1
URL: https://gitee.com/src-openeuler/iSulad-lxcfs-toolkit
URL: https://gitee.com/src-openeuler/lxcfs-tools
Source0: %{name}.tar.gz
BuildRoot: %{_tmppath}/%{name}-root
@ -26,23 +26,23 @@ export RPM_BUILD_SOURCE=%_topdir/SOURCES
cd $RPM_BUILD_DIR
mkdir -p $RPM_BUILD_DIR/src/isula.org/isulad-lxcfs-toolkit && cd $RPM_BUILD_DIR/src/isula.org/isulad-lxcfs-toolkit
mkdir -p $RPM_BUILD_DIR/src/isula.org/lxcfs-tools && cd $RPM_BUILD_DIR/src/isula.org/lxcfs-tools
gzip -dc $RPM_BUILD_SOURCE/%{name}.tar.gz | tar -xvvf -
%build
cd $RPM_BUILD_DIR/src/isula.org/isulad-lxcfs-toolkit
cd $RPM_BUILD_DIR/src/isula.org/lxcfs-tools
make
%install
HOOK_DIR=$RPM_BUILD_ROOT/var/lib/isulad/hooks
ISULAD_LXCFS_TOOLKIT_DIR=$RPM_BUILD_ROOT/usr/local/bin
LXCFS_TOOLS_DIR=$RPM_BUILD_ROOT/usr/local/bin
cd $RPM_BUILD_DIR/src/isula.org/isulad-lxcfs-toolkit
cd $RPM_BUILD_DIR/src/isula.org/lxcfs-tools
mkdir -p -m 0700 ${HOOK_DIR}
mkdir -p -m 0700 ${ISULAD_LXCFS_TOOLKIT_DIR}
mkdir -p -m 0700 ${LXCFS_TOOLS_DIR}
install -m 0750 build/lxcfs-hook ${HOOK_DIR}
install -m 0750 build/isulad-lxcfs-toolkit ${ISULAD_LXCFS_TOOLKIT_DIR}
install -m 0750 build/lxcfs-tools ${LXCFS_TOOLS_DIR}
#Install and uninstall scripts
%pre
@ -89,7 +89,7 @@ chmod 0640 ${HOOK_SPEC}/hookspec.json
#Files list
%files
%defattr(0550,root,root,0550)
/usr/local/bin/isulad-lxcfs-toolkit
/usr/local/bin/lxcfs-tools
%attr(0550,root,root) /var/lib/isulad/hooks
%attr(0550,root,root) /var/lib/isulad/hooks/lxcfs-hook
@ -99,5 +99,8 @@ rm -rfv %{buildroot}
%changelog
* Tue Jan 7 2020 Zhangsong <zhangsong34@huawei.com> - 0.3.16
- update package
* Thu Feb 1 2018 Tanzhe <tanzhe@huawei.com>
- add require version

View File

@ -1,11 +1,11 @@
{
"prestart": [
{
"path": "/var/lib/isulad/hooks/lxcfs-hook",
"args": ["lxcfs-hook", "--log", "/var/log/lxcfs-hook.log"],
"env": []
}
],
"poststart":[],
"poststop":[]
}
{
"prestart": [
{
"path": "/var/lib/isulad/hooks/lxcfs-hook",
"args": ["lxcfs-hook", "--log", "/var/log/lxcfs-hook.log"],
"env": []
}
],
"poststart":[],
"poststop":[]
}

View File

@ -1,5 +1,5 @@
// Copyright (c) Huawei Technologies Co., Ltd. 2019. All rights reserved.
// iSulad-lxcfs-toolkit is licensed under the Mulan PSL v1.
// lxcfs-tools is licensed under the Mulan PSL v1.
// You can use this software according to the terms and conditions of the Mulan PSL v1.
// You may obtain a copy of Mulan PSL v1 at:
// http://license.coscl.org.cn/MulanPSL
@ -17,17 +17,17 @@ package main
import (
"fmt"
"io/ioutil"
"isulad-lxcfs-toolkit/libmount"
"lxcfs-tools/libmount"
"os"
"strconv"
isulad_lxcfs_log "github.com/sirupsen/logrus"
lxcfs_log "github.com/sirupsen/logrus"
)
func prestartMountHook(pid int, rootfs string) error {
lxcfssubpath, err := ioutil.ReadDir("/var/lib/lxc/lxcfs/proc")
if err != nil {
isulad_lxcfs_log.Errorf("Prase lxcfs dir failed: %v", err)
lxcfs_log.Errorf("Prase lxcfs dir failed: %v", err)
return err
}
@ -51,7 +51,7 @@ func prestartMountHook(pid int, rootfs string) error {
}
if err := libmount.NsExecMount(strconv.Itoa(pid), rootfs, valueMountPaths, valuePaths); err != nil {
isulad_lxcfs_log.Errorf("mount %v into container error: %v", valueMountPaths, err)
lxcfs_log.Errorf("mount %v into container error: %v", valueMountPaths, err)
return err
}
return nil

View File

@ -1,5 +1,5 @@
// Copyright (c) Huawei Technologies Co., Ltd. 2019. All rights reserved.
// iSulad-lxcfs-toolkit is licensed under the Mulan PSL v1.
// lxcfs-tools is licensed under the Mulan PSL v1.
// You can use this software according to the terms and conditions of the Mulan PSL v1.
// You may obtain a copy of Mulan PSL v1 at:
// http://license.coscl.org.cn/MulanPSL
@ -17,7 +17,7 @@ package main
import (
"flag"
"fmt"
"isulad-lxcfs-toolkit/hooks/lxcfs-hook/utils"
"lxcfs-tools/hooks/lxcfs-hook/utils"
"os"
"github.com/docker/docker/pkg/reexec"

View File

@ -1,5 +1,5 @@
// Copyright (c) Huawei Technologies Co., Ltd. 2019. All rights reserved.
// iSulad-lxcfs-toolkit is licensed under the Mulan PSL v1.
// lxcfs-tools is licensed under the Mulan PSL v1.
// You can use this software according to the terms and conditions of the Mulan PSL v1.
// You may obtain a copy of Mulan PSL v1 at:
// http://license.coscl.org.cn/MulanPSL

View File

@ -1,5 +1,5 @@
// Copyright (c) Huawei Technologies Co., Ltd. 2019. All rights reserved.
// iSulad-lxcfs-toolkit is licensed under the Mulan PSL v1.
// lxcfs-tools is licensed under the Mulan PSL v1.
// You can use this software according to the terms and conditions of the Mulan PSL v1.
// You may obtain a copy of Mulan PSL v1 at:
// http://license.coscl.org.cn/MulanPSL
@ -16,7 +16,7 @@ package libmount
import (
"encoding/json"
"fmt"
"isulad-lxcfs-toolkit/libmount/nsexec"
"lxcfs-tools/libmount/nsexec"
"os"
"strconv"
"strings"

View File

@ -1,5 +1,5 @@
// Copyright (c) Huawei Technologies Co., Ltd. 2019. All rights reserved.
// iSulad-lxcfs-toolkit is licensed under the Mulan PSL v1.
// lxcfs-tools is licensed under the Mulan PSL v1.
// You can use this software according to the terms and conditions of the Mulan PSL v1.
// You may obtain a copy of Mulan PSL v1 at:
// http://license.coscl.org.cn/MulanPSL
@ -14,7 +14,7 @@
package libmount
import (
"isulad-lxcfs-toolkit/libmount/nsexec"
"lxcfs-tools/libmount/nsexec"
)
// NsExecMount exec mount in container namespace

View File

@ -1,5 +1,5 @@
// Copyright (c) Huawei Technologies Co., Ltd. 2019. All rights reserved.
// iSulad-lxcfs-toolkit is licensed under the Mulan PSL v1.
// lxcfs-tools is licensed under the Mulan PSL v1.
// You can use this software according to the terms and conditions of the Mulan PSL v1.
// You may obtain a copy of Mulan PSL v1 at:
// http://license.coscl.org.cn/MulanPSL

View File

@ -1,5 +1,5 @@
// Copyright (c) Huawei Technologies Co., Ltd. 2019. All rights reserved.
// iSulad-lxcfs-toolkit is licensed under the Mulan PSL v1.
// lxcfs-tools is licensed under the Mulan PSL v1.
// You can use this software according to the terms and conditions of the Mulan PSL v1.
// You may obtain a copy of Mulan PSL v1 at:
// http://license.coscl.org.cn/MulanPSL

10
main.go
View File

@ -1,5 +1,5 @@
// Copyright (c) Huawei Technologies Co., Ltd. 2019. All rights reserved.
// iSulad-lxcfs-toolkit is licensed under the Mulan PSL v1.
// lxcfs-tools is licensed under the Mulan PSL v1.
// You can use this software according to the terms and conditions of the Mulan PSL v1.
// You may obtain a copy of Mulan PSL v1 at:
// http://license.coscl.org.cn/MulanPSL
@ -21,19 +21,19 @@ import (
"github.com/docker/docker/pkg/reexec"
_ "github.com/opencontainers/runc/libcontainer/nsenter"
isulad_lxcfs_log "github.com/sirupsen/logrus"
lxcfs_log "github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
const (
usage = `Toolkit for reconnet to a running isulad using lxcfs`
syslogTag = "isulad-lxcfs-tools"
syslogTag = "lxcfs-tools"
)
var version = "0.1"
func onfail(err error) {
isulad_lxcfs_log.Error(err)
lxcfs_log.Error(err)
fmt.Fprint(os.Stderr, err)
os.Exit(1)
}
@ -44,7 +44,7 @@ func onfailf(t string, v ...interface{}) {
func runToolkit() {
app := cli.NewApp()
app.Name = "isulad-lxcfs-toolkit"
app.Name = "lxcfs-tools"
app.Usage = usage
v := []string{

View File

@ -1,5 +1,5 @@
// Copyright (c) Huawei Technologies Co., Ltd. 2019. All rights reserved.
// iSulad-lxcfs-toolkit is licensed under the Mulan PSL v1.
// lxcfs-tools is licensed under the Mulan PSL v1.
// You can use this software according to the terms and conditions of the Mulan PSL v1.
// You may obtain a copy of Mulan PSL v1 at:
// http://license.coscl.org.cn/MulanPSL
@ -19,7 +19,7 @@ import (
"fmt"
"io"
"io/ioutil"
"isulad-lxcfs-toolkit/libmount"
"lxcfs-tools/libmount"
"os"
"os/exec"
"strings"
@ -27,7 +27,7 @@ import (
"syscall"
"time"
isulad_lxcfs_log "github.com/sirupsen/logrus"
lxcfs_log "github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
@ -66,7 +66,7 @@ var recmountContainer = cli.Command{
onfail(fmt.Errorf("read init user namespace fail: %v", err))
}
if context.Bool("all") {
isulad_lxcfs_log.Info("remount to all containers")
lxcfs_log.Info("remount to all containers")
if err := remountAll(initMountns, initUserns); err != nil {
onfail(err)
}
@ -101,7 +101,7 @@ var checklxcfs = cli.Command{
if err := waitForLxcfs(); err != nil {
onfail(err)
} else {
isulad_lxcfs_log.Info("lxcfs is running")
lxcfs_log.Info("lxcfs is running")
}
},
}
@ -119,20 +119,20 @@ var execprestart = cli.Command{
if err := doprestart(); err != nil {
onfail(err)
} else {
isulad_lxcfs_log.Info("prestart done")
lxcfs_log.Info("prestart done")
}
},
}
func doprestart() error {
isulad_lxcfs_log.Info("do prestart")
lxcfs_log.Info("do prestart")
if err := syscall.Unmount("/var/lib/lxc/lxcfs", syscall.MNT_DETACH); err == nil {
isulad_lxcfs_log.Warning("releaseMountpoint: umount /var/lib/lxc/lxcfs")
lxcfs_log.Warning("releaseMountpoint: umount /var/lib/lxc/lxcfs")
}
if err := syscall.Unmount("/var/lib/lxc", syscall.MNT_DETACH); err == nil {
isulad_lxcfs_log.Warning("releaseMountpoint: umount /var/lib/lxc")
lxcfs_log.Warning("releaseMountpoint: umount /var/lib/lxc")
}
prestartparm1 := []string{
@ -170,7 +170,7 @@ func waitForLxcfs() error {
if count == maxCount {
err := fmt.Errorf("lxcfs is not ready")
isulad_lxcfs_log.Errorf("%v", err)
lxcfs_log.Errorf("%v", err)
return err
}
@ -178,7 +178,7 @@ func waitForLxcfs() error {
}
func remountAll(initMountns, initUserns string) error {
isulad_lxcfs_log.Info("begin remount All runing container...")
lxcfs_log.Info("begin remount All runing container...")
out, err := execCommond("isula", []string{"ps", "--format", "{{.ID}} {{.Pid}}"})
if err != nil {
return err
@ -196,19 +196,19 @@ func remountAll(initMountns, initUserns string) error {
res := make(chan struct{}, 1)
go func() {
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)
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[0])
lxcfs_log.Errorf("remount lxcfs dir to container(%s) timeout", containerslice[0])
}
}()
}
wg.Wait()
isulad_lxcfs_log.Info(" remount All done...")
lxcfs_log.Info(" remount All done...")
return nil
}
@ -221,7 +221,7 @@ func remountToContainer(initMountns, initUserns, containerid string, pid string,
}
}
isulad_lxcfs_log.Infof("begin remount container,container id: %s, pid: %s", containerid, pid)
lxcfs_log.Infof("begin remount container,container id: %s, pid: %s", containerid, pid)
lxcfssubpath, err := ioutil.ReadDir("/var/lib/lxc/lxcfs/proc")
if err != nil {
@ -244,18 +244,18 @@ func remountToContainer(initMountns, initUserns, containerid string, pid string,
}
if err := libmount.NsExecUmount(pid, valuePaths); err != nil {
isulad_lxcfs_log.Errorf("unmount %v for container error: %v", valuePaths, err)
lxcfs_log.Errorf("unmount %v for container error: %v", valuePaths, err)
}
if err := libmount.NsExecMount(pid, "", valueMountPaths, valuePaths); err != nil {
isulad_lxcfs_log.Errorf("mount %v into container %s error: %v", valueMountPaths, containerid, err)
lxcfs_log.Errorf("mount %v into container %s error: %v", valueMountPaths, containerid, err)
return err
}
return nil
}
func isContainerExsit(containerid string) (string, error) {
isulad_lxcfs_log.Info("begin isContainerExsit...")
lxcfs_log.Info("begin isContainerExsit...")
if containerid == "" {
return "", fmt.Errorf("Containerid mustn't be empty")
}
@ -283,7 +283,7 @@ func execCommond(command string, params []string) ([]string, error) {
res := []string{
" ",
}
isulad_lxcfs_log.Info("exec cmd :", cmd.Args)
lxcfs_log.Info("exec cmd :", cmd.Args)
stdout, err := cmd.StdoutPipe()

View File

@ -1,5 +1,5 @@
// Copyright (c) Huawei Technologies Co., Ltd. 2019. All rights reserved.
// iSulad-lxcfs-toolkit is licensed under the Mulan PSL v1.
// lxcfs-tools is licensed under the Mulan PSL v1.
// You can use this software according to the terms and conditions of the Mulan PSL v1.
// You may obtain a copy of Mulan PSL v1 at:
// http://license.coscl.org.cn/MulanPSL
@ -17,13 +17,13 @@ package main
import (
"fmt"
"io/ioutil"
"isulad-lxcfs-toolkit/libmount"
"lxcfs-tools/libmount"
"os"
"strings"
"sync"
"time"
isulad_lxcfs_log "github.com/sirupsen/logrus"
lxcfs_log "github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
@ -62,7 +62,7 @@ var umountContainer = cli.Command{
onfail(fmt.Errorf("read init user namespace fail: %v", err))
}
if context.Bool("all") {
isulad_lxcfs_log.Info("umount for all containers")
lxcfs_log.Info("umount for all containers")
if err := umountAll(initMountns, initUserns); err != nil {
onfail(err)
}
@ -84,7 +84,7 @@ var umountContainer = cli.Command{
}
func umountAll(initMountns, initUserns string) error {
isulad_lxcfs_log.Info("begin umount All runing container...")
lxcfs_log.Info("begin umount All runing container...")
out, err := execCommond("isula", []string{"ps", "--format", "{{.ID}} {{.Pid}}"})
if err != nil {
return err
@ -102,20 +102,20 @@ func umountAll(initMountns, initUserns string) error {
res := make(chan struct{}, 1)
go func() {
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)
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[0])
lxcfs_log.Errorf("umount lxcfs dir from container(%s) timeout", containerslice[0])
}
}()
}
wg.Wait()
isulad_lxcfs_log.Info(" umount All done...")
lxcfs_log.Info(" umount All done...")
return nil
}
@ -128,7 +128,7 @@ func umountForContainer(initMountns, initUserns, containerid string, pid string,
}
}
isulad_lxcfs_log.Infof("begin umount container,container id: %s, pid: %s", containerid, pid)
lxcfs_log.Infof("begin umount container,container id: %s, pid: %s", containerid, pid)
lxcfssubpath, err := ioutil.ReadDir("/var/lib/lxc/lxcfs/proc")
if err != nil {
@ -149,7 +149,7 @@ func umountForContainer(initMountns, initUserns, containerid string, pid string,
}
if err := libmount.NsExecUmount(pid, valuePaths); err != nil {
isulad_lxcfs_log.Errorf("unmount %v for container %s error: %v", valuePaths, containerid, err)
lxcfs_log.Errorf("unmount %v for container %s error: %v", valuePaths, containerid, err)
return err
}
return nil