Start AEM Automatically using SystemD

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 system.d!  This has a long history that I won’t get into here, but for your reference here is a great article which articulates why the previous init SysV method is being depreciated in favour of 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, lets 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 script is updated accordingly.
    • This script should be readable and executable by the root
    • AEM_USER
      • The system user in 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
      • 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 which 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:
      # sudo chmod u+rwx /usr/bin/aem
    4. Test the file works as expected
      # ./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 scripts location
    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
        # systemctl enable aem.system

That’s it! On your next reboot, AEM should be started as expected.

4 responses to “Start AEM Automatically Using SystemD”

  1. Anurag Sharma says:

    This is really awesome…

  2. fkh says:

    Unfortunately this approach will not work on SLES & Ubuntu (at least not w/o modifications). Why not go for a different approach that should work an all three Linux distributions.
    http://pastebin.com/ZY5sYW1j
    Granted setting CQ_JVM_OPTS is not very convenient but one doesn’t change that very often so it should be fine.

  3. Ryan McCullough says:

    That looks quite promising, thanks for sharing.

  4. Ekta says:

    I don’t see system.d directory. I see systemd instead. Are they both same?
    I am using Linux Redhat.

    Also, I am getting below error after doing all the steps-

    # systemctl enable aem.system
    Failed to execute operation: No such file or directory
    I have already provided required permissions aem.system file.

    Any suggestions?

Leave a Reply