Example #1
0
func XServiceRemove(zname string) error {
	var ws, err = service.NewService(zname, "", "")
	err = ws.Remove()
	if err != nil {
		return err
	}
	return nil
}
Example #2
0
func XServiceAdd(zname, zdisplyName, zdesc string, onStart, onStop func() error) error {

	var ws, err = service.NewService(zname, zdisplyName, zdesc)

	err = ws.Install()
	if err != nil {
		return err
	}
	err = ws.Run(onStart, onStop)
	if err != nil {
		return err
	}
	return nil
}
Example #3
0
File: a3.go Project: enderlu/vfp
func main() {

	zser_b, _ := vfp.Filetostr(zpath + "service.txt")

	var displayName = "check word from page"
	var desc = "check word from page."
	var ws, err = service.NewService(readStr(zser_b), displayName, desc)

	if err != nil {
		fmt.Printf("%s unable to start: %s", displayName, err)
		return
	}

	if len(os.Args) > 1 {
		var err error
		verb := os.Args[1]
		switch verb {
		case "install":
			err = ws.Install()
			if err != nil {
				fmt.Printf("Failed to install: %s\n", err)
				return
			}
			fmt.Printf("Service \"%s\" installed.\n", displayName)
		case "remove":
			err = ws.Remove()
			if err != nil {
				fmt.Printf("Failed to remove: %s\n", err)
				return
			}
			fmt.Printf("Service \"%s\" removed.\n", displayName)
		}
		return
	}
	err = ws.Run(func() error {
		// start
		go doWork()
		ws.LogInfo("I'm Running!")
		return nil
	}, func() error {
		// stop
		stopWork()
		ws.LogInfo("I'm Stopping!")
		return nil
	})
	if err != nil {
		ws.LogError(err.Error())
	}
}
Example #4
0
func main() {
	var displayName = "Go Service Test2"
	var desc = "This is a test Go service.  It is designed to run well."
	var ws, err = service.NewService("GoServiceTest2", displayName, desc)

	if err != nil {
		fmt.Printf("%s unable to start: %s", displayName, err)
		return
	}

	if len(os.Args) > 1 {
		var err error
		verb := os.Args[1]
		switch verb {
		case "install":
			err = ws.Install()
			if err != nil {
				fmt.Printf("Failed to install: %s\n", err)
				return
			}
			fmt.Printf("Service \"%s\" installed.\n", displayName)
		case "remove":
			err = ws.Remove()
			if err != nil {
				fmt.Printf("Failed to remove: %s\n", err)
				return
			}
			fmt.Printf("Service \"%s\" removed.\n", displayName)
		}
		return
	}
	err = ws.Run(func() error {
		// start
		go doWork()
		ws.LogInfo("I'm Running!")
		return nil
	}, func() error {
		// stop
		stopWork()
		ws.LogInfo("I'm Stopping!")
		return nil
	})
	if err != nil {
		ws.LogError(err.Error())
	}
}