當前位置: 首頁>>代碼示例>>Golang>>正文


Golang svc.Run函數代碼示例

本文整理匯總了Golang中golang.org/x/sys/windows/svc.Run函數的典型用法代碼示例。如果您正苦於以下問題:Golang Run函數的具體用法?Golang Run怎麽用?Golang Run使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Run函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: ProcessWindowsControlEvents

// On windows this creates a loop that only finishes when
// a Stop or Shutdown request is received. On non-windows
// platforms, the function does nothing. The stopCallback
// function is called when the Stop/Shutdown request is
// received.
func ProcessWindowsControlEvents(stopCallback func()) {
	err := svc.Run(os.Args[0], &beatService{})
	if err != nil {
		logp.Err("Error: %v", err)
	}
	stopCallback()
}
開發者ID:Esquive,項目名稱:libbeat,代碼行數:12,代碼來源:service_windows.go

示例2: Run

func (ws *windowsService) Run() error {
	ws.setError(nil)
	if !interactive {
		// Return error messages from start and stop routines
		// that get executed in the Execute method.
		// Guarded with a mutex as it may run a different thread
		// (callback from windows).
		runErr := svc.Run(ws.Name, ws)
		startStopErr := ws.getError()
		if startStopErr != nil {
			return startStopErr
		}
		if runErr != nil {
			return runErr
		}
		return nil
	}
	err := ws.i.Start(ws)
	if err != nil {
		return err
	}

	sigChan := make(chan os.Signal)

	signal.Notify(sigChan, os.Interrupt, os.Kill)

	<-sigChan

	return ws.i.Stop(ws)
}
開發者ID:sdhjl2000,項目名稱:service,代碼行數:30,代碼來源:service_windows.go

示例3: main

func main() {
	var logDir = ""
	flag.StringVar(&logDir, "logDir", "", "The directory where the logs will be stored")
	var serviceName = flag.String("serviceName", "mssql_broker", "The name of the service as installed in Windows SCM")

	if !flag.Parsed() {
		flag.Parse()
	}

	interactiveMode, err := svc.IsAnInteractiveSession()
	if err != nil {
		panic(err.Error())
	}

	if interactiveMode {
		runMain(os.Stdout)
	} else {
		var err error

		if logDir == "" {
			//will default to %windir%\System32\
			workingDir, err := os.Getwd()
			if err != nil {
				panic(err.Error())
			}
			logDir = path.Join(workingDir, "logs")
		}
		if _, err := os.Stat(logDir); os.IsNotExist(err) {
			err := os.Mkdir(logDir, 0666)
			if err != nil {
				panic(err.Error())
			}
		}

		logFilePath := path.Join(logDir, "mssql_broker.log")

		logFile, err := os.OpenFile(logFilePath, os.O_WRONLY|os.O_CREATE|os.O_APPEND|os.O_SYNC, 0660)
		if err != nil {
			panic(err.Error())
		}
		defer logFile.Close()

		//setting stderr & stdout
		os.Stdout = logFile
		os.Stderr = logFile

		fileWriter := NewWinFileWriter(logFile)

		ws := WindowsService{
			writer: fileWriter,
		}

		err = svc.Run(*serviceName, &ws)
		if err != nil {
			panic(err.Error())
		}
	}
}
開發者ID:PvanHengel,項目名稱:cf-mssql-broker,代碼行數:58,代碼來源:main_windows.go

示例4: initService

func initService(daemonCli *DaemonCli) (bool, error) {
	if *flUnregisterService {
		if *flRegisterService {
			return true, errors.New("--register-service and --unregister-service cannot be used together")
		}
		return true, unregisterService()
	}

	if *flRegisterService {
		return true, registerService()
	}

	if !*flRunService {
		return false, nil
	}

	interactive, err := svc.IsAnInteractiveSession()
	if err != nil {
		return false, err
	}

	h := &handler{
		tosvc:     make(chan bool),
		fromsvc:   make(chan error),
		daemonCli: daemonCli,
	}

	var log *eventlog.Log
	if !interactive {
		log, err = eventlog.Open(*flServiceName)
		if err != nil {
			return false, err
		}
	}

	logrus.AddHook(&etwHook{log})
	logrus.SetOutput(ioutil.Discard)

	service = h
	go func() {
		if interactive {
			err = debug.Run(*flServiceName, h)
		} else {
			err = svc.Run(*flServiceName, h)
		}

		h.fromsvc <- err
	}()

	// Wait for the first signal from the service handler.
	err = <-h.fromsvc
	if err != nil {
		return false, err
	}
	return false, nil
}
開發者ID:SUSE,項目名稱:docker.mirror,代碼行數:56,代碼來源:service_windows.go

示例5: Run

func Run() error {
	log.Infof("starting %s service", serviceName)

	err := svc.Run(serviceName, &myservice{})
	if err != nil {
		log.Infof("%s service failed: %v", serviceName, err)
		return err
	}
	log.Infof("service stopped")
	return nil
}
開發者ID:Nanocloud,項目名稱:community,代碼行數:11,代碼來源:service.go

示例6: runService

