2016-07-08 19:04:00 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"net"
|
2016-07-22 20:44:27 +00:00
|
|
|
"os"
|
2016-07-08 19:04:00 +00:00
|
|
|
|
|
|
|
"github.com/kubernetes/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
|
|
|
|
"github.com/mrunalp/ocid/server"
|
2016-07-20 01:30:05 +00:00
|
|
|
"github.com/urfave/cli"
|
2016-07-08 19:04:00 +00:00
|
|
|
"google.golang.org/grpc"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2016-07-22 20:44:27 +00:00
|
|
|
unixDomainSocket = "/var/run/ocid.sock"
|
2016-07-08 19:04:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2016-07-20 01:30:05 +00:00
|
|
|
app := cli.NewApp()
|
|
|
|
app.Name = "ocic"
|
|
|
|
app.Usage = "client for ocid"
|
|
|
|
|
|
|
|
app.Flags = []cli.Flag{
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "sandboxdir",
|
|
|
|
Value: "/var/lib/ocid/sandbox",
|
|
|
|
Usage: "ocid pod sandbox dir",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
app.Action = func(c *cli.Context) error {
|
|
|
|
// Remove the socket if it already exists
|
|
|
|
if _, err := os.Stat(unixDomainSocket); err == nil {
|
|
|
|
if err := os.Remove(unixDomainSocket); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lis, err := net.Listen("unix", unixDomainSocket)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("failed to listen: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
s := grpc.NewServer()
|
|
|
|
|
|
|
|
sandboxDir := c.String("sandboxdir")
|
|
|
|
service, err := server.New("", sandboxDir)
|
|
|
|
if err != nil {
|
2016-07-22 20:44:27 +00:00
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2016-07-20 01:30:05 +00:00
|
|
|
|
|
|
|
runtime.RegisterRuntimeServiceServer(s, service)
|
|
|
|
runtime.RegisterImageServiceServer(s, service)
|
|
|
|
s.Serve(lis)
|
|
|
|
return nil
|
2016-07-22 20:44:27 +00:00
|
|
|
}
|
2016-07-20 01:30:05 +00:00
|
|
|
|
|
|
|
if err := app.Run(os.Args); err != nil {
|
2016-07-19 18:53:57 +00:00
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2016-07-08 19:04:00 +00:00
|
|
|
}
|