Improve prefix creation and feedback

This makes the default /var/lib/mgmt/ directory, but also allows you to
use a prefix in /tmp/ automatically if you can't write anywhere else.
This commit is contained in:
James Shubin
2016-08-09 16:22:37 -04:00
parent 79ba750dd5
commit 03c1df98f4
2 changed files with 23 additions and 0 deletions

View File

@@ -1539,6 +1539,8 @@ func (obj *EmbdEtcd) StartServer(newCluster bool, peerURLsMap etcdtypes.URLsMap)
err = os.MkdirAll(obj.dataDir, 0770) err = os.MkdirAll(obj.dataDir, 0770)
if err != nil { if err != nil {
log.Printf("Etcd: StartServer: Couldn't mkdir: %s.", obj.dataDir)
log.Printf("Etcd: StartServer: Mkdir error: %s.", err)
obj.DestroyServer() obj.DestroyServer()
return err return err
} }

21
main.go
View File

@@ -22,6 +22,7 @@ import (
etcdtypes "github.com/coreos/etcd/pkg/types" etcdtypes "github.com/coreos/etcd/pkg/types"
"github.com/coreos/pkg/capnslog" "github.com/coreos/pkg/capnslog"
"github.com/urfave/cli" "github.com/urfave/cli"
"io/ioutil"
"log" "log"
"os" "os"
"os/signal" "os/signal"
@@ -121,6 +122,22 @@ func run(c *cli.Context) error {
return cli.NewExitError("", 1) return cli.NewExitError("", 1)
} }
// make sure the working directory prefix exists
if err := os.MkdirAll(prefix, 0770); err != nil {
if c.Bool("allow-tmp-prefix") {
if prefix, err = ioutil.TempDir("", program); err != nil {
log.Printf("Main: Error: Can't create temporary prefix!")
return cli.NewExitError("", 1)
}
log.Println("Main: Warning: Working prefix directory is temporary!")
} else {
log.Printf("Main: Error: Can't create prefix!")
return cli.NewExitError("", 1)
}
}
log.Printf("Main: Working prefix is: %s", prefix)
var wg sync.WaitGroup var wg sync.WaitGroup
exit := make(chan bool) // exit signal exit := make(chan bool) // exit signal
var G, fullGraph *Graph var G, fullGraph *Graph
@@ -472,6 +489,10 @@ func main() {
Name: "no-caching", Name: "no-caching",
Usage: "don't allow remote caching of remote execution binary", Usage: "don't allow remote caching of remote execution binary",
}, },
cli.BoolFlag{
Name: "allow-tmp-prefix",
Usage: "allow creation of a new temporary prefix if main prefix is unavailable",
},
}, },
}, },
} }