Running Liferay as a Service
Running Liferay as a Service
How to run Liferay as a Service and make it auto-started on system reboot
Introduction
Sometimes servers hosting Liferay can be restarted. For a higher availability of the Liferay portal we need to make sure that Liferay is also started automatically during the system start. To achieve this - Liferay can be run as a service configured to auto-start.
Configuration
Define Liferay Service Configuration File
To define a service for Liferay - create a liferay.service file inside /usr/lib/systemd/system directory as root user:
sudo su
cd /usr/lib/systemd/system
touch liferay.service
nano liferay.service
with the following content:
[Unit]
Description=Liferay Service
After=network.target
[Service]
Type=forking
User=user
Group=user
Environment=JAVA_HOME=[JAVA_HOME]
Environment=CATALINA_PID=[LIFERAY-PATH]/tomcat[-x.x.x]/temp/tomcat.pid
Environment=CATALINA_HOME=[LIFERAY-PATH]/tomcat[-x.x.x]
Environment=CATALINA_BASE=[LIFERAY-PATH]/tomcat[-x.x.x]
Environment=CATALINA_TMPDIR=[LIFERAY-PATH]/tomcat[-x.x.x]/temp
Environment='CATALINA_OPTS=-Dfile.encoding=UTF-8 -Djava.locale.providers=JRE,COMPAT,CLDR -Djava.net.preferIPv4Stack=true -Duser.timezone=GMT -Xms8g -Xmx8g -XX:MaxNewSize=2g -XX:MaxMetaspaceSize=1g -XX:MetaspaceSize=1g -XX:NewSize=2g -XX:SurvivorRatio=16 -XX:InitialCodeCacheSize=64m -XX:ReservedCodeCacheSize=96m -XX:TargetSurvivorRatio=50 -XX:MaxTenuringThreshold=15'
ExecStart=/bin/bash [LIFERAY-PATH]/tomcat[-x.x.x]/bin/startup.sh
ExecStop=/bin/bash [LIFERAY-PATH]/tomcat[-x.x.x]/bin/shutdown.sh
[Install]
WantedBy=multi-user.target
Specify Java Home [JAVA_HOME] and Liferay path [LIFERAY-PATH].
Define the user and group under which the service should be started.
Note: the WantedBy=multi-user.target directive inside [Install] sections makes the service auto-started on reboot
Enable Liferay Service
Reload the systemd daemons to pick up the new service file:
sudo systemctl daemon-reload
Run the following command to enabled the service:
sudo systemctl enable liferay.service
Run Liferay Service
Run the following command to start the Liferay Service:
sudo systemctl start liferay.service
Restart the system to make sure service is started properly:
sudo reboot
Enjoy 😏
Comments
Post a Comment