[fix] Add random delay to app fetchlist cron job (#297)

* Add random delay to app fetchlist cron job
* Split the sleep and yunohost command on two lines
This commit is contained in:
Alexandre Aubin 2017-04-24 13:38:11 +02:00 committed by GitHub
parent 1516f48699
commit c502b8c348

View file

@ -1933,8 +1933,15 @@ def _install_appslist_fetch_cron():
logger.debug("Installing appslist fetch cron job")
cron_job = []
cron_job.append("#!/bin/bash")
# We add a random delay between 0 and 60 min to avoid every instance fetching
# the appslist at the same time every night
cron_job.append("(sleep $((RANDOM%3600));")
cron_job.append("yunohost app fetchlist > /dev/null 2>&1) &")
with open(cron_job_file, "w") as f:
f.write('#!/bin/bash\n\nyunohost app fetchlist > /dev/null 2>&1\n')
f.write('\n'.join(cron_job))
_set_permissions(cron_job_file, "root", "root", 0755)