1

I am using apache-tomcat-8.5.15 and starting(startup.sh) & stopping(shutdown.sh) it using the shell scripts contained in its bin/ directory. In my custom shell script file, when I write:

./shutdown.sh
./startup.sh

and run, it seems to work fine. But when I run with

./shutdown.sh && ./startup.sh

it shows

java.net.BindException: Address already in use (Bind failed)

saying that the address is already bound.

Why is this happening? How can I resolve this error?

Or, is there a simple command that can restart tomcat?

codeforester
  • 39,467
  • 16
  • 112
  • 140
viz
  • 1,247
  • 16
  • 27
  • 1
    Either `shutdown.sh` isn't shutting down your instance cleanly or you need to wait for a few seconds before calling `startup.sh`. Try `./shutdown.sh && sleep 5 && ./startup.sh`. – codeforester Jun 02 '17 at 05:26
  • 1
    I guess `shutdown.sh` is somewhat async and continues to do something after returning to the terminal. Just sleep a bit after it finished – SHG Jun 02 '17 at 05:28
  • Thanks guys, I figured out on my own. I'll post my answer in a minute. – viz Jun 02 '17 at 05:36

2 Answers2

0

Why is this happening? How can I resolve this error?

This problem occurs mainly when you try to run your tomcat on a port which is already being used by other application or other process of tomcat itself,

Yes, you can surly resolve this by either just killing or stopping the process which is bind to that port.

Satish Kumar
  • 110
  • 1
  • 11
0

Why is this happening? How can I resolve this error?

It wasn't a issue of whether having && or not. It was just a testing mistake.

It was because

INFO: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [38,251] milliseconds.

This part was eating up almost 40 secs so that when I was testing the script with &&, the shutdown.sh couldn't shut down the tomcat process since it was on its initialization stage.

To fix this, you could set in JAVA_OPT to feed dev/urandom. Refer to this answer & comment for the detailed solution.

In fact, without this problem, it was fine to do either way.


Is there a simple command that can restart tomcat?

Probably not.


Are starup.sh and shutdown.sh run asynchronously?

I don't have a definite answer on this, but according to the code inside scripts(here and here) which is same as in my version of Tomcat, they don't seem to be async. Please correct me if I'm wrong.

Community
  • 1
  • 1
viz
  • 1,247
  • 16
  • 27