func runService(name string, isDebug bool) {
	var err error

	log.Printf("starting %s service\n", name)
	err = svc.Run(name, &tetherservice{})
	if err != nil {
		log.Printf("%s service failed: %v\n", name, err)
		return
	}
	log.Printf("%s service stopped\n", name)
}
開發者ID:jak-atx,項目名稱:vic,代碼行數:11,代碼來源:service_windows.go

示例7: Exec

// If the application is running in an interactive session, run until
// terminated. Otherwise, run the application as a Windows service.
func Exec() error {
	isInteractive, err := svc.IsAnInteractiveSession()
	if err != nil {
		return err
	}
	if !isInteractive {
		return svc.Run(ServiceName, &service{})
	} else {
		execSignal()
		return nil
	}
}
開發者ID:hectane,項目名稱:hectane,代碼行數:14,代碼來源:exec_windows.go

示例8: Run

func (ws *windowsService) Run(onStart, onStop func() error) error {
	elog, err := eventlog.Open(ws.name)
	if err != nil {
		return err
	}
	defer elog.Close()

	ws.logger = elog

	ws.onStart = onStart
	ws.onStop = onStop
	return svc.Run(ws.name, ws)
}
開發者ID:ZhuHangpeng,項目名稱:mig,代碼行數:13,代碼來源:service_windows.go

示例9: runService

func runService(context *cli.Context) error {
	interactive, err := svc.IsAnInteractiveSession()
	if err != nil {
		return fmt.Errorf("Failed to detect interactive session: %s", err)
	}

	s := service{context, interactive}

	if interactive {
		return debug.Run(lib.ConnectorName, &s)
	} else {
		return svc.Run(lib.ConnectorName, &s)
	}
}
開發者ID:jacobmarble,項目名稱:cloud-print-connector,代碼行數:14,代碼來源:gcp-windows-connector.go

示例10: runAsService

func runAsService(name string) {
	elog, err := eventlog.Open(name)
	if err != nil {
		return
	}
	defer elog.Close()

	elog.Info(1, fmt.Sprintf("etcd: starting %s service", name))
	if err = svc.Run(name, &etcdService{elog: elog}); err != nil {
		elog.Error(1, fmt.Sprintf("etcd: %s service failed: %v", name, err))
		return
	}
	elog.Info(1, fmt.Sprintf("etcd: %s service stopped", name))
}
開發者ID:chai2010,項目名稱:etcd,代碼行數:14,代碼來源:main_windows.go

示例11: main

func main() {
	elog, err := eventlog.Open(name)
	if err != nil {
		log.Fatal(err.Error())
	}
	defer elog.Close()

	// `svc.Run` blocks until windows service will stopped.
	// ref. https://msdn.microsoft.com/library/cc429362.aspx
	err = svc.Run(name, &handler{elog: elog})
	if err != nil {
		log.Fatal(err.Error())
	}
}
開發者ID:y-kuno,項目名稱:mackerel-agent,代碼行數:14,代碼來源:wrapper_windows.go

示例12: RunService

func RunService(context *cli.Context) {
	interactive, err := svc.IsAnInteractiveSession()
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed to detect interactive session: %s\n", err)
		os.Exit(1)
	}

	s := service{context, interactive}

	if interactive {
		debug.Run(lib.ConnectorName, &s)
	} else {
		svc.Run(lib.ConnectorName, &s)
	}
}
開發者ID:agoode,項目名稱:cloud-print-connector,代碼行數:15,代碼來源:gcp-windows-connector.go

示例13: HandleService

func HandleService() chan int {
	res := make(chan int)
	go func() {
		isIntSess, err := svc.IsAnInteractiveSession()
		if err != nil {
			log.Fatalf("failed to determine if we are running in an interactive session: %v", err)
		}
		if !isIntSess {
			log.Println("runService(svcName, false)")
			svc.Run("Concordis", &myservice{res})
		} else {
			log.Println("A standard consle session")
		}
	}()
	return res
}
開發者ID:HeinOldewage,項目名稱:Hyades,代碼行數:16,代碼來源:service_windows.go

示例14: RunAsService

// Returns true if we detected that we are not running in a non-interactive session, and so
// launched the service. This function will not return until the service exits.
func RunAsService(handler func()) bool {
	interactive, err := svc.IsAnInteractiveSession()
	if err != nil {
		log.Fatalf("failed to determine if we are running in an interactive session: %v", err)
		return false
	}
	if interactive {
		return false
	}

	serviceName := "" // this doesn't matter when we are a "single-process" service
	service := &myservice{
		handler: handler,
	}
	svc.Run(serviceName, service)
	return true
}
開發者ID:IMQS,項目名稱:logscraper,代碼行數:19,代碼來源:service_windows.go

示例15: init

func init() {
	interactive, err := svc.IsAnInteractiveSession()
	if err != nil {
		panic(err)
	}
	if interactive {
		return
	}
	go func() {
		_ = svc.Run("", runner{})

		guard.Lock()
		f := onExit
		guard.Unlock()

		// Don't hold this lock in user code.
		if f != nil {
			f()
		}
		// Make sure we exit.
		os.Exit(0)
	}()
}
開發者ID:goist,項目名稱:minwinsvc,代碼行數:23,代碼來源:svc_windows.go


注:本文中的golang.org/x/sys/windows/svc.Run函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。