cubefs

Форк
0
103 строки · 2.6 Кб
1
// Copyright 2022 The CubeFS Authors.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12
// implied. See the License for the specific language governing
13
// permissions and limitations under the License.
14

15
package main
16

17
import (
18
	"net/http"
19
	"os"
20

21
	"github.com/cubefs/cubefs/blobstore/common/config"
22
	"github.com/cubefs/cubefs/blobstore/common/rpc"
23
	"github.com/cubefs/cubefs/blobstore/common/rpc/auditlog"
24
	"github.com/cubefs/cubefs/blobstore/common/rpc/example"
25
	"github.com/cubefs/cubefs/blobstore/util/log"
26
)
27

28
// Config service config
29
type Config struct {
30
	LogLevel log.Level       `json:"log_level"`
31
	AuditLog auditlog.Config `json:"auditlog"`
32

33
	App struct {
34
		BindAddr string            `json:"bind_addr"`
35
		App      example.AppConfig `json:"app"`
36
	} `json:"app"`
37
	File struct {
38
		BindAddr string `json:"bind_addr"`
39
	} `json:"file"`
40
	Meta struct {
41
		BindAddr string `json:"bind_addr"`
42
	} `json:"meta"`
43
}
44

45
func main() {
46
	config.Init("f", "", "main.conf")
47

48
	var conf Config
49
	err := config.Load(&conf)
50
	if err != nil {
51
		log.Fatal(err)
52
	}
53
	log.SetOutputLevel(conf.LogLevel)
54

55
	os.MkdirAll(conf.AuditLog.LogDir, 0o644)
56
	lh, lf, _ := auditlog.Open("RPC", &conf.AuditLog)
57
	defer lf.Close()
58

59
	{
60
		c := conf.Meta
61
		httpServer := &http.Server{
62
			Addr:    c.BindAddr,
63
			Handler: rpc.MiddlewareHandlerWith(example.NewMetaHandler(), lh),
64
		}
65

66
		log.Info("meta server is running at:", c.BindAddr)
67
		go func() {
68
			if err := httpServer.ListenAndServe(); err != nil && err != http.ErrServerClosed {
69
				log.Panic("meta server exits:", err)
70
			}
71
		}()
72
	}
73
	{
74
		c := conf.File
75
		httpServer := &http.Server{
76
			Addr:    c.BindAddr,
77
			Handler: rpc.MiddlewareHandlerWith(example.NewFileHandler(), lh),
78
		}
79

80
		log.Info("file server is running at:", c.BindAddr)
81
		go func() {
82
			if err := httpServer.ListenAndServe(); err != nil && err != http.ErrServerClosed {
83
				log.Panic("file server exits:", err)
84
			}
85
		}()
86
	}
87
	{
88
		c := conf.App
89
		httpServer := &http.Server{
90
			Addr:    c.BindAddr,
91
			Handler: rpc.MiddlewareHandlerWith(example.NewAppHandler(c.App), lh),
92
		}
93

94
		log.Info("app server is running at:", c.BindAddr)
95
		go func() {
96
			if err := httpServer.ListenAndServe(); err != nil && err != http.ErrServerClosed {
97
				log.Panic("app server exits:", err)
98
			}
99
		}()
100
	}
101

102
	<-make(chan struct{})
103
}
104

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.