Creato da pastuweb.com
Share My Page
My Social Accounts
Account FaceBook Account LinkedIn Account Twitter Account Google Plus Account Git Hub

First of all, you have to create a sh script in /etc/init.d:

cd /etc/init.d

sudo nano tomcat7

and then paste this rows:

#!/bin/sh
 
# Tomcat7 con LIFERAY 6.1 auto-start
#
# description: Auto-starts tomcat
# processname: tomcat
# pidfile: /var/run/tomcat.pid
 
case $1 in
start)
sh /home/portaleLiferay/liferay-portal-6.1.2-ce-ga3/tomcat-7.0.40/bin/startup.sh
python /home/portaleLiferay/liferay-portal-6.1.2-ce-ga3/send_email.py  STARTUP
;;
stop)
sh /home/portaleLiferay/liferay-portal-6.1.2-ce-ga3/tomcat-7.0.40/bin/shutdown.sh
python /home/portaleLiferay/liferay-portal-6.1.2-ce-ga3/send_email.py STOP
;;
restart)
sh /home/portaleLiferay/liferay-portal-6.1.2-ce-ga3/tomcat-7.0.40/bin/shutdown.sh
sh /home/portaleLiferay/liferay-portal-6.1.2-ce-ga3/tomcat-7.0.40/bin/startup.sh
python /home/portaleLiferay/liferay-portal-6.1.2-ce-ga3/send_email.py RESTART
;;
esac
 
exit 0
 
Then save file and execute this commands:
sudo update-rc.d tomcat7 defaults
sudo chmod 755 /home/portaleLiferay/liferay-portal-6.1.2-ce-ga3/tomcat-7.0.40/bin/startup.sh
sudo chmod 755 /home/portaleLiferay/liferay-portal-6.1.2-ce-ga3/tomcat-7.0.40/bin/shutdown.sh
 
Allright, then you have to create a Python script to send mail:
 
cd /home/portaleLiferay/liferay-portal-6.1.2-ce-ga3
sudo nano send_email.py
 
#!/usr/bin/python

import smtplib
import sys

sender = 'info@appuntivari.net'
receivers = ['francesco.pasturenzi@gmail.com']
text = "Application Server AppuntiVari.net in "+sys.argv[1]+" wait 5-10 minutes"


message = """\
From: %s
To: %s
Subject: %s

%s
""" % (sender, ", ".join(receivers), "AppuntiVari.net machine info", text)

smtpObj = smtplib.SMTP('mailhost.domain.it', 25)
smtpObj.sendmail(sender, receivers, message)
print "Email sended with SUCCESS."
 
If you have issues (for instance: permission or syntax error about redirection)

Issue about Syntax errore or redirection: you have to override #!/bin/sh with #!/bin/bash

Issue about permission: you have to use sudo -S <<< "password" command, for instance:

sh /home/portaleLiferay/liferay-portal-6.1.2-ce-ga3/tomcat-7.0.40/bin/startup.sh

to

sudo -S <<< "password_sudo" sh /home/portaleLiferay/liferay-portal-6.1.2-ce-ga3/tomcat-7.0.40/bin/startup.sh

Another importa thing is you have to use alway ABSOLUTE PATH.