-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
131 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,10 @@ _testmain.go | |
*.exe | ||
*.test | ||
*.prof | ||
|
||
cmt | ||
runtime.json | ||
config.json | ||
rootfs | ||
cpuinfo.img | ||
descriptors.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
|
||
sudo rm dump.tar.gz | ||
ssh 172.31.60.136 <<EOF | ||
cd lala | ||
sudo runc kill | ||
sudo rm -fr /var/run/opencontainer/ | ||
sudo rm -fr images | ||
sudo rm dump.tar.gz | ||
sudo sh -c 'runc start &' | ||
echo "DONE" | ||
EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,87 @@ | ||
package migrate | ||
|
||
import "github.com/codegangsta/cli" | ||
import ( | ||
"fmt" | ||
"log" | ||
"path/filepath" | ||
|
||
"github.com/codegangsta/cli" | ||
"github.com/marcosnils/cmt/cmd" | ||
"github.com/marcosnils/cmt/validate" | ||
) | ||
|
||
var Command = cli.Command{ | ||
Name: "migrate", | ||
Usage: "Migrate running container", | ||
Flags: []cli.Flag{ | ||
cli.StringFlag{ | ||
Name: "source-host", | ||
Name: "src", | ||
Usage: "Source host where the container is running", | ||
}, | ||
cli.StringFlag{ | ||
Name: "container-dir", | ||
Usage: "Directory where the container is running in the source host", | ||
}, | ||
cli.StringFlag{ | ||
Name: "target-host", | ||
Name: "dst", | ||
Usage: "Target host to migrate the container", | ||
}, | ||
cli.StringFlag{ | ||
Name: "target-container-dir", | ||
Usage: "Directory to copy container data in target host", | ||
}, | ||
cli.BoolFlag{ | ||
Name: "pre-dump", | ||
Usage: "Perform pre-dumps when migrating", | ||
}, | ||
cli.DurationFlag{ | ||
Name: "max-downtime", | ||
Usage: "Max downtime allowed when performing pre-dumps", | ||
}, | ||
}, | ||
Action: func(c *cli.Context) { | ||
srcUrl := validate.ParseURL(c.String("src")) | ||
dstUrl := validate.ParseURL(c.String("dst")) | ||
|
||
log.Println("Performing validations") | ||
src, dst := validate.Validate(srcUrl, dstUrl) | ||
|
||
log.Println("Preparing everything to do a checkpoint") | ||
imagesPath := fmt.Sprintf("%s/images", srcUrl.Path) | ||
containerId := getContainerId(srcUrl.Path) | ||
|
||
_, _, err := src.Run("mkdir", "-p", imagesPath) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
log.Println("Performing the checkpoint") | ||
_, _, err = src.Run("sudo", "runc", "--id", containerId, "checkpoint", "--image-path", imagesPath) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
srcTarFile := fmt.Sprintf("%s/dump.tar.gz", srcUrl.Path) | ||
dstTarFile := fmt.Sprintf("%s/images/dump.tar.gz", dstUrl.Path) | ||
_, _, err = src.Run("sudo", "tar", "-czf", srcTarFile, "-C", fmt.Sprintf("%s/", imagesPath), ".") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
log.Println("Copying checkpoint image to dst") | ||
_, _, err = dst.Run("mkdir", "-p", fmt.Sprintf("%s/images", dstUrl.Path)) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
err = cmd.Scp(src.URL(srcTarFile), dst.URL(fmt.Sprintf("%s/images", dstUrl.Path))) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
log.Println("Preparing image at destination host") | ||
_, _, err = dst.Run("sudo", "tar", "-C", fmt.Sprintf("%s/images", dstUrl.Path), "-xvzf", dstTarFile) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
log.Println("Performing the restore") | ||
configFilePath := fmt.Sprintf("%s/config.json", dstUrl.Path) | ||
runtimeFilePath := fmt.Sprintf("%s/runtime.json", dstUrl.Path) | ||
dstImagesPath := fmt.Sprintf("%s/images", dstUrl.Path) | ||
_, _, err = dst.Output("sudo", "runc", "--id", containerId, "restore", "--image-path", dstImagesPath, "--config-file", configFilePath, "--runtime-file", runtimeFilePath) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
}, | ||
} | ||
|
||
func getContainerId(path string) string { | ||
_, id := filepath.Split(path) | ||
return id | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters