mirror of https://github.com/minio/minio.git
Merge pull request #741 from harshavardhana/pr_out_mkdonut_now_creates_a_donut_processing_cli_args
mkdonut now creates a donut processing cli args
This commit is contained in:
commit
36904d5da9
1
Makefile
1
Makefile
|
@ -34,6 +34,7 @@ cyclo:
|
||||||
gomake-all: getdeps verifiers
|
gomake-all: getdeps verifiers
|
||||||
@echo "Installing minio:"
|
@echo "Installing minio:"
|
||||||
@go run make.go install
|
@go run make.go install
|
||||||
|
@go run cmd/mkdonut/make.go install
|
||||||
|
|
||||||
release: getdeps verifiers
|
release: getdeps verifiers
|
||||||
@echo "Installing minio:"
|
@echo "Installing minio:"
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
mkdonut
|
|
@ -17,22 +17,21 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/minio/minio/pkg/iodine"
|
"github.com/minio/minio/pkg/iodine"
|
||||||
)
|
)
|
||||||
|
|
||||||
// IsUsable provides a comprehensive way of knowing if the provided mountPath is mounted and writable
|
// isUsable provides a comprehensive way of knowing if the provided mountPath is mounted and writable
|
||||||
func IsUsable(mountPath string) (bool, error) {
|
func isUsable(mountPath string) (bool, error) {
|
||||||
mntpoint, err := os.Stat(mountPath)
|
mntpoint, err := os.Stat(mountPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, iodine.New(err, nil)
|
return false, iodine.New(err, nil)
|
||||||
}
|
}
|
||||||
parent, err := os.Stat(filepath.Join(mountPath, ".."))
|
parent, err := os.Stat("/")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, iodine.New(err, nil)
|
return false, iodine.New(err, nil)
|
||||||
}
|
}
|
||||||
|
@ -40,7 +39,7 @@ func IsUsable(mountPath string) (bool, error) {
|
||||||
parentSt := parent.Sys().(*syscall.Stat_t)
|
parentSt := parent.Sys().(*syscall.Stat_t)
|
||||||
|
|
||||||
if mntpointSt.Dev == parentSt.Dev {
|
if mntpointSt.Dev == parentSt.Dev {
|
||||||
return false, iodine.New(errors.New("not mounted"), nil)
|
return false, iodine.New(fmt.Errorf("Not mounted %s", mountPath), nil)
|
||||||
}
|
}
|
||||||
testFile, err := ioutil.TempFile(mountPath, "writetest-")
|
testFile, err := ioutil.TempFile(mountPath, "writetest-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -20,12 +20,14 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/dustin/go-humanize"
|
"github.com/dustin/go-humanize"
|
||||||
"github.com/minio/cli"
|
"github.com/minio/cli"
|
||||||
|
"github.com/minio/minio/pkg/donut"
|
||||||
"github.com/minio/minio/pkg/iodine"
|
"github.com/minio/minio/pkg/iodine"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -72,6 +74,50 @@ func getSystemData() map[string]string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func runMkdonut(c *cli.Context) {
|
||||||
|
if !c.Args().Present() || c.Args().First() == "help" {
|
||||||
|
cli.ShowAppHelp(c)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
donutName := c.Args().First()
|
||||||
|
if c.Args().First() != "" {
|
||||||
|
if !donut.IsValidDonut(donutName) {
|
||||||
|
Fatalf("Invalid donutname %s\n", donutName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var disks []string
|
||||||
|
for _, disk := range c.Args().Tail() {
|
||||||
|
if _, err := isUsable(disk); err != nil {
|
||||||
|
Fatalln(err)
|
||||||
|
}
|
||||||
|
disks = append(disks, disk)
|
||||||
|
}
|
||||||
|
for _, disk := range disks {
|
||||||
|
if err := os.MkdirAll(filepath.Join(disk, donutName), 0700); err != nil {
|
||||||
|
Fatalln(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
hostname, err := os.Hostname()
|
||||||
|
if err != nil {
|
||||||
|
Fatalln(err)
|
||||||
|
}
|
||||||
|
donutConfig := &donut.Config{}
|
||||||
|
donutConfig.Version = "0.0.1"
|
||||||
|
donutConfig.DonutName = donutName
|
||||||
|
donutConfig.NodeDiskMap = make(map[string][]string)
|
||||||
|
// keep it in exact order as it was specified, do not try to sort disks
|
||||||
|
donutConfig.NodeDiskMap[hostname] = disks
|
||||||
|
// default cache is unlimited
|
||||||
|
donutConfig.MaxSize = 0
|
||||||
|
|
||||||
|
if err := donut.SaveConfig(donutConfig); err != nil {
|
||||||
|
Fatalln(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
Infoln("Success!")
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// set up iodine
|
// set up iodine
|
||||||
iodine.SetGlobalState("mkdonut.version", Version)
|
iodine.SetGlobalState("mkdonut.version", Version)
|
||||||
|
@ -82,7 +128,8 @@ func main() {
|
||||||
|
|
||||||
// set up app
|
// set up app
|
||||||
app := cli.NewApp()
|
app := cli.NewApp()
|
||||||
app.Name = "minio"
|
app.Action = runMkdonut
|
||||||
|
app.Name = "mkdonut"
|
||||||
app.Version = Version
|
app.Version = Version
|
||||||
app.Compiled = getVersion()
|
app.Compiled = getVersion()
|
||||||
app.Author = "Minio.io"
|
app.Author = "Minio.io"
|
||||||
|
|
|
@ -28,6 +28,22 @@ import (
|
||||||
"github.com/minio/minio/pkg/utils/atomic"
|
"github.com/minio/minio/pkg/utils/atomic"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// IsValidDonut - verify donut name is correct
|
||||||
|
func IsValidDonut(donutName string) bool {
|
||||||
|
if len(donutName) < 3 || len(donutName) > 63 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if donutName[0] == '.' || donutName[len(donutName)-1] == '.' {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if match, _ := regexp.MatchString("\\.\\.", donutName); match == true {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
// We don't support donutNames with '.' in them
|
||||||
|
match, _ := regexp.MatchString("^[a-zA-Z][a-zA-Z0-9\\-]+[a-zA-Z0-9]$", donutName)
|
||||||
|
return match
|
||||||
|
}
|
||||||
|
|
||||||
// IsValidBucket - verify bucket name in accordance with
|
// IsValidBucket - verify bucket name in accordance with
|
||||||
// - http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingBucket.html
|
// - http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingBucket.html
|
||||||
func IsValidBucket(bucket string) bool {
|
func IsValidBucket(bucket string) bool {
|
||||||
|
|
Loading…
Reference in New Issue