Example #1
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 #2
0
func main() {
	if len(os.Args) < 2 || os.Args[1] != "service" {
		log.Println("(re)Installing service")
		err := service.InstallItSelf()
		if err != nil {
			log.Println(err)
		}
		return
	}
	err := service.Run()
	if err != nil {
		log.Println(err)
	}
}
Example #3
0
func main() {
	if len(os.Args) < 2 || os.Args[1] != "service" {
		logrus.Info("(re)Installing service")
		err := service.InstallItSelf()
		if err != nil {
			logrus.Error(err)
		}
		return
	}

	if debug {
		out, err := os.OpenFile(`C:\plaza.log`, os.O_WRONLY|os.O_CREATE, 0644)
		if err == nil {
			defer out.Close()
			log.SetOutput(out)
			logrus.SetOutput(out)
		}
	}

	err := service.Run()
	if err != nil {
		logrus.Error(err)
	}
}