Skip to content
This repository has been archived by the owner on May 27, 2023. It is now read-only.

Commit

Permalink
add support for reset using old-glibc
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonYangShadow committed Nov 23, 2021
1 parent ebdc722 commit 1a91e2f
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 10 deletions.
Binary file modified build/linux/x86_64/Linux-x86_64-lpmx
Binary file not shown.
89 changes: 82 additions & 7 deletions container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (server *RPC) RPCDelete(req Request, res *Response) error {
return nil
}

func Init(reset bool, deppath string) *Error {
func Init(reset bool, deppath string, useOldGlibc bool) *Error {
currdir, err := GetConfigDir()
if err != nil {
return err
Expand All @@ -157,7 +157,7 @@ func Init(reset bool, deppath string) *Error {
config := fmt.Sprintf("%s/.lpmxsys", currdir)

//delete everything
if reset {
if reset || useOldGlibc {
_, cerr := RemoveAll(config)
if cerr != nil {
return cerr
Expand Down Expand Up @@ -212,10 +212,19 @@ func Init(reset bool, deppath string) *Error {
deppath = fmt.Sprintf("%s/dependency.tar.gz", sys.RootDir)
}
if !FileExist(deppath) {
yaml := fmt.Sprintf("%s/distro.management.yml", sys.RootDir)
err = DownloadFilefromGithubPlus(dist, release, "dependency.tar.gz", SETTING_URL, sys.RootDir, yaml)
if err != nil {
return err
if useOldGlibc {
gen_url := fmt.Sprintf("%s/default.dependency.tar.gz", SETTING_URL)
fmt.Printf("Downloading default.dependency.tar.gz from %s\n", gen_url)
err = DirectDownloadFilefromGithub("dependency.tar.gz", gen_url, sys.RootDir)
if err != nil {
return err
}
} else {
yaml := fmt.Sprintf("%s/distro.management.yml", sys.RootDir)
err = DownloadFilefromGithubPlus(dist, release, "dependency.tar.gz", SETTING_URL, sys.RootDir, yaml)
if err != nil {
return err
}
}
}

Expand Down Expand Up @@ -274,6 +283,72 @@ func Init(reset bool, deppath string) *Error {
return nil
}

func Reset(useOldGlibc bool) *Error {
currdir, err := GetConfigDir()
if err != nil {
return err
}
config := fmt.Sprintf("%s/.lpmxsys", currdir)

if ok, pid, _ := GetProcessIdByName("memcached"); ok {
fmt.Println("stopping memcached instance...")
err := KillProcessByPid(pid)
if err != nil {
return err
}
}

var sys Sys
sys.RootDir = config
err = unmarshalObj(sys.RootDir, &sys)
if err != nil {
return err
}

//download memcached related files based on host os info
dist, release, cerr := GetHostOSInfo()
if cerr != nil {
dist = "default"
release = "default"
}

if dist == "" {
dist = "default"
}

if release == "" {
release = "default"
}

deppath := fmt.Sprintf("%s/dependency.tar.gz", sys.RootDir)
if FileExist(deppath) {
RemoveFile(deppath)
}

if useOldGlibc {
gen_url := fmt.Sprintf("%s/default.dependency.tar.gz", SETTING_URL)
fmt.Printf("Downloading default.dependency.tar.gz from %s\n", gen_url)
err = DirectDownloadFilefromGithub("dependency.tar.gz", gen_url, sys.RootDir)
if err != nil {
return err
}
} else {
yaml := fmt.Sprintf("%s/distro.management.yml", sys.RootDir)
err = DownloadFilefromGithubPlus(dist, release, "dependency.tar.gz", SETTING_URL, sys.RootDir, yaml)
if err != nil {
return err
}
}

fmt.Println("Uncompressing downloaded dependency.tar.gz")
err = Untar(deppath, sys.RootDir)
if err != nil {
return err
}

return nil
}

func Uninstall() *Error {
currdir, err := GetConfigDir()
if err != nil {
Expand Down Expand Up @@ -1769,7 +1844,7 @@ func SkopeoLoad(name, dir string) *Error {

//check if folder exists
adir, derr := filepath.Abs(dir)
if derr!= nil {
if derr != nil {
cerr := ErrNew(derr, fmt.Sprintf("could not parse the absolute path: %s", adir))
return cerr
}
Expand Down
26 changes: 23 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var (
)

const (
VERSION = "alpha-1.8"
VERSION = "alpha-1.8.1"
)

func checkCompleteness() *Error {
Expand Down Expand Up @@ -49,13 +49,14 @@ func checkCompleteness() *Error {
func main() {
var InitReset bool
var InitDep string
var InitUseOldGlibc bool
var initCmd = &cobra.Command{
Use: "init",
Short: "init the lpmx itself",
Long: "init command is the basic command of lpmx, which is used for initializing lpmx system",
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
err := Init(InitReset, InitDep)
err := Init(InitReset, InitDep, InitUseOldGlibc)
if err != nil {
LOGGER.Fatal(err.Error())
return
Expand All @@ -69,6 +70,7 @@ func main() {
}
initCmd.Flags().BoolVarP(&InitReset, "reset", "r", false, "initialize by force(optional)")
initCmd.Flags().StringVarP(&InitDep, "dependency", "d", "", "dependency tar ball(optional)")
initCmd.Flags().BoolVarP(&InitUseOldGlibc, "use-old-glibc", "g", false, "use old glibc veresion(optional)")

var ListName string
var listCmd = &cobra.Command{
Expand Down Expand Up @@ -1031,6 +1033,24 @@ func main() {
},
}

var ResetUseOldGlibc bool
var resetCmd = &cobra.Command{
Use: "reset",
Short: "reset dependencies",
Long: "reset necessary libraries of lpmx",
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
err := Reset(ResetUseOldGlibc)
if err != nil {
LOGGER.Error(err.Error())
return
} else {
LOGGER.Info("DONE")
}
},
}
resetCmd.Flags().BoolVarP(&ResetUseOldGlibc, "use-old-glibc", "g", false, "use old glibc veresion(optional)")

var versionCmd = &cobra.Command{
Use: "version",
Short: "show the version of LPMX",
Expand All @@ -1045,6 +1065,6 @@ func main() {
Use: "lpmx",
Short: "lpmx rootless container",
}
rootCmd.AddCommand(initCmd, destroyCmd, listCmd, setCmd, resumeCmd, getCmd, dockerCmd, singularityCmd, exposeCmd, uninstallCmd, versionCmd, downloadCmd, updateCmd)
rootCmd.AddCommand(initCmd, destroyCmd, listCmd, setCmd, resumeCmd, getCmd, dockerCmd, singularityCmd, exposeCmd, uninstallCmd, versionCmd, downloadCmd, updateCmd, resetCmd)
rootCmd.Execute()
}

0 comments on commit 1a91e2f

Please sign in to comment.