docker-library / tomcat

Docker Official Image packaging for Apache Tomcat
https://tomcat.apache.org
Apache License 2.0
623 stars 746 forks source link

How to restart catarina.sh from inside the container #61

Closed kujiy closed 6 years ago

kujiy commented 7 years ago

It seems that there's no restart option for catalina.sh. I'd like to restart just my tomcat service from inside the container for logrotate, not from the docker host. Unfortunately, I don't have its source so I can't touch the app. Does anybody know how to restart or regenerate its log file?

[root@tc /]# docker exec tomcat /usr/local/tomcat/bin/catalina.sh  
Usage: catalina.sh ( commands ... )
commands:
  debug             Start Catalina in a debugger
  debug -security   Debug Catalina with a security manager
  jpda start        Start Catalina under JPDA debugger
  run               Start Catalina in the current window
  run -security     Start in the current window with security manager
  start             Start Catalina in a separate window
  start -security   Start in a separate window with security manager
  stop              Stop Catalina, waiting up to 5 seconds for the process to end
  stop n            Stop Catalina, waiting up to n seconds for the process to end
  stop -force       Stop Catalina, wait up to 5 seconds and then use kill -KILL if still running
  stop n -force     Stop Catalina, wait up to n seconds and then use kill -KILL if still running
  version           What version of tomcat are you running?
Note: Waiting for the process to end and use of the -force option require that $CATALINA_PID is defined
antoineco commented 7 years ago

@kujiy the usual way to rotate logs on tomcat is simply to truncate the file after creating a copy of it (copytruncate logrotate option). see: tomcat-8.0.logrotate (Fedora package).

Since this is not ideal you could also let log4j rotate the files for you.

kujiy commented 7 years ago

@antoineco Oh my goodness, copytruncate will be the best! I'll try it next week. Thank you!

tianon commented 6 years ago

Closing, since this appears to be resolved. Since catalina.sh is running as PID 1 inside the container, it cannot be restarted without restarting the entire container. Hopefully the copytruncate suggestion works for you!

In the future, these sorts of questions/requests would be more appropriately posted to the Docker Community Forums, the Docker Community Slack, or Stack Overflow.