cmd/server: add socket flag

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
Antonio Murdaca 2016-09-20 12:31:10 +02:00
parent 2378a1983a
commit 910f343f79
No known key found for this signature in database
GPG key ID: B2BEAD150DE936B9

View file

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