Let’s write liferay startup script by following these steps :
- First, you need to install the sysv-rc-conf in your system. To do so, Open the terminal and go to the following path.
/etc/apt
- Now, Open the “sources.list” file using the following command.
sudo nano sources.list
- And add the following package in the “sources.list” file and save it.
deb http://archive.ubuntu.com/ubuntu/ trusty main universe restricted multiverse
- Now, Install the sysv-rc-conf package by using the following command.
sudo apt-get update -y
sudo apt-get install -y sysv-rc-conf
After successful installation of sysv-rc-conf, please follow these steps.
- Open new terminal and go to path ‘/etc/init.d’
- Create a file by using the following command. ( here liferay-autostart is name file that will be created under directory ‘/etc/init.d’ )
sudo touch liferay-autostart
- Open file by using the following command.
sudo nano liferay-autostart
- Open the above file and add below script into file
// update liferay-autostart
#!/bin/bash
TOMCAT_HOME=${liferay_tomcat_path}/bin
START_TOMCAT=${liferay_tomcat_path}/bin/startup.sh
STOP_TOMCAT=${liferay_tomcat_path}/bin/shutdown.sh
start() {
echo -n "Starting tomcat: "
cd $TOMCAT_HOME
${START_TOMCAT}
echo "done."
}
stop() {
echo -n "Shutting down tomcat: "
cd $TOMCAT_HOME
${STOP_TOMCAT}
echo "done."
}
case "$1" in
start)
sleep 10
start
;;
stop)
stop
;;
restart)
stop
sleep 10
start
;;
*)
echo "Usage: $0 {start|stop|restart}"
esac
exit 0
Note : Replace variable ${liferay_tomcat_path} with actual path of your liferay installation.
Once you add it, the script is ready to run. Execute following commands on file you have created under ‘/etc/init.d’
sudo chmod 755 liferay-autostart
sudo update-rc.d liferay-autostart remove
sudo update-rc.d liferay-autostart defaults
sudo sysv-rc-conf – – list liferay-autostart
- Last command should return the output below.
liferay-autostart 0:off 1:off 2:on 3:on 4:on 5:on 6:off
If you didn’t get the above output ( you have made some mistakes ), please verify steps again.