Sample Tomcat Startup Scripts

I have had many clients ask me if Liferay has management scripts for Apache Tomcat. While Liferay doesn't officially recommend any particular way to start/stop Tomcat, I have found this works really well for me on client sites.

You’ll need to make the script executable by running the chmod command:
sudo chmod 755 /etc/init.d/liferay
The last step is actually linking this script to the startup folders with a symbolic link. Execute these two commands and we should be on our way.
sudo ln -s /etc/init.d/liferay /etc/rc1.d/K99liferay
sudo ln -s /etc/init.d/liferay /etc/rc2.d/S99liferay



Brett, nice meeting you yesterday after your session on clustering. I came to the symposium to get answer on couple of open question regarding licensing and clustering with respect to auto scaling on a cloud environment. I got those from you at the very last technical session of the symposium. I guess no one goes empty handed from the symposium, now quite literally.
Nice script, but if you have more then one instance of tomact running, it will allow only to start one of them, because you grep only for org.apache.catalina.startup.Bootstrap, so you should also grep for the tomcat home dir


Absolutely true. For the client I made this for they were only running one JVM per box. It could and should be improved upon based on your specific needs.
Couple of minor points. Setting the rc symlinks should be done with chkconfig since this script supports it. Not all distros have those symlinks in that place.

Secondly add exit 99 or similar after line 82 - tomcat not running. This script always returns success, puppet wants the exit status to be 'correct'.
Nice, this will replace my simpler version next time. I like to add some "chown -r $TOMCAT_USER $TOMCAT_HOME/work $TOMCAT_HOME/temp $TOMCAT_HOME/logs $TOMCAT_HOME/webapps" (etc) because I was bitten once by someone accidentally starting tomcat as root - this does recover proper ownership at latest with the next startup - otherwise there'd be a bunch of unwritable files left over.
The end of the liferay tomcat process apparently does not automatically mean that all external connections started by the tomcat process are properly shut down yet. We use the said script via cron to force a scheduled ldap import from our AD. (We never got the ldap.import.interval to work, only the initial sync at startup). The restart via the script usually means less than 5 seconds between shutdown and startup and more than often - no initial ldap import.
Great post, thank you.
Just a note: if you run "service liferay stop" from a non-root user, it will prompt a password request to perform the stop operation by "su" mode.
If you type a wrong password you will get a "su: Authentication failure", but process will continue:
"Waiting for processes to exit. Timeout before we kill the pid: 0/45
Waiting for processes to exit. Timeout before we kill the pid: 5/45