Liferay

Liferay server autostart script in ubuntu

Jigna Patel
Jigna PatelAug 5, 2022

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.
1/etc/apt
  • Now, Open the “sources.list” file using the following command.
1sudo nano sources.list
  • And add the following package in the “sources.list” file and save it.
1deb http://archive.ubuntu.com/ubuntu/ trusty main universe restricted multiverse
  • Now, Install the sysv-rc-conf package by using the following command.
1sudo apt-get update -y
1sudo 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’ )
1sudo touch liferay-autostart
  • Open file by using the following command.
1sudo nano liferay-autostart
  • Open the above file and add below script into file
1#!/bin/bash 
2TOMCAT_HOME=${liferay_tomcat_path}/bin 
3START_TOMCAT=${liferay_tomcat_path}/bin/startup.sh 
4STOP_TOMCAT=${liferay_tomcat_path}/bin/shutdown.sh 
5 
6start() { 
7 echo -n "Starting tomcat: " 
8 cd $TOMCAT_HOME 
9 ${START_TOMCAT} 
10 echo "done." 
11} 
12 
13stop() { 
14 echo -n "Shutting down tomcat: " 
15 cd $TOMCAT_HOME 
16 ${STOP_TOMCAT} 
17 echo "done." 
18} 
19 
20case "$1" in 
21start) 
22 sleep 10 
23 start 
24 ;;  
25 
26stop) 
27 stop 
28 ;;  
29 
30restart) 
31 stop 
32 sleep 10 
33 start 
34 ;; 
35 *) 
36 
37echo "Usage: $0 {start|stop|restart}" 
38esac 
39exit 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’

1sudo chmod 755 liferay-autostart
2sudo update-rc.d liferay-autostart remove
3sudo update-rc.d liferay-autostart defaults
4sudo sysv-rc-conf - - list liferay-autostart
  • Last command should return the output below.
1liferay-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.


© 2026 IGNEK. All rights reserved.

Ignek on LinkedInIgnek on InstagramIgnek on FacebookIgnek on YouTubeIgnek on X