0

Is there any way to check if any instance of Echo server is already running so that only one instance of Echo server run at one time.

I have this code

func main() {
    // Echo instance
    e := echo.New()

    // Start server
    e.Logger.Fatal(e.Start(":1323"))
}

and what I am thinking is:

func main() {
    // Echo instance
    if(<<SOME LOGIC TO GET IF ECHO INSTANCE IS RUNNING, OR HOW MANY INSTANCES ARE RUNNING TO ASSIGN NEW INSTANCE ONLY IF INSTANCE PREVIOUS IS 0>>){
        e := echo.New()
    }
    

    // Start server
    e.Logger.Fatal(e.Start(":1323"))
}

I am supposed to replace "<<SOME LOGIC TO GET IF ECHO INSTANCE IS RUNNING, OR HOW MANY INSTANCES ARE RUNNING TO ASSIGN NEW INSTANCE ONLY IF INSTANCE PREVIOUS IS 0>>", Any pointer?

Thor
  • 113
  • 10
  • 1
    By default you can only bind to an address once, so starting multiple process will fail anyway. Even if you were to check, an instance could be started between checking an executing a new one. – JimB Aug 08 '22 at 12:49
  • Yeah.. but that throws Fatal error. "bind: address already in use". I want to handle that too. For that I would need to check if any instance is already running or not. – Thor Aug 08 '22 at 13:05
  • 1
    It throws "Fatal error", because you are calling `Logger.Fatal`. If you want to handle that more gracefully, then handle the error in some other way (what exactly you would do, I don't know, since you need to abort anyway to fix the problem with another process) – JimB Aug 08 '22 at 13:07

0 Answers0