Example #1
0
func (m *myservice) Execute(args []string, r <-chan svc.ChangeRequest, changes chan<- svc.Status) (ssec bool, errno uint32) {
	log.Info("Executing service")
	const cmdsAccepted = svc.AcceptStop | svc.AcceptShutdown
	changes <- svc.Status{State: svc.StartPending}

	go router.Start()

	changes <- svc.Status{State: svc.Running, Accepts: cmdsAccepted}
loop:
	for {
		c := <-r
		switch c.Cmd {
		case svc.Interrogate:
			changes <- c.CurrentStatus
			// Testing deadlock from https://code.google.com/p/winsvc/issues/detail?id=4
			time.Sleep(100 * time.Millisecond)
			changes <- c.CurrentStatus
		case svc.Stop, svc.Shutdown:
			break loop
		default:
			log.Error("unexpected control request #%d", c)
		}
	}
	changes <- svc.Status{State: svc.StopPending}
	return
}
Example #2
0
// main is the main function of plaza.
// plaza takes only one argument that determines in which mode plaza should be
// launched:
//  - install: This will copy plaza to the right plaza (C:\Windows\plaza.exe),
//             create the Windows service for plaza and start it.
//  - service: This will launch plaza as a Windows service. It should only be
//             called by the Windows service manager; never directly.
//  - server: This will launch the plaza server normaly launched in the process.
//            This option exists mainly for test purposes.
//  - shell: This will launch plaza in shell mode. It should only be called by
//           plaza itself.
// If launched without argument, we asume Windows launched plaza as the shell
// application of the session. The shell application of a sessions, is the
// application launched when the user logon to his Windows session. Usually it's
// `C:\Windows\explorer.exe`. This value is set in the registry at:
// `SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\Shell`.
// If so, plaza will just execute itself in shell mode in a detached process
// and exit. This; in order to hide the console windows created by Windows for
// the shell application.
func main() {
	if len(os.Args) > 1 {
		var err error

		switch os.Args[1] {

		case "install":
			initPlatform()
			logrus.Info("(re)Installing service")
			err = service.InstallItSelf()

		case "service":
			initPlatform()
			err = service.Run()

		case "server":
			initPlatform()
			router.Start()

		case "shell":
			sendShellInfo()

			c := make(chan os.Signal, 1)
			signal.Notify(c)
			<-c
			return
		default:
			err = fmt.Errorf("Invalid action %s. Must be \"install\" or \"service\".", os.Args[1])
		}

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

	{
		cmd := exec.Command(`C:\Windows\plaza.exe`, "shell")
		detachedProcess := uint32(0x00000008)
		cmd.SysProcAttr = &syscall.SysProcAttr{
			HideWindow:    true,
			CreationFlags: syscall.CREATE_NEW_PROCESS_GROUP | detachedProcess,
		}

		err := cmd.Start()
		if err != nil {
			logrus.Error(err)
		}
	}
}
Example #3
0
func LaunchAll() {
	go router.Start()
	ProvisionAll()
}
Example #4
0
func main() {
	router.Start()
}