• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang svc.IsAnInteractiveSession函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中golang.org/x/sys/windows/svc.IsAnInteractiveSession函数的典型用法代码示例。如果您正苦于以下问题:Golang IsAnInteractiveSession函数的具体用法?Golang IsAnInteractiveSession怎么用?Golang IsAnInteractiveSession使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了IsAnInteractiveSession函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: IsAnInteractiveSession

func IsAnInteractiveSession() bool {
	isIntSess, err := svc.IsAnInteractiveSession()
	if err != nil {
		log.Fatalf("winsvc.InServiceMode: svc.IsAnInteractiveSession(): err = %v", err)
	}
	return isIntSess
}
开发者ID:chai2010,项目名称:winsvc,代码行数:7,代码来源:service.go


示例2: init

func init() {
	var err error
	interactive, err = svc.IsAnInteractiveSession()
	if err != nil {
		panic(err)
	}
}
开发者ID:sdhjl2000,项目名称:service,代码行数:7,代码来源:service_windows.go


示例3: win_service_main

func win_service_main() {
	const svcName = "scollector"
	var err error
	switch *win_service_command {
	case "install":
		err = installService(svcName, "Stack Exchange's Metric Collection Agent")
	case "remove":
		err = removeService(svcName)
	case "start":
		err = startService(svcName)
	case "stop":
		err = controlService(svcName, svc.Stop, svc.Stopped)
	case "":
		isIntSess, err := svc.IsAnInteractiveSession()
		if err != nil {
			slog.Fatalf("failed to determine if we are running in an interactive session: %v", err)
		}
		if !isIntSess {
			go runService(svcName, false)
		}
		return
	default:
		slog.Fatalf("unknown winsvc command: %v", *win_service_command)
	}
	if err != nil {
		slog.Fatalf("failed to %s %s: %v", *win_service_command, svcName, err)
	}
	os.Exit(0)
}
开发者ID:noblehng,项目名称:bosun,代码行数:29,代码来源:service_windows.go


示例4: 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


示例5: 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


示例6: 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


示例7: NewWindowsService

func NewWindowsService(i WindowsServiceInterface, c *WindowsServiceConfig) (Service, error) {
	var err error

	interactive, err = svc.IsAnInteractiveSession()
	if err != nil {
		return nil, err
	}
	ws := &windowsService{
		i:      i,
		Config: c,
	}
	return ws, nil
}
开发者ID:judwhite,项目名称:go-github-check,代码行数:13,代码来源:service.go


示例8: 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


示例9: 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


示例10: platformInit

func platformInit(config *Config) error {
	isInteractive, err := svc.IsAnInteractiveSession()
	if err != nil {
		return err
	}
	if !isInteractive {
		h, err := newEventLogHook()
		if err != nil {
			return err
		}
		hook = h
		logrus.AddHook(hook)
	}
	return nil
}
开发者ID:hectane,项目名称:hectane,代码行数:15,代码来源:log_windows.go


示例11: main

func main() {
	if len(os.Args) < 2 {
		runApp()
		return
	}
	const svcName = "DirectPrintServer"

	isIntSess, err := svc.IsAnInteractiveSession()
	if err != nil {
		log.Fatalf("failed to determine if we are running in an interactive session: %v", err)
	}
	if !isIntSess {
		runService(svcName, false)
		return
	}

	if len(os.Args) < 2 {
		usage("no command specified")
	}

	cmd := strings.ToLower(os.Args[1])
	switch cmd {
	case "debug":
		runService(svcName, true)
		return
	case "start":
		runApp()
		return
	case "install_s":
		err = installService(svcName, "Direct Print Server")
	case "remove_s":
		err = removeService(svcName)
	case "start_s":
		err = startService(svcName)
	case "stop_s":
		err = controlService(svcName, svc.Stop, svc.Stopped)
	case "pause_s":
		err = controlService(svcName, svc.Pause, svc.Paused)
	case "continue_s":
		err = controlService(svcName, svc.Continue, svc.Running)
	default:
		usage(fmt.Sprintf("invalid command %s", cmd))
	}
	if err != nil {
		log.Fatalf("failed to %s %s: %v", cmd, svcName, err)
	}
	return
}
开发者ID:procks,项目名称:direct_print_server,代码行数:48,代码来源:main.go


