Here’s a bash kill liferay script!
This should kill any running liferay or liferay social office on a linux system.
Open up your favorite editor and paste this in
#!/bin/bash # #Script name: kill_liferay.sh # #Purpose: To kill any running instance of liferay on a linux system # #Usage: ./kill_liferay.sh # for pid in `ps aux | grep java | grep liferay | grep tomcat | awk '{print $2}'` do echo "Liferay is running with pid $pid ..." kill $pid if ! kill $pid > /dev/null 2>&1; then echo "Could not send SIGTERM to process $pid .. trying kill -9" >&2 if ! kill -9 $pid > /dev/null 2>&1; then echo "Unable to kill $pid with kill -9" else echo "Successfully killed Liferay with PID $pid!" fi else echo "Successfully killed Liferay with PID $pid!" fi done
Save the file something like kill_liferay.sh
Next you’ll need to:
# chmod +x kill_liferay.sh
When to kill liferay?
When it is not responding. Here is a nice script to detect just that!
Note the /etc/init.d/liferay script is using the kill liferay script amongst other things!
#!/bin/bash # # /usr/local/bin/liferay.cron.sh if curl -I -L http://localhost:8080 | grep "Liferay Portal" > /dev/null; then echo "Liferay is up" > /dev/null else /etc/init.d/liferay restart fi
/etc/init.d/liferay
#!/bin/bash ####################### # # init.d script to start/stop the liferay tomcat # instance # # ticket #111216-06715 # ####################### # chkconfig: 2345 80 05 # description: Liferay Tomcat services. PATHTOCATALINA="/home/liferay/liferay-social-office-1.5b/tomcat-6.0.18/bin/" START="/bin/sh startup.sh" STOP="/bin/sh shutdown.sh" STOPKILL="/bin/sh kill_liferay.sh" DEBUGLOG="/home/liferay/debug.log" function help { echo "Usage:" echo " liferay [ start|stop|restart|kill ]" echo " start - start the server" echo " stop - stop the server" echo " restart - stop then start the server" echo " kill - stop the server hard" exit 0 } function killliferay { echo -n "killling liferay" cd ${PATHTOCATALINA} ${STOPKILL} } function startliferay { /bin/su - liferay -c "cd ${PATHTOCATALINA};${START}" } function stopliferay { /bin/su - liferay -c "cd ${PATHTOCATALINA};${STOP}" sleep 15 if [ "$(ps aux | grep java | grep liferay | grep tomcat | awk '{print $2}')" ]; then killliferay fi } function restartliferay { stopliferay sleep 10 startliferay } case ${1} in start) startliferay exit 0 ;; stop) stopliferay exit 0 ;; restart) restartliferay exit 0 ;; kill) killliferay exit 0 ;; esac
[…] a handy script to.. ahem.. kill Liferay processes on unix-based systems. Hopefully you don't need this too often […]