talos/internal/app/osd/main.go
Andrey Smirnov ab2917e833
feat(init): implement init gRPC API, forward reboot to init (#579)
This implements insecure over-file-socket gRPC API for init with two
first simplest APIs: reboot and shutdown (poweroff).

File socket is mounted only to `osd` service, so it is the only service
which can access init API. Osd forwards reboot/shutdown already
implemented APIs to init which actually executes these.

This enables graceful shutdown/reboot with service shutdown, sync, etc.

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
2019-04-26 23:04:24 +03:00

63 lines
1.4 KiB
Go

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package main
import (
"flag"
"log"
"github.com/talos-systems/talos/internal/app/osd/internal/reg"
"github.com/talos-systems/talos/internal/pkg/constants"
"github.com/talos-systems/talos/internal/pkg/grpc/factory"
"github.com/talos-systems/talos/internal/pkg/grpc/tls"
"github.com/talos-systems/talos/pkg/userdata"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
)
var (
dataPath *string
)
func init() {
log.SetFlags(log.Lshortfile | log.Ldate | log.Lmicroseconds | log.Ltime)
dataPath = flag.String("userdata", "", "the path to the user data")
flag.Parse()
}
func main() {
data, err := userdata.Open(*dataPath)
if err != nil {
log.Fatalf("open user data: %v", err)
}
config, err := tls.NewConfig(tls.Mutual, data.Security.OS)
if err != nil {
log.Fatalf("credentials: %v", err)
}
initClient, err := reg.NewInitServiceClient()
if err != nil {
log.Fatalf("init client: %v", err)
}
log.Println("Starting osd")
err = factory.ListenAndServe(
&reg.Registrator{
Data: data,
InitServiceClient: initClient,
},
factory.Port(constants.OsdPort),
factory.ServerOptions(
grpc.Creds(
credentials.NewTLS(config),
),
),
)
if err != nil {
log.Fatalf("listen: %v", err)
}
}