January 2, 2021
Estimated Post Reading Time ~

Start AEM Automatically Using SystemD

With the release of RedHat and CentOS 7.x, the previously used method, init.d, for starting AEM as a service will no longer function. Out with the old SysV, in with the system.d! This has a long history that I won’t get into here, but for your reference here is a great article that articulates why the previous init SysV method is being depreciated in favor of the system.d.

Now, onto the fun stuff. How can we modify (or create) a system.d init script that will work with AEM? Well, I’ll walk you through how to do this using the standard init.d AEM script. If you have your own already, feel free to substitute it into the instructions.

You can grab a copy of the standard AEM init.d here (or here).
And here is the corresponding system.d file.

Now that we’re on the same page, let's get a few things straight:
  • If you generated your init.d script (from above) these instructions use the filename aem and location /usr/bin/aem for the location of this script. If you are using different values, please ensure the aem.system the script is updated accordingly.
  • This script should be readable and executable by the root
  • AEM_USER
    • The system user under which AEM is expected to run under. Be certain to start up an AEM instance using this user prior to going through these instructions to be sure they have appropriate permissions to the crx-quickstart folder
    • The default value is “aem”
  • AEM_ROOT
    • The root folder of AEM, or the parent folder of the crx-quickstart folder.
    • ex. if your crx-quickstart folder is /opt/aem6/crx-quickstart, the root folder would be /opt/aem6
    • Default value is /opt/aem6
  • aem.system is a (very) basic system.d script generated for your standard AEM init.d. In it, there are several places that reference the existing aem script. It is assuming that your AEM init.d script (see above for link) is located at /usr/bin/aem. This location can be modified to any you like, just ensure that:
    • It must be readable and executable by the root user
    • If the location of your AEM script is not /usr/bin/aem, update references to ExecStart, ExecStop, and ExecReload accordingly
    • If your AEM script does not include a restart, feel free to remove the ExecReload line as it will not function as expected.
Now for the official instructions:
  1. (If no existing init.d) Download the sample init.d script here
    1. Open the file and modify the AEM_USER and AEM_ROOT variables to suit your environment (see above for description)
    2. Save the file to your file system. This can be saved anywhere – the example aem.system file uses /usr/bin/aem.
    3. Ensure that the file is readable and writable as root:
      1. # sudo chmod u+rwx /usr/bin/aem
    4. Test the file works as expected
      1. # ./usr/bin/aem start
  2. Download the aem.system file.
    1. (If you are not using /usr/bin/aem) – Modify the aem.system file by updating the location referenced by ExecStart, ExecStop, and ExecReload to match the location of the script
    2. Save the script to /etc/system.d/system/aem.system
    3. Ensure that the file is readable and writable as root:
      1. # sudo chmod u+rwx /etc/system.d/system/aem.system
    4. Enable the system.d entry:
      1. # cd /etc/system.d/system
      2. # systemctl enable aem.system
That’s it! On your next reboot, AEM should be started as expected.


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.