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",
|
2016-07-29 22:35:10 +00:00
|
|
|
Value: "/var/lib/ocid/sandboxes",
|
2016-07-20 01:30:05 +00:00
|
|
|
Usage: "ocid pod sandbox dir",
|
|
|
|
},
|
2016-07-29 22:35:10 +00:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "runtime",
|
|
|
|
Value: "/usr/bin/runc",
|
|
|
|
Usage: "OCI runtime path",
|
|
|
|
},
|
2016-08-01 22:08:21 +00:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "containerdir",
|
|
|
|
Value: "/var/lib/ocid/containers",
|
|
|
|
Usage: "ocid container dir",
|
|
|
|
},
|
2016-07-20 01:30:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
2016-08-01 22:08:21 +00:00
|
|
|
containerDir := c.String("containerdir")
|
2016-07-20 01:30:05 +00:00
|
|
|
sandboxDir := c.String("sandboxdir")
|
2016-08-01 22:08:21 +00:00
|
|
|
service, err := server.New(c.String("runtime"), sandboxDir, containerDir)
|
2016-07-20 01:30:05 +00:00
|
|
|
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
|
|
|
}
|