func (service *Service) Manage(command string) (string, error) {

    // usage := "Usage: myservice install | uninstall | start | stop | status"
		usage := "annoyme [--daemon|-d] install | uninstall | start | stop | status"

    // if received any kind of command, do it
    if command != "run" {
    //     command := os.Args[2]
			switch command {
			case "install":
					return service.Install("--daemon run")
			case "uninstall":
					return service.Remove()
			case "start":
					return service.Start()
			case "stop":
					return service.Stop()
			case "status":
					return service.Status()
			default:
					return usage, nil
			}
    }

    // Do something, call your goroutines, etc

    // Set up channel on which to send signal notifications.
    // We must use a buffered channel or risk missing the signal
    // if we're not ready to receive when the signal is sent.
    interrupt := make(chan os.Signal, 1)
    signal.Notify(interrupt, os.Interrupt, os.Kill, syscall.SIGTERM)

    // Set up listener for defined host and port
    listener, err := net.Listen("tcp", port)
    if err != nil {
        return "Possibly was a problem with the port binding", err
    }

    // set up channel on which to send accepted connections
    listen := make(chan net.Conn, 100)
    go acceptConnection(listener, listen)

    // loop work cycle with accept connections or interrupt
    // by system signal
    for {
        select {
        case conn := <-listen:
            go handleClient(conn)
        case killSignal := <-interrupt:
            stdlog.Println("Got signal:", killSignal)
            stdlog.Println("Stoping listening on ", listener.Addr())
            listener.Close()
            if killSignal == os.Interrupt {
                return "Daemon was interruped by system signal", nil
            }
            return "Daemon was killed", nil
        }
    }

    // never happen, but need to complete code
    return usage, nil
}
// Manage by daemon commands or run the daemon
Manage by daemon commands or run the daemon
// Manage by daemon commands or run the daemon
func (service *Service) Manage(command string) (string, error) {
		usage := "annoyme [--daemon|-d] install | uninstall | start | stop | status"
    if command != "run" {
			switch command {
			case "install":
					return service.Install("--daemon run")
			case "uninstall":
					return service.Remove()
			case "start":
					return service.Start()
			case "stop":
					return service.Stop()
			case "status":
					return service.Status()
			default:
					return usage, nil
			}
    }
    interrupt := make(chan os.Signal, 1)
    signal.Notify(interrupt, os.Interrupt, os.Kill, syscall.SIGTERM)
    listener, err := net.Listen("tcp", port)
    if err != nil {
        return "Possibly was a problem with the port binding", err
    }
    listen := make(chan net.Conn, 100)
    go acceptConnection(listener, listen)
    for {
        select {
        case conn := <-listen:
            go handleClient(conn)
        case killSignal := <-interrupt:
            stdlog.Println("Got signal:", killSignal)
            stdlog.Println("Stoping listening on ", listener.Addr())
            listener.Close()
            if killSignal == os.Interrupt {
                return "Daemon was interruped by system signal", nil
            }
            return "Daemon was killed", nil
        }
    }
    return usage, nil
}
func ( service * Service ) Manage ( command string ) ( string , error ) { usage := " " if command != " " { switch command { case " " : return service . Install ( " " ) case " " : return service . Remove ( ) case " " : return service . Start ( ) case " " : return service . Stop ( ) case " " : return service . Status ( ) default : return usage , nil } } interrupt := make ( chan os . Signal , 1 ) signal . Notify ( interrupt , os . Interrupt , os . Kill , syscall . SIGTERM ) listener , err := net . Listen ( " " , port ) if err != nil { return " " , err } listen := make ( chan net . Conn , 100 ) go acceptConnection ( listener , listen ) for { select { case conn := <- listen : go handleClient ( conn ) case killSignal := <- interrupt : stdlog . Println ( " " , killSignal ) stdlog . Println ( " " , listener . Addr ( ) ) listener . Close ( ) if killSignal == os . Interrupt { return " " , nil } return " " , nil } } return usage , nil }
Manage by daemon commands or run the daemon
Manage by daemon commands or run the daemon
// usage := "Usage: myservice install | uninstall | start | stop | status" // if received any kind of command, do it //     command := os.Args[2] // Do something, call your goroutines, etc // Set up channel on which to send signal notifications. // We must use a buffered channel or risk missing the signal // if we're not ready to receive when the signal is sent. // Set up listener for defined host and port // set up channel on which to send accepted connections // loop work cycle with accept connections or interrupt // by system signal // never happen, but need to complete code