コード例 #1
0
ファイル: caretakerd.go プロジェクト: echocat/caretakerd
// NewCaretakerd creates a new Caretakerd instance from the given config
func NewCaretakerd(conf Config, syncGroup *usync.Group) (*Caretakerd, error) {
	err := conf.Validate()
	if err != nil {
		return nil, err
	}
	log, err := logger.NewLogger(conf.Logger, "caretakerd", syncGroup)
	if err != nil {
		return nil, errors.New("Could not create logger for caretakerd.").CausedBy(err)
	}
	ks, err := keyStore.NewKeyStore(bool(conf.RPC.Enabled), conf.KeyStore)
	if err != nil {
		return nil, err
	}
	ctl, err := control.NewControl(conf.Control, ks)
	if err != nil {
		return nil, err
	}
	services, err := service.NewServices(conf.Services, syncGroup, ks)
	if err != nil {
		return nil, err
	}
	result := Caretakerd{
		open:          true,
		config:        conf,
		logger:        log,
		control:       ctl,
		keyStore:      ks,
		services:      services,
		lock:          new(sync.Mutex),
		syncGroup:     syncGroup,
		signalChannel: nil,
	}
	runtime.SetFinalizer(&result, finalize)
	return &result, nil
}
コード例 #2
0
ファイル: service.go プロジェクト: echocat/caretakerd
// NewService creates a new service instance from the given Config.
func NewService(conf Config, name string, syncGroup *usync.Group, sec *keyStore.KeyStore) (*Service, error) {
	err := conf.Validate()
	if err != nil {
		return nil, errors.New("Config of service '%v' is not valid.", name).CausedBy(err)
	}
	acc, err := access.NewAccess(conf.Access, name, sec)
	if err != nil {
		return nil, errors.New("Could not create access for service '%v'.", name).CausedBy(err)
	}
	log, err := logger.NewLogger(conf.Logger, name, syncGroup)
	if err != nil {
		return nil, errors.New("Could not create logger for service '%v'.", name).CausedBy(err)
	}
	result := &Service{
		config:    conf,
		logger:    log,
		name:      name,
		syncGroup: syncGroup,
		access:    acc,
	}
	runtime.SetFinalizer(result, finalize)
	return result, nil
}
コード例 #3
0
ファイル: main.go プロジェクト: echocat/caretakerd
	"fmt"
	"github.com/echocat/caretakerd"
	"github.com/echocat/caretakerd/app"
	"github.com/echocat/caretakerd/logger"
	"github.com/echocat/caretakerd/sync"
	"io/ioutil"
	"os"
	"path/filepath"
)

var version string
var packageName string

var log, _ = logger.NewLogger(logger.Config{
	Level:    logger.Info,
	Filename: "console",
	Pattern:  "%d{YYYY-MM-DD HH:mm:ss} [%-5.5p] %m%n%P{%m}",
}, "manual", sync.NewGroup())

func panicHandler() {
	if r := recover(); r != nil {
		log.LogProblem(r, logger.Fatal, "There is an unrecoverable problem occured.")
		os.Exit(2)
	}
}

func getSrcRootPath() string {
	if len(os.Args) < 2 || len(os.Args[1]) <= 0 {
		fmt.Fprintf(os.Stderr, "Usage: %v <package> <output>\n", os.Args[0])
		os.Exit(1)
	}