Hi,
I am looking for an script to re start AEM instance, is there a way to do it in the AEM config ?
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
Hi,
If you are using AEM on-premise and AEM has been installed as a system service, you can easily use a "restart" command from the command line, in this scenario, you will have to create a bash script that will invoke the "aem service restart" and this will be scheduled at midnight, you can use "cron" for example to achieve the schedule(1), here you can find the details about this scenario: https://github.com/ksurendra/aem-as-a-service
If you are using AEM on-premise but AEM has not been installed as a system service, you will have to manually stop the AEM instance, verify the process is stopped, and start again the instance, this again will be a script that will be scheduled. You can find more info here about this scenario: https://aem-development.com/knowledge-base/how-to-restart-aem-instance/
If you are using AEMaaCS, I think there is no need to really bounce an instance due on each deployment this will be recreated, please read about how AEMaaCS works: https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/overview/architectu... which can help to clarify your doubts.
Something worth mentioning as well is that you can restart the system information that depending on your requirements can be useful: please check this article as well: https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/difference-between-aem-res...
Hope this helps
(1). https://stackoverflow.com/questions/37574458/how-to-run-a-bash-script-via-cron
Hi,
If you are using AEM on-premise and AEM has been installed as a system service, you can easily use a "restart" command from the command line, in this scenario, you will have to create a bash script that will invoke the "aem service restart" and this will be scheduled at midnight, you can use "cron" for example to achieve the schedule(1), here you can find the details about this scenario: https://github.com/ksurendra/aem-as-a-service
If you are using AEM on-premise but AEM has not been installed as a system service, you will have to manually stop the AEM instance, verify the process is stopped, and start again the instance, this again will be a script that will be scheduled. You can find more info here about this scenario: https://aem-development.com/knowledge-base/how-to-restart-aem-instance/
If you are using AEMaaCS, I think there is no need to really bounce an instance due on each deployment this will be recreated, please read about how AEMaaCS works: https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/overview/architectu... which can help to clarify your doubts.
Something worth mentioning as well is that you can restart the system information that depending on your requirements can be useful: please check this article as well: https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/difference-between-aem-res...
Hope this helps
(1). https://stackoverflow.com/questions/37574458/how-to-run-a-bash-script-via-cron
Hi @ashish_mishra1!
AEM itself does not have a built-in restart scheduling. Depending on your setup (on-premise or AMS with AEM 6.5 vs. AEM Cloud Service), there might be different options to achieve this.What "flavor" of AEM are you running and where is it hosted?
Overall, there are many reasons not to implement a daily restart of AEM and various challenges from an operational point of view if still trying to do it.
That leads to an important question: Why do you want to restart AEM regularly? What is your motivation?
If you are experiencing issues with AEM, such as decreasing performance or increasing issues/errors that can be solved by a restart of the instance, the better option would be to start a root cause analysis and work on the cause, not the symptoms.
In AEM, there isn't a built-in configuration specifically designed for scheduling automatic restarts. However, you can use a python script. Same python script will help you to start and restart the instance.
AEM_PATH = "/path/to/aem"
AEM_JAR = "aem-author.jar"
def start_aem():
try:
# Start AEM
subprocess.run(["java", "-jar", f"{AEM_PATH}/{AEM_JAR}"], check=True)
print("AEM started successfully.")
except subprocess.CalledProcessError as e:
print(f"Error: {e}")
print("AEM start failed.")
def stop_aem():
try:
# Stop AEM
subprocess.run([f"{AEM_PATH}/crx-quickstart/bin/stop"], check=True)
print("AEM stopped successfully.")
except subprocess.CalledProcessError as e:
print(f"Error: {e}")
print("AEM stop failed.")
def job():
# Start AEM
start_aem()
# Wait for a specified duration (in seconds)
duration = 60 # Adjust this to the desired duration
print(f"Waiting for {duration} seconds...")
time.sleep(duration)
# Stop AEM
stop_aem()
The schedule.every().day.at("00:00").do(job) line schedules the job to run every day at midnight.
# Schedule the job to run every day at a specific time (adjust as needed)
schedule.every().day.at("00:00").do(job)
while True:
schedule.run_pending()
time.sleep(1)
If you dont want to use python then you can use a scheduling tool like cron on Linux/macOS or Task Scheduler on Windows to run shell script at the desired interval.
Please be aware of what I have outlined in my post:
That being said, please also be aware that the provided python script is pretty basic and I would not recommend to use it in a scheduled, automatic mode for any relevant (meaning: productive) environment. It is lacking several checks (e. g. if AEM is already running on "start_aem"; a general status check after start up; a verification that AEM was actually shut down in "stop_aem"). There is a whole lot of exceptional and corner cases where solely relying on return codes from sub-processes is insufficient and results in an undefined state of your application. Also relying on fixed sleep timers to wait for AEM to reach a certain state (being it shut down or start up) is highly unreliable. This might cause various issues, up to repository corruption and a state where AEM is not running properly after the script is finished.
Finally, to me as a person not being familiar with Python, it seems that "job()" does have a logical flaw: It does trigger an AEM start up, waits for 60 seconds (hoping that AEM is fast enough) and shuts it down as a last step. After this routine, AEM will be in a shut down state (and your OPS team not happy). The start- and stop-methods should most probably be switched here: First shutting AEM down, waiting (and hoping) that AEM actually shuts down in the defined time frame and afterwards starting it up again. But as mentioned above: there are several sanity checks missing to make this more robust.
And re-emphasizing on my initial post: What is your motivation for scheduled restarts in the first place?
You are right @markus_bulla_adobe , It is a basic python script and one can use it for personal use only for local instances.
Views
Likes
Replies