/
init.go
45 lines (38 loc) · 920 Bytes
/
init.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package cmd
import (
"github.com/baetyl/baetyl-go/v2/context"
"github.com/baetyl/baetyl-go/v2/errors"
"github.com/spf13/cobra"
_ "github.com/baetyl/baetyl/ami"
"github.com/baetyl/baetyl/config"
"github.com/baetyl/baetyl/initz"
"github.com/baetyl/baetyl/plugin"
)
func init() {
rootCmd.AddCommand(initCmd)
}
var initCmd = &cobra.Command{
Use: "init",
Short: "Run init program of Baetyl",
Long: `Baetyl runs the init program to sync with cloud and start core service.`,
Run: func(_ *cobra.Command, _ []string) {
startInitService()
},
}
func startInitService() {
context.Run(func(ctx context.Context) error {
var cfg config.Config
err := ctx.LoadCustomConfig(&cfg)
if err != nil {
return errors.Trace(err)
}
plugin.ConfFile = ctx.ConfFile()
init, err := initz.NewInitialize(cfg)
if err != nil {
return errors.Trace(err)
}
defer init.Close()
ctx.Wait()
return nil
})
}