« Back

Sample Tomcat Startup Scripts

General Blogs October 22, 2013 By Brett Swaim Staff

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

 

 

Threaded Replies Author Date
Brett, nice meeting you yesterday after your... Prasanta Bhuyan October 23, 2013 12:45 PM
Glad to be of service! Brett Swaim November 18, 2013 9:26 AM
Nice script, but if you have more then one... Daniel Nordhoff-Vergien December 19, 2013 2:24 AM
Absolutely true. For the client I made this for... Brett Swaim December 19, 2013 4:18 PM
Couple of minor points. Setting the rc symlinks... Kevin Thorpe June 30, 2014 4:22 AM
Nice, this will replace my simpler version next... Olaf Kock August 13, 2014 3:40 AM
The end of the liferay tomcat process... Akke Bengtsson February 16, 2015 1:14 AM
Great post, thank you. Just a note: if you run... Pierpaolo Cira May 6, 2015 3:18 AM
Great post with a good example of start/stop... ser aus August 11, 2015 4:56 AM

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.
Posted on 10/23/13 12:45 PM.
Glad to be of service!
Posted on 11/18/13 9:26 AM in reply to Prasanta Bhuyan.
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

Regards

Daniel
Posted on 12/19/13 2:24 AM.
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.
Posted on 12/19/13 4:18 PM in reply to Daniel Nordhoff-Vergien.
Kevin Thorpe
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'.
Posted on 6/30/14 4:22 AM.
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.
Posted on 8/13/14 3:40 AM.
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.
Posted on 2/16/15 1:14 AM.
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
..."
Posted on 5/6/15 3:18 AM.
Great post with a good example of start/stop script for tomcat

Thanks!
Posted on 8/11/15 4:56 AM in reply to Pierpaolo Cira.