func runAPIService(cmd *cobra.Command, args []string) (exit int) { // Set up the signal handler here so we can make sure the // signals are caught after print the starting message. signal.Notify(exitCh, syscall.SIGINT, syscall.SIGTERM) log.Print("API service starting...") tcpl, err := net.Listen("tcp", flagAPIServiceListenClientURL) if err != nil { stderr("api-service: %v", err) return 1 } defer tcpl.Close() publicServer := grpc.NewServer() // TODO(yifan): Add TLS credential option. v1AlphaAPIServer, err := newV1AlphaAPIServer() if err != nil { stderr("api-service: failed to create API service: %v", err) return 1 } v1alpha.RegisterPublicAPIServer(publicServer, v1AlphaAPIServer) go publicServer.Serve(tcpl) log.Printf("API service running on %v...", flagAPIServiceListenClientURL) <-exitCh log.Print("API service exiting...") return }
// Open one or more listening sockets, then start the gRPC server func runAPIService(cmd *cobra.Command, args []string) (exit int) { // Set up the signal handler here so we can make sure the // signals are caught after print the starting message. signal.Notify(exitCh, syscall.SIGINT, syscall.SIGTERM) stderr.Print("API service starting...") listeners, err := openAPISockets() if err != nil { stderr.PrintE("Failed to open sockets", err) return 254 } if len(listeners) == 0 { // This is unlikely... stderr.Println("No sockets to listen to. Quitting.") return 254 } publicServer := grpc.NewServer() // TODO(yifan): Add TLS credential option. v1AlphaAPIServer, err := newV1AlphaAPIServer() if err != nil { stderr.PrintE("failed to create API service", err) return 254 } v1alpha.RegisterPublicAPIServer(publicServer, v1AlphaAPIServer) for _, l := range listeners { defer l.Close() go publicServer.Serve(l) } stderr.Printf("API service running") <-exitCh stderr.Print("API service exiting...") return }