Merge pull request #44 from runcom/sock-flag

cmd/server: add socket flag
This commit is contained in:
Mrunal Patel 2016-09-20 10:35:12 -07:00 committed by GitHub
commit e2f60be880
2 changed files with 16 additions and 14 deletions

4
.gitignore vendored
View file

@ -1,4 +1,4 @@
ocid
ocic
/ocid
/ocic
conmon/conmon
conmon/conmon.o

View file

@ -12,10 +12,6 @@ import (
"google.golang.org/grpc"
)
const (
unixDomainSocket = "/var/run/ocid.sock"
)
func main() {
app := cli.NewApp()
app.Name = "ocic"
@ -27,16 +23,21 @@ func main() {
Value: "/var/lib/ocid/sandboxes",
Usage: "ocid pod sandbox dir",
},
cli.StringFlag{
Name: "runtime",
Value: "/usr/bin/runc",
Usage: "OCI runtime path",
},
cli.StringFlag{
Name: "containerdir",
Value: "/var/lib/ocid/containers",
Usage: "ocid container dir",
},
cli.StringFlag{
Name: "socket",
Value: "/var/run/ocid.sock",
Usage: "path to ocid socket",
},
cli.StringFlag{
Name: "runtime",
Value: "/usr/bin/runc",
Usage: "OCI runtime path",
},
cli.BoolFlag{
Name: "debug",
Usage: "enable debug output for logging",
@ -76,13 +77,14 @@ func main() {
}
app.Action = func(c *cli.Context) error {
socketPath := c.String("socket")
// Remove the socket if it already exists
if _, err := os.Stat(unixDomainSocket); err == nil {
if err := os.Remove(unixDomainSocket); err != nil {
if _, err := os.Stat(socketPath); err == nil {
if err := os.Remove(socketPath); err != nil {
logrus.Fatal(err)
}
}
lis, err := net.Listen("unix", unixDomainSocket)
lis, err := net.Listen("unix", socketPath)
if err != nil {
logrus.Fatalf("failed to listen: %v", err)
}