From 2b5bd3cd888021beba630f256d965e361d15f1ce Mon Sep 17 00:00:00 2001 From: tituspijean Date: Wed, 4 Jan 2023 12:04:46 +0100 Subject: [PATCH 1/3] Implement random cron schedule --- conf/aeneria.cron | 2 +- scripts/_common.sh | 11 +++++++++++ scripts/install | 3 +++ scripts/upgrade | 8 ++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/conf/aeneria.cron b/conf/aeneria.cron index 6da777c..0c8ba2e 100644 --- a/conf/aeneria.cron +++ b/conf/aeneria.cron @@ -1 +1 @@ -*/20 * * * * __APP__ /usr/bin/php__PHPVERSION__ __FINALPATH__/bin/console aeneria:fetch-data +__MINUTES__ __HOUR__-23/3 * * * __APP__ /usr/bin/php__PHPVERSION__ __FINALPATH__/bin/console aeneria:fetch-data diff --git a/scripts/_common.sh b/scripts/_common.sh index 8da29ca..9395a7d 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -12,6 +12,17 @@ pkg_dependencies="apt-transport-https postgresql postgresql-contrib php${YNH_PHP # PERSONAL HELPERS #================================================= +# Assign two variables: +# minutes: random value between 00 and 59 (MM) +# hour: random value between 0 and 2 +# It is used for the cronjob, so that it runs every 3 hours starting at 00:MM, 01:MM, or 02:MM. +generate_random_minutes_hour () { + minutes="$(ynh_string_random --length=1 --filter=0-5)$(ynh_string_random --length=1 --filter=0-9)" + hour="$(ynh_string_random --length=1 --filter=0-2)" + ynh_app_setting_set --app=$app --key=minutes --value=$minutes + ynh_app_setting_set --app=$app --key=hour --value=$hour +} + #================================================= # EXPERIMENTAL HELPERS #================================================= diff --git a/scripts/install b/scripts/install index fb28664..09b226d 100644 --- a/scripts/install +++ b/scripts/install @@ -149,6 +149,9 @@ popd #================================================= ynh_script_progression --message="Setuping a cron..." --weight=1 +# Generate random running schedule, and save $hour and $minutes as app parameters +generate_random_minutes_hour + ynh_add_config --template="../conf/aeneria.cron" --destination="/etc/cron.d/$app" chown root: "/etc/cron.d/$app" chmod 644 "/etc/cron.d/$app" diff --git a/scripts/upgrade b/scripts/upgrade index a9be555..c857551 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -25,6 +25,8 @@ phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) deskey=$(ynh_app_setting_get --app=$app --key=deskey) db_user="$db_name" +hour=$(ynh_app_setting_get --app=$app --key=hour) +minutes=$(ynh_app_setting_get --app=$app --key=minutes) #================================================= # CHECK VERSION @@ -66,6 +68,12 @@ if [ -z "$final_path" ]; then ynh_app_setting_set --app=$app --key=final_path --value=$final_path fi +# If minutes or hour do not exist, create them +if [ -z "$minutes" ] || [ -z "$hour" ]; then + # Generate random running schedule, and save $hour and $minutes as app parameters + generate_random_minutes_hour +fi + # Cleaning legacy permissions if ynh_legacy_permissions_exists; then ynh_legacy_permissions_delete_all From db13286b093f14084290b03e648b9f69fd61280d Mon Sep 17 00:00:00 2001 From: yunohost-bot Date: Wed, 4 Jan 2023 11:23:32 +0000 Subject: [PATCH 2/3] Auto-update README --- README.md | 21 ++++++++++----------- README_fr.md | 27 +++++++++++++++------------ 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 53f186c..0848728 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ It shall NOT be edited by hand. # æneria for YunoHost -[![Integration level](https://dash.yunohost.org/integration/aeneria.svg)](https://dash.yunohost.org/appci/app/aeneria) ![](https://ci-apps.yunohost.org/ci/badges/aeneria.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/aeneria.maintain.svg) +[![Integration level](https://dash.yunohost.org/integration/aeneria.svg)](https://dash.yunohost.org/appci/app/aeneria) ![Working status](https://ci-apps.yunohost.org/ci/badges/aeneria.status.svg) ![Maintenance status](https://ci-apps.yunohost.org/ci/badges/aeneria.maintain.svg) [![Install æneria with YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=aeneria) *[Lire ce readme en français.](./README_fr.md)* @@ -23,11 +23,9 @@ The idea of [æneria](https://aeneria.com) is to display energy consumption and **Shipped version:** 1.1.6~ynh2 - - ## Screenshots -![](./doc/screenshots/screenshot1.png) +![Screenshot of æneria](./doc/screenshots/screenshot1.png) ## Disclaimers / important information @@ -48,21 +46,22 @@ But don't worry, you can easilly transfer your data from Pilea to æneria follow ## Documentation and resources -* Official app website: https://aeneria.com -* Official admin documentation: https://docs.aeneria.com -* Upstream app code repository: https://gitlab.com/aeneria/aeneria-app -* YunoHost documentation for this app: https://yunohost.org/app_aeneria -* Report a bug: https://github.com/YunoHost-Apps/aeneria_ynh/issues +* Official app website: +* Official admin documentation: +* Upstream app code repository: +* YunoHost documentation for this app: +* Report a bug: ## Developer info Please send your pull request to the [testing branch](https://github.com/YunoHost-Apps/aeneria_ynh/tree/testing). To try the testing branch, please proceed like that. -``` + +``` bash sudo yunohost app install https://github.com/YunoHost-Apps/aeneria_ynh/tree/testing --debug or sudo yunohost app upgrade aeneria -u https://github.com/YunoHost-Apps/aeneria_ynh/tree/testing --debug ``` -**More info regarding app packaging:** https://yunohost.org/packaging_apps \ No newline at end of file +**More info regarding app packaging:** diff --git a/README_fr.md b/README_fr.md index dbb52bb..4e4eeca 100644 --- a/README_fr.md +++ b/README_fr.md @@ -1,10 +1,14 @@ + + # æneria pour YunoHost -[![Niveau d'intégration](https://dash.yunohost.org/integration/aeneria.svg)](https://dash.yunohost.org/appci/app/aeneria) ![](https://ci-apps.yunohost.org/ci/badges/aeneria.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/aeneria.maintain.svg) +[![Niveau d'intégration](https://dash.yunohost.org/integration/aeneria.svg)](https://dash.yunohost.org/appci/app/aeneria) ![Statut du fonctionnement](https://ci-apps.yunohost.org/ci/badges/aeneria.status.svg) ![Statut de maintenance](https://ci-apps.yunohost.org/ci/badges/aeneria.maintain.svg) [![Installer æneria avec YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=aeneria) *[Read this readme in english.](./README.md)* -*[Lire ce readme en français.](./README_fr.md)* > *Ce package vous permet d'installer æneria rapidement et simplement sur un serveur YunoHost. Si vous n'avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) pour savoir comment l'installer et en profiter.* @@ -19,11 +23,9 @@ The idea of [æneria](https://aeneria.com) is to display energy consumption and **Version incluse :** 1.1.6~ynh2 - - ## Captures d'écran -![](./doc/screenshots/screenshot1.png) +![Capture d'écran de æneria](./doc/screenshots/screenshot1.png) ## Avertissements / informations importantes @@ -44,21 +46,22 @@ But don't worry, you can easilly transfer your data from Pilea to æneria follow ## Documentations et ressources -* Site officiel de l'app : https://aeneria.com -* Documentation officielle de l'admin : https://docs.aeneria.com -* Dépôt de code officiel de l'app : https://gitlab.com/aeneria/aeneria-app -* Documentation YunoHost pour cette app : https://yunohost.org/app_aeneria -* Signaler un bug : https://github.com/YunoHost-Apps/aeneria_ynh/issues +* Site officiel de l'app : +* Documentation officielle de l'admin : +* Dépôt de code officiel de l'app : +* Documentation YunoHost pour cette app : +* Signaler un bug : ## Informations pour les développeurs Merci de faire vos pull request sur la [branche testing](https://github.com/YunoHost-Apps/aeneria_ynh/tree/testing). Pour essayer la branche testing, procédez comme suit. -``` + +``` bash sudo yunohost app install https://github.com/YunoHost-Apps/aeneria_ynh/tree/testing --debug ou sudo yunohost app upgrade aeneria -u https://github.com/YunoHost-Apps/aeneria_ynh/tree/testing --debug ``` -**Plus d'infos sur le packaging d'applications :** https://yunohost.org/packaging_apps \ No newline at end of file +**Plus d'infos sur le packaging d'applications :** From f5ed5b4d825a474d945d4efe643f8d41db9c0fda Mon Sep 17 00:00:00 2001 From: tituspijean Date: Sat, 7 Jan 2023 12:07:21 +0100 Subject: [PATCH 3/3] Explain cronjob random start time Co-authored-by: Simon MELLERIN --- scripts/_common.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 9395a7d..ba24150 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -15,7 +15,11 @@ pkg_dependencies="apt-transport-https postgresql postgresql-contrib php${YNH_PHP # Assign two variables: # minutes: random value between 00 and 59 (MM) # hour: random value between 0 and 2 -# It is used for the cronjob, so that it runs every 3 hours starting at 00:MM, 01:MM, or 02:MM. +# To avoid peak load on proxy.aeneria.com, we randomize when the cron job will be launched +# Assign two variables: +# minutes: random value between 00 and 59 (MM) +# hour: random value between 0 and 2 +# These two variables are used in conf/aeneria.cron so that it runs every 3 hours starting at 00:MM, 01:MM, or 02:MM. generate_random_minutes_hour () { minutes="$(ynh_string_random --length=1 --filter=0-5)$(ynh_string_random --length=1 --filter=0-9)" hour="$(ynh_string_random --length=1 --filter=0-2)"