예제 #1
0
파일: telegraf.go 프로젝트: li-ang/telegraf
func main() {
	if runtime.GOOS == "windows" {
		svcConfig = &service.Config{
			Name:        "telegraf",
			DisplayName: "Telegraf Data Collector Service",
			Description: "Collects data using a series of plugins and publishes it to" +
				"another series of plugins.",
			Arguments: []string{"-config", "C:\\Program Files\\Telegraf\\telegraf.conf"},
		}

		prg := &program{}
		s, err := service.New(prg, svcConfig)
		if err != nil {
			log.Fatal(err)
		}
		logger, err = s.Logger(nil)
		if err != nil {
			log.Fatal(err)
		}
		err = s.Run()
		if err != nil {
			logger.Error(err)
		}
	} else {
		stop = make(chan struct{})
		reloadLoop(stop, nil)
	}
}
예제 #2
0
func TestRunInterrupt(t *testing.T) {
	p := &program{}
	sc := &service.Config{
		Name: "go_service_test",
	}
	s, err := service.New(p, sc)
	if err != nil {
		t.Fatalf("New err: %s", err)
	}

	go func() {
		<-time.After(1 * time.Second)
		interruptProcess(t)
	}()

	go func() {
		for i := 0; i < 25 && p.numStopped == 0; i++ {
			<-time.After(200 * time.Millisecond)
		}
		if p.numStopped == 0 {
			t.Fatal("Run() hasn't been stopped")
		}
	}()

	if err = s.Run(); err != nil {
		t.Fatalf("Run() err: %s", err)
	}
}
예제 #3
0
func TestInstallRunRestartStopRemove(t *testing.T) {
	p := &program{}
	s, err := service.New(p, sc)
	if err != nil {
		t.Fatal(err)
	}
	_ = s.Uninstall()

	err = s.Install()
	if err != nil {
		t.Fatal("install", err)
	}
	defer s.Uninstall()

	err = s.Start()
	if err != nil {
		t.Fatal("start", err)
	}
	err = s.Restart()
	if err != nil {
		t.Fatal("restart", err)
	}
	err = s.Stop()
	if err != nil {
		t.Fatal("stop", err)
	}
	err = s.Uninstall()
	if err != nil {
		t.Fatal("uninstall", err)
	}
}
예제 #4
0
func DoInit(cfg WebServerConfiger,
	serviceConfig *service.Config,
	middlewareFactory func(*httpway.Router) map[string]*httpway.Router,
	routeFactory map[string]func(*httpway.Router),
	bootstrap func(server *httpway.Server, logger *golog.Logger, router *httpway.Router) error) (service.Service, error) {

	p := &program{
		middlewareFactory: middlewareFactory,
		routeFactory:      routeFactory,
		bootstrap:         bootstrap,
	}

	s, err := service.New(p, serviceConfig)
	if err != nil {
		log.Fatal(err)
	}

	logger, err := s.Logger(nil)
	if err != nil {
		log.Fatal(err)
	}
	p.systemLog = logger

	if err := initConfig(cfg); err != nil {
		p.systemLog.Error(err)
		return nil, err
	}

	if err := p.initLogger(); err != nil {
		p.systemLog.Error(err)
		return nil, err
	}

	return s, nil
}
예제 #5
0
func main() {
	svcConfig := &service.Config{
		Name:        "GoServiceExampleStopPause",
		DisplayName: "Go Service Example: Stop Pause",
		Description: "This is an example Go service that pauses on stop.",
	}

	prg := &program{}
	s, err := service.New(prg, svcConfig)
	if err != nil {
		log.Fatal(err)
	}
	if len(os.Args) > 1 {
		err = service.Control(s, os.Args[1])
		if err != nil {
			log.Fatal(err)
		}
		return
	}

	logger, err = s.Logger(nil)
	if err != nil {
		log.Fatal(err)
	}
	err = s.Run()
	if err != nil {
		logger.Error(err)
	}
}
예제 #6
0
func main() {
	controlFlag := flag.String("control", "", "{install|uninstall|start|stop}")
	flag.Parse()
	conf := &service.Config{
		Name:        "shuthelper_server",
		DisplayName: "shuthelper server service",
		Description: "remote host shutdown helper service ...",
	}

	p := &program{}

	s, err := service.New(p, conf)
	if err != nil {
		panic(err)
	}

	logger, err = s.Logger(nil)
	if err != nil {
		panic(err)
	}

	if !strings.EqualFold(*controlFlag, "") {
		err = service.Control(s, *controlFlag)
		if err != nil {
			panic(err)
		}
		return
	}

	s.Run()
}
예제 #7
0
파일: main.go 프로젝트: oblank/knowledgedb
func main() {
	svcConfig := &service.Config{
		Name:        "KnowledgeDB",
		DisplayName: "Knowledge DB",
		Description: "Knowledge DB - Webserver",
	}

	prg := &program{}
	s, err := service.New(prg, svcConfig)
	if err != nil {
		log.Fatal(err)
	}

	logger, err := s.Logger(nil)
	if err != nil {
		log.Fatal(err)
	}
	log.SetServiceLogger(logger)

	if len(os.Args) == 2 {
		command := os.Args[1]
		err := service.Control(s, command)
		if err != nil {
			log.Fatalf("%v\n\nValidOperations: %v", err, service.ControlAction)
		}
		return
	}
	err = s.Run()
	if err != nil {
		log.Error(err)
	}
}
예제 #8
0
파일: service.go 프로젝트: Cobolock/GoGO
func main() {

	k, err := registry.OpenKey(registry.LOCAL_MACHINE, "SOFTWARE\\INT", registry.QUERY_VALUE)
	checkErr(err)
	defer k.Close()

	Path, _, err = k.GetStringValue("WorkingDirectory")
	checkErr(err)

	fmt.Printf("%s\n", Path)

	svcConfig := &service.Config{
		Name:        "SphinxMailer",
		DisplayName: "SphinxMailer",
		Description: "Отправляет письма при обнаружении событий в СКУД Сфинкс.",
	}

	prg := &program{}
	s, err := service.New(prg, svcConfig)
	if err != nil {
		log.Fatal(err)
	}
	logger, err = s.Logger(nil)
	if err != nil {
		log.Fatal(err)
	}
	err = s.Run()
	if err != nil {
		logger.Error(err)
	}
}
예제 #9
0
func main() {
	svcConfig := &service.Config{
		Name:        "ArduinoCreateBridge",
		DisplayName: "Arduino Create Bridge",
		Description: "A bridge that allows Arduino Create to operate on the boards connected to the computer",
	}

	prg := &program{}
	s, err := service.New(prg, svcConfig)
	if err != nil {
		log.Fatal(err)
	}
	if len(os.Args) > 1 {
		err = service.Control(s, os.Args[1])
		if err != nil {
			log.Fatal(err)
		}
		return
	}

	logger, err = s.Logger(nil)
	if err != nil {
		log.Fatal(err)
	}

	err = s.Install()
	if err != nil {
		logger.Error(err)
	}

	err = s.Run()
	if err != nil {
		logger.Error(err)
	}
}
예제 #10
0
파일: sync.go 프로젝트: Felamande/filesync
func main() {
	settings.Init()
	flag.Parse()

	if len(os.Args) == 1 {
		flag.Usage()
		return
	}

	if flag.Lookup("run") == nil && flag.Lookup("svcctl") == nil && flag.Lookup("help") == nil && flag.Lookup("console") == nil {
		flag.Usage()
		return
	}

	if *help {
		flag.Usage()
		return
	}

	LogFile, err := os.OpenFile(settings.Log.File, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0777)
	if err != nil {
		fmt.Println(err)
		return
	}

	p := &Program{
		Logger: log.New(LogFile, "[filesync]", log.Ldefault|log.Lmicroseconds),
	}

	s, err := svc.New(p, &svc.Config{
		Name:        "Filesync",
		DisplayName: "FileSync Service",
		Description: "Filesync is a simple tool to sync files between multiple directory pairs.",
		Arguments:   []string{"-run"},
	})

	if err != nil {
		fmt.Println(err.Error())
		return
	}

	if *run {
		if *console {
			p.Logger = log.New(os.Stdout, "[filesync]", log.Ldefault|log.Lmicroseconds)
			p.run()
			return
		}
		err := s.Run()
		fmt.Println("run with error: ", err)
		return
	}

	Actions := strings.Split(*controls, ",")
	for _, action := range Actions {
		err := svc.Control(s, action)
		fmt.Println(err)
	}

}
예제 #11
0
파일: runner.go 프로젝트: anansii/centurio
func main() {
	svcFlag := flag.String("service", "", "Control the system service.")
	flag.Parse()

	configPath, err := getConfigPath()
	if err != nil {
		log.Fatal(err)
	}
	config, err := getConfig(configPath)
	if err != nil {
		log.Fatal(err)
	}

	svcConfig := &service.Config{
		Name:        config.Name,
		DisplayName: config.DisplayName,
		Description: config.Description,
	}

	prg := &program{
		exit: make(chan struct{}),

		Config: config,
	}
	s, err := service.New(prg, svcConfig)
	if err != nil {
		log.Fatal(err)
	}
	prg.service = s

	errs := make(chan error, 5)
	logger, err = s.Logger(errs)
	if err != nil {
		log.Fatal(err)
	}

	go func() {
		for {
			err := <-errs
			if err != nil {
				log.Print(err)
			}
		}
	}()

	if len(*svcFlag) != 0 {
		err := service.Control(s, *svcFlag)
		if err != nil {
			log.Printf("Valid actions: %q\n", service.ControlAction)
			log.Fatal(err)
		}
		return
	}
	err = s.Run()
	if err != nil {
		logger.Error(err)
	}
}
예제 #12
0
파일: main.go 프로젝트: vsdutka/ipdf
// Service setup.
//   Define service config.
//   Create the service.
//   Setup the logger.
//   Handle service controls (optional).
//   Run the service.
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())

	flag.Usage = usage
	svcFlag = flag.String("service", "", fmt.Sprintf("Control the system service. Valid actions: %q\n", service.ControlAction))
	portFlag = flag.Int("port", 17000, "    Port number")
	flag.Parse()

	if *portFlag == 0 {
		usage()
		os.Exit(2)
	}

	svcConfig := &service.Config{
		Name:        serviceName(),
		DisplayName: serviceDisplayName(),
		Description: serviceDisplayName(),
		Arguments:   []string{fmt.Sprintf("-port=%d", *portFlag)},
	}

	prg := &program{}
	s, err := service.New(prg, svcConfig)
	if err != nil {
		log.Fatal(err)
	}
	errs := make(chan error, 5)
	func() {
		loggerLock.Lock()
		defer loggerLock.Unlock()
		logger, err = s.Logger(errs)
		if err != nil {
			log.Fatal(err)
		}
	}()

	go func() {
		for {
			err := <-errs
			if err != nil {
				log.Print(err)
			}
		}
	}()

	if len(*svcFlag) != 0 {
		err := service.Control(s, *svcFlag)
		if err != nil {
			log.Printf("Valid actions: %q\n", service.ControlAction)
			log.Fatal(err)
		}
		return
	}
	err = s.Run()
	if err != nil {
		logError(err)
	}
}
예제 #13
0
// Service setup.
//   Define service config.
//   Create the service.
//   Setup the logger.
//   Handle service controls (optional).
//   Run the service.
func main() {

	svcFlag := flag.String("service", "", "Control the system service.")
	flag.Parse()

	if !service.Interactive() {
		root, _ := osext.ExecutableFolder()

		f, err := os.OpenFile(root+"/output.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
		if err != nil {
			log.Fatal(err)
		}
		defer f.Close()
		log.SetOutput(f)
	}

	svcConfig := &service.Config{
		Name:        "FPL Checker",
		DisplayName: "FPL Checker",
		Description: "Free Post Code Lottery daily winner checker",
	}

	prg := &program{}
	s, err := service.New(prg, svcConfig)
	if err != nil {
		log.Fatal(err)
	}
	errs := make(chan error, 5)
	logger, err = s.Logger(errs)
	if err != nil {
		log.Fatal(err)
	}

	go func() {
		for {
			err := <-errs
			if err != nil {
				log.Print(err)
			}
		}
	}()

	if len(*svcFlag) != 0 {
		err := service.Control(s, *svcFlag)
		if err != nil {
			log.Printf("Valid actions: %q\n", service.ControlAction)
			log.Fatal(err)
		}
		return
	}
	err = s.Run()
	if err != nil {
		logger.Error(err)
	}
}
예제 #14
0
func runService() {
	p := &program{}
	s, err := service.New(p, sc)
	if err != nil {
		log.Fatal(err)
	}
	err = s.Run()
	if err != nil {
		log.Fatal(err)
	}
}
예제 #15
0
func runService() {
	p := &program{}
	sc := &service.Config{
		Name: "go_service_test",
	}
	s, err := service.New(p, sc)
	if err != nil {
		log.Fatal(err)
	}
	if err = s.Run(); err != nil {
		log.Fatal(err)
	}
}
예제 #16
0
func main() {
	usageHelpMessage := `You must set the config, e.g. BarcodeQueryTool.exe -config="config.json"`

	// Get flags
	svcFlag := flag.String("service", "", "Control the system service.")
	mainconfig := flag.String("config", "", usageHelpMessage)
	flag.Parse()

	svcConfig := &service.Config{
		Name:        "Barcode Query Tool",
		DisplayName: "BarcodeQueryTool",
		Description: "Back-end for BarcodeQueryTool in Siemens WinCC",
		Arguments:   []string{"-config=" + *mainconfig},
	}
	newApp := &app{}
	s, err := service.New(newApp, svcConfig)
	if err != nil {
		log.Fatal(err)
	}

	if *svcFlag != "" {
		err = service.Control(s, *svcFlag)
		if err != nil {
			log.Printf("Valid actions: %q\n", service.ControlAction)
			log.Fatal(err)
		}
		return
	}

	newApp.execPath, err = osext.ExecutableFolder()
	if err != nil {
		log.Fatalf("Error finding program executable path: %v", err)
	}

	// Load config
	if *mainconfig == "" {
		log.Fatal(usageHelpMessage)
	}
	newApp.conf = &api.AppConfig{}
	err = newApp.conf.LoadFromFile(newApp.execPath + "\\" + *mainconfig)
	if err != nil {
		log.Fatalf("Error loading %v: %v", *mainconfig, err)
	}

	err = s.Run()
	if err != nil {
		log.Fatal(err)
	}
}
예제 #17
0
func mustNewRunAsService(
	t *testing.T,
	p *program,
	reportDir string,
) service.Service {
	sc := &service.Config{
		Name:      "go_service_test",
		Arguments: []string{"-test.v=true", runAsServiceArg, reportDir},
	}
	s, err := service.New(p, sc)
	if err != nil {
		t.Fatal(err)
	}
	return s
}
예제 #18
0
func main() {
	if commandLineSetup() {
		return
	}

	// setup system service
	serviceConfig := &service.Config{
		Name:        daemon.Daemon.Name,
		DisplayName: daemon.Daemon.DisplayName,
		Description: daemon.Daemon.Description,
	}

	supervisor := daemon.Daemon.NewSupervisor()
	s, err := service.New(supervisor, serviceConfig)
	if err != nil {
		log.Fatalf("Operating system is not supported: %s", err)
	}
	supervisor.BindToService(s)

	if len(*serviceParam) != 0 {
		err := service.Control(s, *serviceParam)
		if err != nil {
			log.Info("Valid service actions:\n", service.ControlAction)
			log.Fatal(err)
		}
		return
	}

	// initialize application context
	context := context.NewContext()
	err = context.LoadConfig(configurationFile)
	if err != nil {
		log.Fatal("Loading configuration file failed.")
	}
	if cfgfile.ValidateConfig() {
		log.Info("Config OK")
		return
	}

	backendSetup(context)

	// start main loop
	services.StartPeriodicals(context)
	err = s.Run()
	if err != nil {
		log.Fatal(err)
	}
}
예제 #19
0
func main() {
	svcFlag := flag.String("service", "", "Control the system service.")
	flag.Parse()

	svcConfig := &service.Config{
		Name:        "GoPrintServer",
		DisplayName: "Go Print Server",
		Description: "Expose printer control as WebSocket server.",
	}

	prg := &program{}
	s, err := service.New(prg, svcConfig)
	if err != nil {
		log.Fatal(err)
	}
	logger, err = s.Logger(nil)
	if err != nil {
		log.Fatal(err)
	}
	errs := make(chan error, 5)
	logger, err = s.Logger(errs)
	if err != nil {
		log.Fatal(err)
	}

	go func() {
		for {
			err := <-errs
			if err != nil {
				log.Print(err)
			}
		}
	}()

	if len(*svcFlag) != 0 {
		err := service.Control(s, *svcFlag)
		if err != nil {
			log.Printf("Valid actions: %q\n", service.ControlAction)
			log.Fatal(err)
		}
		return
	}
	err = s.Run()
	if err != nil {
		logger.Error(err)
	}
}
예제 #20
0
func main() {
	svcConfig := &service.Config{
		Name:        "podcastd",
		DisplayName: "podcastd",
		Description: "https://github.com/bigwhoop/podcastd (v" + VERSION + ")",
	}

	prg := &daemon{}

	s, err := service.New(prg, svcConfig)
	if err != nil {
		logger.Fatal(err)
	}

	if s.Run() != nil {
		logger.Fatal(err)
	}
}
예제 #21
0
파일: gtd.go 프로젝트: anansii/centurio
// Service setup.
//   Define service config.
//   Create the service.
//   Setup the logger.
//   Handle service controls (optional).
//   Run the service.
func main() {
	svcFlag := flag.String("service", "", "Control the system service.")
	flag.Parse()

	svcConfig := &service.Config{
		Name:        "gtdworker",
		DisplayName: "Getting Things Done",
		Description: "Worker Service to get things done.",
	}

	prg := &program{}
	s, err := service.New(prg, svcConfig)
	if err != nil {
		log.Fatal(err)
	}
	errs := make(chan error, 5)
	logger, err = s.Logger(errs)
	if err != nil {
		log.Fatal(err)
	}

	go func() {
		for {
			err := <-errs
			if err != nil {
				log.Print(err)
			}
		}
	}()

	if len(*svcFlag) != 0 {
		err := service.Control(s, *svcFlag)
		if err != nil {
			log.Printf("Valid actions: %q\n", service.ControlAction)
			log.Fatal(err)
		}
		return
	}

	err = s.Run()
	if err != nil {
		logger.Error(err)
	}
}
예제 #22
0
파일: main.go 프로젝트: sdhjl2000/service
// Service setup.
//   Define service config.
//   Create the service.
//   Setup the logger.
//   Handle service controls (optional).
//   Run the service.
func main() {
	svcFlag := flag.String("service", "", "Control the system service.")
	flag.Parse()

	svcConfig := &service.Config{
		Name:        "GoServiceExampleLogging",
		DisplayName: "Go Service Example for Logging",
		Description: "This is an example Go service that outputs log messages.",
	}

	prg := &program{}
	s, err := service.New(prg, svcConfig)
	if err != nil {
		log.Fatal(err)
	}
	errs := make(chan error, 5)
	logger, err = s.Logger(errs)
	if err != nil {
		log.Fatal(err)
	}

	go func() {
		for {
			err := <-errs
			if err != nil {
				log.Print(err)
			}
		}
	}()

	if len(*svcFlag) != 0 {
		err := service.Control(s, *svcFlag)
		if err != nil {
			log.Printf("Valid actions: %q\n", service.ControlAction)
			log.Fatal(err)
		}
		return
	}
	err = s.Run()
	if err != nil {
		logger.Error(err)
	}
}
예제 #23
0
파일: telegraf.go 프로젝트: ninech/telegraf
func main() {
	if runtime.GOOS == "windows" {
		svcConfig = &service.Config{
			Name:        "telegraf",
			DisplayName: "Telegraf Data Collector Service",
			Description: "Collects data using a series of plugins and publishes it to" +
				"another series of plugins.",
			Arguments: []string{"-config", "C:\\Program Files\\Telegraf\\telegraf.conf"},
		}

		prg := &program{}
		s, err := service.New(prg, svcConfig)
		if err != nil {
			log.Fatal(err)
		}
		logger, err = s.Logger(nil)
		if err != nil {
			log.Fatal(err)
		}
		// Handle the -service flag here to prevent any issues with tooling that may not have an interactive
		// session, e.g. installing from Ansible
		flag.Parse()
		if *fService != "" {
			if *fConfig != "" {
				(*svcConfig).Arguments = []string{"-config", *fConfig}
			}
			err := service.Control(s, *fService)
			if err != nil {
				log.Fatal(err)
			}
		} else {
			err = s.Run()
			if err != nil {
				logger.Error(err)
			}
		}
	} else {
		stop = make(chan struct{})
		reloadLoop(stop, nil)
	}
}
예제 #24
0
func main() {
	svcConfig := &service.Config{
		Name:        "nsqlookupd",
		DisplayName: "nsqlookupd",
		Description: "nsqlookupd 0.3.2",
	}

	prg := &program{}
	s, err := service.New(prg, svcConfig)
	if err != nil {
		log.Fatal(err)
	}
	logger, err = s.Logger(nil)
	if err != nil {
		log.Fatal(err)
	}
	err = s.Run()
	if err != nil {
		logger.Error(err)
	}
}
예제 #25
0
파일: main.go 프로젝트: hanscj1/service
func main() {
	svcConfig := &service.Config{
		Name:        "GoServiceTest",
		DisplayName: "Go Service Test",
		Description: "This is a test Go service.",
	}

	prg := &program{}
	s, err := service.New(prg, svcConfig)
	if err != nil {
		log.Fatal(err)
	}
	logger, err = s.Logger(nil)
	if err != nil {
		log.Fatal(err)
	}
	err = s.Run()
	if err != nil {
		logger.Error(err)
	}
}
예제 #26
0
파일: main.go 프로젝트: onyxhat/pogo
func main() {
	svcConfig := &service.Config{
		Name:        "pogo",
		DisplayName: "PoGo Service",
		Description: "PoGo API Service.",
	}

	prg := &program{}
	s, err := service.New(prg, svcConfig)
	if err != nil {
		log.Fatal(err)
	}
	logger, err := s.Logger(nil)
	if err != nil {
		log.Fatal(err)
	}
	err = s.Run()
	if err != nil {
		logger.Error(err)
	}
}
예제 #27
0
func main() {
	svcConfig := &service.Config{
		Name:        "RTCPProxyServer",
		DisplayName: "逆向TCP代理服务",
		Description: "主要用来处理第三方回调的问题 方便调试",
	}

	prg := &program{}
	s, err := service.New(prg, svcConfig)
	if err != nil {
		KolonseWeb.DefaultLogs().Error(err.Error())
	}
	logger, err := s.Logger(nil)
	if err != nil {
		KolonseWeb.DefaultLogs().Error(err.Error())
	}
	err = s.Run()
	if err != nil {
		logger.Error(err)
	}
}
예제 #28
0
파일: main.go 프로젝트: rdterner/tp
func main() {
	flag.Parse()

	hasFile, err := loadConfig()
	if hasFile == true && err != nil {
		fmt.Println("failed to read config file %q: %v", configFileName, err)
		os.Exit(1)
	}

	sc := &service.Config{
		Name: "tps",
	}
	a := &app{}
	s, err := service.New(a, sc)
	if err != nil {
		fmt.Println("failed to create service: %v", err)
		os.Exit(1)
	}

	log, err = s.Logger(nil)
	if err != nil {
		fmt.Println("error opening logger: %v", err)
		os.Exit(1)
	}
	if len(*action) > 0 {
		err = service.Control(s, *action)
		if err != nil {
			fmt.Printf("Control action %q failed: %v\n", *action, err)
			fmt.Printf("available actions: %q\n", service.ControlAction)
			flag.PrintDefaults()
			os.Exit(2)
		}
		return
	}
	err = s.Run()
	if err != nil {
		log.Errorf("runtime error: %v", err)
	}
}
예제 #29
0
func initService() service.Service {
	svcFlag := flag.String("service", "", "Control the system service.")
	flag.Parse()

	svcConfig := &service.Config{
		Name:        "ipsecdiagtool",
		DisplayName: "A service for IPSecDiagTool",
		Description: "Detects packet loss & periodically reports the MTU for all configured tunnels.",
	}

	prg := &program{}
	s, err := service.New(prg, svcConfig)
	if err != nil {
		log.Fatal(err)
	}
	errs := make(chan error, 5)
	//logger, err = s.Logger(errs)
	if err != nil {
		log.Fatal(err)
	}

	go func() {
		for {
			err := <-errs
			check(err)
		}
	}()

	if len(*svcFlag) != 0 {
		err := service.Control(s, *svcFlag)
		if err != nil {
			log.Printf("Valid actions: %q\n", service.ControlAction)
			log.Fatal(err)
		}
		os.Exit(0)
	}
	return s
}
예제 #30
0
func main() {
	// 处理系统信号
	go signalProc()

	serviceConfig := &service.Config{
		Name:        config.ServiceName,
		DisplayName: config.ServiceDisplayName,
		Description: config.ServiceDescription,
	}

	// 创建服务
	handler := serviceHandler.New()
	serviceObj, err := service.New(handler, serviceConfig)
	if err != nil {
		panic(fmt.Sprintf("创建服务失败:%s", err))
	}

	// 运行服务
	err = serviceObj.Run()
	if err != nil {
		panic(fmt.Sprintf("运行服务失败:%s", err))
	}
}