Installing AEM as a service — LINUX/CentOS 7.x

Singaiah Chintalapudi
3 min readMay 22, 2020

--

I think most of the AEM customers are running their AEM prod servers on the cloud managed by AMS. So, you most likely to use CentOS for your on-premise DEV/pre-prod servers. Therefore, this article will help you to setup the AEM on CentOS 7.x.

I. Before you start:

a. Make sure the java is installed and environment variables are set

b. You’ve a root access to the CentOS VM

II. Installing AEM:

  1. Copy the aem-jar/license files to: /mnt/crx/author (if you’re setting publish then copy the jar to: /mnt/crx/publish). Make sure you re-name the jar i.e. for author: aem-author-p4502.jar; for publish: aem-publish-p4503.jar
  2. For publish server setup: Shutdown the server and change the default port 4502 to 4503 on /mnt/crx/publish/crx-quickstart/bin/start. So, this will help to start the publish server on port 4503 when you start the server using these scripts under /mnt/crx/publish/crx-quickstart/bin folder.

III. Init script to start/stop/restart the AEM servers:

  1. Copy the below init script to aem and save this file under: /usr/bin/ location. So the final script location should be: /usr/bin/aem

Note: Check for the AEM_ROOT path. This should be parent folder of crx-quickstart folder.

#!/bin/bash

#

# /etc/rc.d/init.d/aem6

#

#

# # of the file to the end of the tags section must begin with a #

# character. After the tags section, there should be a blank line.

# This keeps normal comments in the rest of the file from being

# mistaken for tags, should they happen to fit the pattern.>

#

# chkconfig: 35 85 15

# description: This service manages the Adobe Experience Manager java process.

# processname: aem6

# pidfile: ${AEM_ROOT}/crx-quickstart/conf/cq.pid

# Source function library.

. /etc/rc.d/init.d/functions

SCRIPT_NAME=`basename $0`

AEM_ROOT=/mnt/crx/author

AEM_USER=aem

########

BIN=${AEM_ROOT}/crx-quickstart/bin

START=${BIN}/start

STOP=${BIN}/stop

STATUS=”${BIN}/status”

case “$1” in

start)

echo -n “Starting AEM services: “

su — ${AEM_USER} ${START}

touch /var/lock/subsys/$SCRIPT_NAME

;;

stop)

echo -n “Shutting down AEM services: “

su — ${AEM_USER} ${STOP}

rm -f /var/lock/subsys/$SCRIPT_NAME

;;

status)

su — ${AEM_USER} ${STATUS}

;;

restart)

su — ${AEM_USER} ${STOP}

su — ${AEM_USER} ${START}

;;

reload)

;;

*)

echo “Usage: $SCRIPT_NAME {start|stop|status|reload}”

exit 1

;;

esac

2. Run the below command:

chmod 755 /usr/bin/aem

3. When you execute the above script, the system user in the script i.e. aem will start/stop/restart the aem server. So, we need to create the system user.

a. Create the system user aem:

sudo add user aem

b. Removing password for the above user:

sudo passwd -d aem

c. Make the above user as a part of sudoers:

sudo usermod -aG wheel aem

d. Provision full permissions to the crx-quickstart folder for the user: aem just in-case if sudo doesn’t work:

sudo chown aem:root /mnt/crx/author

Note: Change the path if you’re working on publish server

4. Now, you should be able to start/stop/restart and get the status of AEM server using the above script (execute below commands in terminal):

Start the AEM server: /usr/bin/aem start

Stop the AEM server: /usr/bin/aem stop

Restart the AEM server: /usr/bin/aem restart

Status of the AEM server: /usr/bin/aem status

IV. AEM as Service

You can start/stop/restart the AEM server using the above script. But it is important to start the server upon system re-boot. For this, you’ll need to set a new service.

  1. Create a new file (aem.service)under: /etc/systemd/system

touch aem.service

2. Edit the file and copy the below script into this file:

[Unit]

Description=AEM Author Server

[Service]

Type=simpleExecStart=/usr/bin/aem start

ExecStop=/usr/bin/aem stop

ExecReload=/usr/bin/aem

restartRemainAfterExit=yes

[Install]

WantedBy=multi-user.target

3. Provide the permissions:

chmod 755 aem.service

4. Reload the system daemon:

systemctl daemon-reload

5. Enable the service to start on boot:

systemctl enable aem.service

6. Re-boot your machine (CentOS box):

reboot

V. Using aem.service to start/stop/restart:

Now, you can use aem.service to start/stop/restart the AEM server instead of the actual AEM script: /usr/bin/aem (see point 4 in Section III).

Start the AEM server: systemctl start aem.service

Stop the AEM server: systemctl stop aem.service

Restart the AEM server: systemctl restart aem.service

Status of the AEM server: systemctl status aem.service

VI. References:

https://helpx.adobe.com/experience-manager/kb/linux-init-script.html

https://github.com/ksurendra/aem-as-a-service

--

--

No responses yet