Saturday, December 18, 2021

How to change Grails App server port in application.yml

This is a quick tutorial on how to set server port while running grails application. By default, grails will use the embedded tomcat server running on port 8080.

Sometimes if another process is using port 8080 then we might get a port address already in use error.

So, what we will do is to change the default port in the config. In grails 3.x version we can set up the custom port inside application.yml file.

Inside application.yml file lets add the following config setup to override the default port 8080.
    port : "8090"
Now if we run the application, it will run on port 8090. 

If we want to configure the setup within the environment then we can do as below:
            port : "8090"
This will set the server port only for the development environment. Re-run the application.

Thursday, December 9, 2021

How to resolve port already in use or kill the running process

 On Linux:

step1: if the process is running at port 3000 then, firstly we have to kill this process for this open your terminal and type

lsof -w -n -i tcp:3000

which shows all the list of open file which is running at port 3000. Here, lsof stands for ls = list and of = opened file. You can see list with pid number.

step2: type sudo kill -9 6911 where 6911 is pid number. Here 9 has its own meaning which is defined as kill command "SIGKILL" you can see this by typing in the terminal as kill -l . You can use -SIGKILL instead of -9.

On Windows:

Open and run command prompt as administrator and type the following command:
   netstat -ano | findstr :8080

This command will find and list the process that uses this port 8080.

Now, we need to kill the process, for this use following command:

   taskkill /pid 5884 /f

Where 5884 is the PID number. Use the process PID number obtained previously.