示例12: main

func main() {
	isIntSess, err := svc.IsAnInteractiveSession()
	if err != nil {
		log.Fatalf("etcd: failed to determine if we are running in an interactive session: %v", err)
	}
	if !isIntSess {
		svcName := filepath.Base(os.Args[0])
		if strings.HasSuffix(strings.ToLower(svcName), ".exe") {
			svcName = svcName[:len(svcName)-len(".exe")]
		}
		runAsService(svcName)
		return
	}

	etcdmain.Main()
}
开发者ID:chai2010,项目名称:etcd,代码行数:16,代码来源:main_windows.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: 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()) {
	isInteractive, err := svc.IsAnInteractiveSession()
	if err != nil {
		logp.Err("IsAnInteractiveSession: %v", err)
		return
	}
	logp.Debug("service", "Windows is interactive: %v", isInteractive)

	run := svc.Run
	if isInteractive {
		run = debug.Run
	}
	err = run(os.Args[0], &beatService{})
	if err != nil {
		logp.Err("Error: %v", err)
	} else {
		stopCallback()
	}
}
开发者ID:hmalphettes,项目名称:dockerbeat,代码行数:24,代码来源:service_windows.go


示例16: 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


示例17: main

func main() {
	// initialize logger
	log := logger.Logger()
	defer log.Close()
	defer log.Flush()

	// parse input parameters
	parseFlags(log)

	// check whether this is an interactive session
	isIntSess, err := svc.IsAnInteractiveSession()
	if err != nil {
		log.Warnf("Failed to determine if we are running in an interactive session: %v", err)
	}

	// isIntSess is false by default (after declaration), this fits the use
	// case that agent is running as Windows service most of times
	switch isIntSess {
	case true:
		run(log)
	case false:
		svc.Run(serviceName, &amazonSSMAgentService{log: log})
	}
}
开发者ID:aws,项目名称:amazon-ssm-agent,代码行数:24,代码来源:agent_windows.go


示例18: main

func main() {
	flag.Usage = usage
	flag.Parse()

	playEnabled = *flagShowPlayground

	if *flagServiceInstall {
		var args []string
		args = append(args, fmt.Sprintf("-goroot=%s", *flagGoroot))
		for i := 1; i < len(os.Args); i++ {
			if strings.HasPrefix(os.Args[i], "-service-install") {
				continue
			}
			if strings.HasPrefix(os.Args[i], "-goroot") {
				continue
			}
			args = append(args, os.Args[i])
		}
		if *flagHttpAddr == "" {
			args = append(args, "-http=:6060")
		}
		if err := installService(ServiceName, ServiceDesc, args...); err != nil {
			log.Fatalf("installService(%s, %s): %v", ServiceName, ServiceDesc, err)
		}
		fmt.Printf("Done\n")
		return
	}
	if *flagServiceUninstall {
		if err := removeService(ServiceName); err != nil {
			log.Fatalf("removeService: %v\n", err)
		}
		fmt.Printf("Done\n")
		return
	}
	if *flagServiceStart {
		if err := startService(ServiceName); err != nil {
			log.Fatalf("startService: %v\n", err)
		}
		fmt.Printf("Done\n")
		return
	}
	if *flagServiceStop {
		if err := controlService(ServiceName, svc.Stop, svc.Stopped); err != nil {
			log.Fatalf("stopService: %v\n", err)
		}
		fmt.Printf("Done\n")
		return
	}

	// Check usage: either server and no args, command line and args, or index creation mode
	if (*flagHttpAddr != "" || *flagUrlFlag != "") != (flag.NArg() == 0) && !*flagWriteIndex {
		usage()
	}

	// run as service
	if isIntSess, err := svc.IsAnInteractiveSession(); err == nil && !isIntSess {
		runService(ServiceName)
		return
	}

	runGodoc()
}
开发者ID:iolg,项目名称:golangdoc,代码行数:62,代码来源:main_windows.go



注:本文中的golang.org/x/sys/windows/svc.IsAnInteractiveSession函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang svc.Run函数代码示例发布时间:2022-05-28
下一篇:
Golang registry.Key类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap