From d6fb14fae59cd5fb72b2e1a99ccfae6f2ad99482 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Mon, 11 Dec 2023 12:37:28 +0100 Subject: [PATCH 1/7] manifestv2 --- check_process | 20 ------ conf/app.src | 7 -- conf/nginx.conf | 2 +- conf/systemd.service | 4 +- doc/{DISCLAIMER.md => ADMIN.md} | 0 manifest.json | 73 -------------------- manifest.toml | 80 ++++++++++++++++++++++ scripts/_common.sh | 34 ++++----- scripts/backup | 19 +---- scripts/install | 118 +++++++++----------------------- scripts/remove | 61 ++++------------- scripts/restore | 67 +++--------------- scripts/upgrade | 102 +++++---------------------- tests.toml | 12 ++++ 14 files changed, 189 insertions(+), 410 deletions(-) delete mode 100644 check_process delete mode 100644 conf/app.src rename doc/{DISCLAIMER.md => ADMIN.md} (100%) delete mode 100644 manifest.json create mode 100644 manifest.toml create mode 100644 tests.toml diff --git a/check_process b/check_process deleted file mode 100644 index b863f8c..0000000 --- a/check_process +++ /dev/null @@ -1,20 +0,0 @@ -;; Test complet - ; Manifest - monitored_servers="remote_domain.tld,remote_domain2.tld" - monitoring_servers="" - mails="john@example.com" - sms_api="" - ; Checks - pkg_linter=1 - setup_sub_dir=0 - setup_root=0 - setup_nourl=1 - setup_private=0 - setup_public=0 - upgrade=1 - # 1.1.0~ynh2 - upgrade=1 from_commit=4feb4a78181518956e7d230a2ab67d96992f8563 - backup_restore=1 - multi_instance=0 - port_already_use=0 - change_url=0 diff --git a/conf/app.src b/conf/app.src deleted file mode 100644 index c2123ad..0000000 --- a/conf/app.src +++ /dev/null @@ -1,7 +0,0 @@ -SOURCE_URL=https://github.com/zamentur/yunomonitor/archive/0a2c295485dbda9da3b97353e094ef414c939609.tar.gz -SOURCE_SUM=e9c63885c5158771a00ae892967a0f7d1f3f538f26d124f8f096bb7b8ff3113a -SOURCE_SUM_PRG=sha256sum -SOURCE_FORMAT=tar.gz -SOURCE_IN_SUBDIR=true -SOURCE_FILENAME=yunomonitor-1-1-0.tar.gz -SOURCE_EXTRACT=true diff --git a/conf/nginx.conf b/conf/nginx.conf index 9a76413..eaea66b 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,5 +1,5 @@ location ^~ '/.well-known/yunomonitor/' { default_type "text/plain"; - alias __FINALPATH__/well-known/; + alias __INSTALL_DIR__/well-known/; } diff --git a/conf/systemd.service b/conf/systemd.service index 6b76dc1..9e6eb45 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -6,8 +6,8 @@ After=network.target Type=oneshot User=__APP__ Group=__APP__ -WorkingDirectory=__FINALPATH__ -ExecStart=__FINALPATH__/yunomonitor.py -c __FINALPATH__/conf/__APP__.yml +WorkingDirectory=__INSTALL_DIR__ +ExecStart=__INSTALL_DIR__/yunomonitor.py -c __INSTALL_DIR__/conf/__APP__.yml User=root Group=root diff --git a/doc/DISCLAIMER.md b/doc/ADMIN.md similarity index 100% rename from doc/DISCLAIMER.md rename to doc/ADMIN.md diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 3b35325..0000000 --- a/manifest.json +++ /dev/null @@ -1,73 +0,0 @@ -{ - "name": "YunoMonitor", - "id": "yunomonitor", - "packaging_format": 1, - "description": { - "en": "Home made tool to monitor automatically your servers", - "fr": "Outil pour surveiller automatiquement vos serveurs" - }, - "version": "1.1.0~ynh3", - "url": "https://github.com/zamentur/yunomonitor", - "upstream": { - "license": "AGPL-3.0", - "website": "https://github.com/zamentur/yunomonitor", - "admindoc": "https://github.com/zamentur/yunomonitor/blob/master/README.md", - "code": "https://github.com/zamentur/yunomonitor" - }, - "license": "AGPL-3.0", - "maintainer": { - "name": "ljf", - "email": "ljf+@reflexlibre.net", - "url": "https://reflexlibre.net" - }, - "requirements": { - "yunohost": ">= 4.3.0" - }, - "multi_instance": false, - "services": [ - "nginx" - ], - "arguments": { - "install": [ - { - "name": "monitored_servers", - "type": "string", - "ask": { - "en": "List all servers you want to monitor with this server (separated by comma)" - }, - "help": { - "en": "You need to install yunomonitor on those servers or add manually a custom configuration file for each server to monitor" - }, - "example": "example.com,example2.com", - "default": "localhost" - }, - { - "name": "monitoring_servers", - "type": "string", - "ask": { - "en": "List all monitoring servers that monitored this server (separated by comma)" - }, - "example": "example.com,example2.com", - "optional": true - }, - { - "name": "mails", - "type": "string", - "ask": { - "en": "Mails to which send alerts about servers monitored by this server (separated by comma)" - }, - "example": "john@example.com,jane@example.com", - "optional": true - }, - { - "name": "sms_api", - "type": "string", - "ask": { - "en": "List here an SMS URL to use to send alerts by SMS (e.g. the internet provider 'free' offers some API for that)" - }, - "example": "https://smsapi.free-mobile.fr/sendmsg?user=USERID&pass=PASSWORD&msg=", - "optional": true - } - ] - } -} diff --git a/manifest.toml b/manifest.toml new file mode 100644 index 0000000..28d60f4 --- /dev/null +++ b/manifest.toml @@ -0,0 +1,80 @@ +#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/manifest.v2.schema.json + +packaging_format = 2 + +id = "yunomonitor" +name = "YunoMonitor" +description.en = "Home made tool to monitor automatically your servers" +description.fr = "Outil pour surveiller automatiquement vos serveurs" + +version = "1.1.0~ynh3" + +maintainers = ["ljf"] + +[upstream] +license = "AGPL-3.0" +code = "https://github.com/zamentur/yunomonitor" +admindoc = "https://github.com/zamentur/yunomonitor/blob/master/README.md" +fund = "https://donate.yunohost.org/" + +[integration] +yunohost = ">= 4.3.0" +architectures = "all" +multi_instance = false +ldap = "not_relevant" +sso = "not_relevant" +disk = "50M" # FIXME: replace with an **estimate** minimum disk requirement. e.g. 20M, 400M, 1G, ... +ram.build = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ... +ram.runtime = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ... + +[install] + [install.monitored_servers] + ask.en = "List all servers you want to monitor with this server (separated by comma)" + help.en = "You need to install yunomonitor on those servers or add manually a custom configuration file for each server to monitor" + type = "string" + example = "example.com,example2.com" + default = "localhost" + + [install.monitoring_servers] + ask.en = "List all monitoring servers that monitored this server (separated by comma)" + type = "string" + example = "example.com,example2.com" + optional = true + + [install.mails] + ask.en = "Mails to which send alerts about servers monitored by this server (separated by comma)" + type = "string" + example = "john@example.com,jane@example.com" + optional = true + + [install.sms_api] + ask.en = "List here an SMS URL to use to send alerts by SMS (e.g. the internet provider 'free' offers some API for that)" + type = "string" + example = "https://smsapi.free-mobile.fr/sendmsg?user=USERID&pass=PASSWORD&msg=" + optional = true + +[resources] + [resources.sources.main] + url = "https://github.com/zamentur/yunomonitor/archive/0a2c295485dbda9da3b97353e094ef414c939609.tar.gz" + sha256 = "e9c63885c5158771a00ae892967a0f7d1f3f538f26d124f8f096bb7b8ff3113a" + autoupdate.strategy = "latest_github_commit" + + [resources.system_user] + + [resources.install_dir] + + [resources.permissions] + + [resources.apt] + packages = [ + "python3-dbus", + "python3-pip", + "python3-cryptography", + "python3-paramiko", + "python3-yaml", + "python3-dnspython", + "python3-requests-toolbelt", + "python3-spf", + "whois", + "smartmontools", + ] diff --git a/scripts/_common.sh b/scripts/_common.sh index 02726b8..bd82a93 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -4,13 +4,28 @@ # COMMON VARIABLES #================================================= -# dependencies used by the app -pkg_dependencies="python3-dbus python3-cryptography python3-paramiko python3-yaml python3-dnspython python3-requests-toolbelt python3-spf whois smartmontools" + #================================================= # PERSONAL HELPERS #================================================= +_yunomonitor_add_nginx_config() { + # Create a dedicated nginx config + # Note: i don't use the helper because i need this file to be named "000-" + finalnginxconf="/etc/nginx/conf.d/$domain.d/000-$app.conf" + ynh_backup_if_checksum_is_different --file="$finalnginxconf" + cp ../conf/nginx.conf "$finalnginxconf" + ynh_replace_string --match_string="__INSTALL_DIR__" --replace_string="$install_dir" --target_file="$finalnginxconf" + ynh_store_file_checksum --file="$finalnginxconf" +} + +_yunomonitor_remove_nginx_config() { + finalnginxconf="/etc/nginx/conf.d/$domain.d/000-$app.conf" + ynh_secure_remove --file="$finalnginxconf" + ynh_systemd_action --service_name=nginx --action=reload +} + #================================================= # EXPERIMENTAL HELPERS #================================================= @@ -20,26 +35,13 @@ ynh_export () { for var in $@; do ynh_arg=$(echo $var | awk '{print toupper($0)}') - if [ "$var" == "path_url" ]; then + if [ "$var" == "path" ]; then ynh_arg="PATH" fi ynh_arg="YNH_APP_ARG_$ynh_arg" export $var="${!ynh_arg}" done } -# Save listed var in YunoHost app settings -# usage: ynh_save_args VARNAME1 [VARNAME2 [...]] - -ynh_save_args () { - for var in $@; - do - local setting_var="$var" - if [ "$var" == "path_url" ]; then - setting_var="path" - fi - ynh_app_setting_set "$app" "$setting_var" "${!var}" - done -} #================================================= # FUTURE OFFICIAL HELPERS diff --git a/scripts/backup b/scripts/backup index 5a1cfbb..b624ee5 100755 --- a/scripts/backup +++ b/scripts/backup @@ -10,23 +10,6 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# LOAD SETTINGS -#================================================= -ynh_print_info --message="Loading installation settings..." - -app=$YNH_APP_INSTANCE_NAME - -final_path=$(ynh_app_setting_get --app=$app --key=final_path) -domain=$(ynh_app_setting_get --app=$app --key=domain) - #================================================= # DECLARE DATA AND CONF FILES TO BACKUP #================================================= @@ -36,7 +19,7 @@ ynh_print_info --message="Declaring files to be backed up..." # BACKUP THE APP MAIN DIR #================================================= -ynh_backup --src_path="$final_path" +ynh_backup --src_path="$install_dir" #================================================= # BACKUP THE NGINX CONFIGURATION diff --git a/scripts/install b/scripts/install index 92ca707..0bf635b 100755 --- a/scripts/install +++ b/scripts/install @@ -10,83 +10,36 @@ source _common.sh source /usr/share/yunohost/helpers #================================================= -# MANAGE SCRIPT FAILURE +# STORE SETTINGS #================================================= -ynh_clean_setup () { - true -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors +domain=$(yunohost domain list --json | jq -r '.["main"]') +path=/.well-known/yunomonitor/ -#================================================= -# RETRIEVE ARGUMENTS FROM THE MANIFEST -#================================================= +ynh_app_setting_set --app="$app" --key="domain" --value="$domain" +ynh_app_setting_set --app="$app" --key="path" --value="$path" -export domain=$(cat /etc/yunohost/current_host) -export path_url=/.well-known/yunomonitor/ +# FIXME: required? ynh_export monitored_servers monitoring_servers mails sms_api -app=$YNH_APP_INSTANCE_NAME - -#================================================= -# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS -#================================================= -ynh_script_progression --message="Validating installation parameters..." --weight=1 - -final_path=/opt/$app -test ! -e "$final_path" || ynh_die --message="This path already contains a folder" - -#================================================= -# STORE SETTINGS FROM MANIFEST -#================================================= -ynh_script_progression --message="Storing installation settings..." --weight=1 - -ynh_save_args domain path_url monitored_servers monitoring_servers mails sms_api - -#================================================= -# STANDARD MODIFICATIONS -#================================================= -# INSTALL DEPENDENCIES -#================================================= -ynh_script_progression --message="Installing dependencies..." --weight=1 - -ynh_install_app_dependencies $pkg_dependencies - -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Configuring system user..." --weight=1 - -# Create a system user -ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Setting up source files..." --weight=1 -ynh_app_setting_set --app=$app --key=final_path --value=$final_path -# Download, check integrity, uncompress and patch the source from app.src -ynh_setup_source --dest_dir="$final_path" +ynh_setup_source --dest_dir="$install_dir" -chmod 750 "$final_path" -chmod -R o-rwx "$final_path" -chown -R $app:www-data "$final_path" +chmod 750 "$install_dir" +chmod -R o-rwx "$install_dir" +chown -R "$app:www-data" "$install_dir" #================================================= # NGINX CONFIGURATION #================================================= ynh_script_progression --message="Configuring NGINX web server..." --weight=1 -# Create a dedicated nginx config -# Note: i don't use the helper because i need this file to be named "000-" -finalnginxconf="/etc/nginx/conf.d/$domain.d/000-$app.conf" -ynh_backup_if_checksum_is_different --file="$finalnginxconf" -cp ../conf/nginx.conf "$finalnginxconf" -ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$finalnginxconf" -ynh_store_file_checksum --file="$finalnginxconf" -ynh_systemd_action --service_name=nginx --action=reload +_yunomonitor_add_nginx_config #================================================= # SPECIFIC SETUP @@ -95,8 +48,8 @@ ynh_systemd_action --service_name=nginx --action=reload #================================================= ynh_script_progression --message="Building Yunomonitor..." -pushd "$final_path" - pip3 install pycryptodome +pushd "$install_dir" + python3 -m pip install pycryptodome popd #================================================= @@ -105,50 +58,41 @@ popd ynh_script_progression --message="Configuring a systemd service..." ynh_add_systemd_config -cp ../conf/systemd.timer "/etc/systemd/system/$app.timer" -ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="/etc/systemd/system/$app.timer" +ynh_add_config --template="systemd.timer" --destination="/etc/systemd/system/$app.timer" + systemctl daemon-reload -systemctl enable $app.timer --quiet -systemctl start $app.timer +systemctl enable "$app.timer" --quiet +systemctl start "$app.timer" #================================================= # ADD A CONFIGURATION #================================================= ynh_script_progression --message="Adding a configuration file..." -echo "mails: [$mails]" > $final_path/conf/$app.yml -echo "sms_apis: [$sms_api]" >> $final_path/conf/$app.yml -echo "monitored_servers: [$monitored_servers]" >> $final_path/conf/$app.yml -echo "monitoring_servers: [$monitoring_servers]" >> $final_path/conf/$app.yml -echo "cachet_apis: []" >> $final_path/conf/$app.yml -sed -i 's/,/","/g' $final_path/conf/$app.yml -sed -i 's/\[/["/g' $final_path/conf/$app.yml -sed -i 's/\]/"]/g' $final_path/conf/$app.yml -sed -i 's/\[""\]/[]/g' $final_path/conf/$app.yml +echo "mails: [$mails]" > $install_dir/conf/$app.yml +echo "sms_apis: [$sms_api]" >> $install_dir/conf/$app.yml +echo "monitored_servers: [$monitored_servers]" >> $install_dir/conf/$app.yml +echo "monitoring_servers: [$monitoring_servers]" >> $install_dir/conf/$app.yml +echo "cachet_apis: []" >> $install_dir/conf/$app.yml +sed -i 's/,/","/g' $install_dir/conf/$app.yml +sed -i 's/\[/["/g' $install_dir/conf/$app.yml +sed -i 's/\]/"]/g' $install_dir/conf/$app.yml +sed -i 's/\[""\]/[]/g' $install_dir/conf/$app.yml # Calculate and store the config file checksum into the app settings -ynh_store_file_checksum --file="$final_path/conf/$app.yml" +ynh_store_file_checksum --file="$install_dir/conf/$app.yml" #================================================= # INIT IGNORE FILE #================================================= -echo "method level server message target" > $final_path/conf/ignore_alert.csv +echo "method level server message target" > "$install_dir/conf/ignore_alert.csv" # Set permissions to app files -chmod u+x $final_path/yunomonitor.py -chmod u+w $final_path/conf -chmod u+w $final_path/well-known - -#================================================= -# GENERIC FINALIZATION -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server..." --weight=1 - -ynh_systemd_action --service_name=nginx --action=reload +chmod u+x "$install_dir/yunomonitor.py" +chmod u+w "$install_dir/conf" +chmod u+w "$install_dir/well-known" #================================================= # END OF SCRIPT diff --git a/scripts/remove b/scripts/remove index cbe3ac0..01b179c 100755 --- a/scripts/remove +++ b/scripts/remove @@ -9,61 +9,30 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." --weight=1 - -app=$YNH_APP_INSTANCE_NAME - -domain=$(ynh_app_setting_get --app=$app --key=domain) -final_path=$(ynh_app_setting_get --app=$app --key=final_path) - #================================================= # STANDARD REMOVE #================================================= # STOP AND REMOVE SERVICE #================================================= -ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1 + +# Remove the service from the list of services known by YunoHost (added from `yunohost service add`) +if ynh_exec_warn_less yunohost service status $app >/dev/null +then + ynh_script_progression --message="Removing $app service integration..." --weight=3 + yunohost service remove "$app" +fi + +#================================================= +# REMOVE SYSTEM CONFIGURATIONS +#================================================= +ynh_script_progression --message="Removing system configurations related to $app..." --weight=1 + +ynh_systemd_action --service_name="$app" --action="stop" --log_path="systemd" --timeout=15 ynh_secure_remove --file="/etc/systemd/system/$app.timer" - -# Remove the dedicated systemd config ynh_remove_systemd_config -#================================================= -# REMOVE APP MAIN DIR -#================================================= -ynh_script_progression --message="Removing app main directory..." --weight=1 - -# Remove the app directory securely -ynh_secure_remove --file="$final_path" - -#================================================= -# REMOVE NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1 - -# Remove the dedicated NGINX config -ynh_remove_nginx_config - -#================================================= -# REMOVE DEPENDENCIES -#================================================= -ynh_script_progression --message="Removing dependencies..." --weight=1 - -# Remove metapackage and its dependencies -ynh_remove_app_dependencies - -#================================================= -# GENERIC FINALIZATION -#================================================= -# REMOVE DEDICATED USER -#================================================= -ynh_script_progression --message="Removing the dedicated system user..." --weight=1 - -# Delete a system user -ynh_system_user_delete --username=$app +_yunomonitor_remove_nginx_config #================================================= # END OF SCRIPT diff --git a/scripts/restore b/scripts/restore index f7346c4..6e86890 100755 --- a/scripts/restore +++ b/scripts/restore @@ -10,41 +10,6 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." --weight=1 - -app=$YNH_APP_INSTANCE_NAME - -domain=$(ynh_app_setting_get --app=$app --key=domain) -final_path=$(ynh_app_setting_get --app=$app --key=final_path) - -#================================================= -# CHECK IF THE APP CAN BE RESTORED -#================================================= -ynh_script_progression --message="Validating restoration parameters..." --weight=1 - -test ! -d $final_path \ - || ynh_die --message="There is already a directory: $final_path " - -#================================================= -# STANDARD RESTORATION STEPS -#================================================= -# RECREATE THE DEDICATED USER -#================================================= -ynh_script_progression --message="Recreating the dedicated system user..." --weight=1 - -# Create the dedicated user (if not existing) -ynh_system_user_create --username=$app --home_dir="$final_path" - #================================================= # RESTORE FILES #================================================= @@ -57,30 +22,20 @@ ynh_restore #================================================= # Restore permissions on app files -chmod 750 "$final_path" -chmod -R o-rwx "$final_path" -chown -R $app:www-data "$final_path" -chmod u+x $final_path/yunomonitor.py -chmod u+w $final_path/conf -chmod u+w $final_path/well-known - -#================================================= -# SPECIFIC RESTORATION -#================================================= -# REINSTALL DEPENDENCIES -#================================================= -ynh_script_progression --message="Reinstalling dependencies..." --weight=1 - -# Define and install dependencies -ynh_install_app_dependencies $pkg_dependencies +chmod 750 "$install_dir" +chmod -R o-rwx "$install_dir" +chown -R $app:www-data "$install_dir" +chmod u+x "$install_dir/yunomonitor.py" +chmod u+w "$install_dir/conf" +chmod u+w "$install_dir/well-known" #================================================= # BUILD YUNOMONITOR #================================================= ynh_script_progression --message="Building Yunomonitor..." -pushd "$final_path" - pip3 install pycryptodome +pushd "$install_dir" + python3 -m pip install pycryptodome popd #================================================= @@ -89,9 +44,9 @@ popd ynh_script_progression --message="Activating systemd timer..." --weight=1 systemctl daemon-reload -systemctl enable $app.service --quiet -systemctl enable $app.timer --quiet -systemctl start $app.timer +systemctl enable "$app.service" --quiet +systemctl enable "$app.timer" --quiet +systemctl start "$app.timer" #================================================= # GENERIC FINALIZATION diff --git a/scripts/upgrade b/scripts/upgrade index 718b08f..33016f7 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -9,37 +9,8 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." --weight=1 - -app=$YNH_APP_INSTANCE_NAME - -domain=$(ynh_app_setting_get --app=$app --key=domain) -final_path=$(ynh_app_setting_get --app=$app --key=final_path) - -#================================================= -# CHECK VERSION -#================================================= -ynh_script_progression --message="Checking version..." - upgrade_type=$(ynh_check_app_version_changed) -#================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP -#================================================= -ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1 - -# Backup the current version of the app -ynh_backup_before_upgrade -ynh_clean_setup () { - # Restore it if the upgrade fails - ynh_restore_upgradebackup -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - #================================================= # STANDARD UPGRADE STEPS #================================================= @@ -47,18 +18,10 @@ ynh_abort_if_errors #================================================= ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 -if ! [ -f $final_path/conf/ignore_alert.csv ]; then - echo "method level server message target" > $final_path/conf/ignore_alert.csv +if ! [ -f $install_dir/conf/ignore_alert.csv ]; then + echo "method level server message target" > $install_dir/conf/ignore_alert.csv fi -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 - -# Create a dedicated user (if not existing) -ynh_system_user_create --username=$app --home_dir="$final_path" - #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -68,46 +31,23 @@ then ynh_script_progression --message="Upgrading source files..." --weight=1 # Download, check integrity, uncompress and patch the source from app.src - ynh_setup_source --dest_dir="$final_path" + ynh_setup_source --dest_dir="$install_dir" fi -chmod 750 "$final_path" -chmod -R o-rwx "$final_path" -chown -R $app:www-data "$final_path" -chmod u+x $final_path/yunomonitor.py -chmod u+w $final_path/conf -chmod u+w $final_path/well-known +chmod 750 "$install_dir" +chmod -R o-rwx "$install_dir" +chown -R $app:www-data "$install_dir" +chmod u+x "$install_dir/yunomonitor.py" +chmod u+w "$install_dir/conf" +chmod u+w "$install_dir/well-known" -#================================================= -# NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1 - -# Create a dedicated nginx config -# Note: i don't use the helper because i need this file to be named "000-" -finalnginxconf="/etc/nginx/conf.d/$domain.d/000-$app.conf" -ynh_backup_if_checksum_is_different --file="$finalnginxconf" -cp ../conf/nginx.conf "$finalnginxconf" -ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$finalnginxconf" -ynh_store_file_checksum --file="$finalnginxconf" -ynh_systemd_action --service_name=nginx --action=reload - -#================================================= -# UPGRADE DEPENDENCIES -#================================================= -ynh_script_progression --message="Upgrading dependencies..." --weight=1 - -ynh_install_app_dependencies $pkg_dependencies - -#================================================= -# SPECIFIC UPGRADE #================================================= # BUILD YUNOMONITOR #================================================= ynh_script_progression --message="Building Yunomonitor..." -pushd "$final_path" - pip3 install pycryptodome +pushd "$install_dir" + python3 -m pip install pycryptodome popd #================================================= @@ -116,16 +56,17 @@ popd ### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script. ### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it. -ynh_backup_if_checksum_is_different --file="$final_path/conf/$app.yml" +ynh_backup_if_checksum_is_different --file="$install_dir/conf/$app.yml" # Recalculate and store the checksum of the file for the next upgrade. -ynh_store_file_checksum --file="$final_path/conf/$app.yml" +ynh_store_file_checksum --file="$install_dir/conf/$app.yml" #================================================= -# SETUP SYSTEMD +# REAPPLY SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Upgrading systemd configuration..." --weight=1 +ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 + +_yunomonitor_add_nginx_config -# Create a dedicated systemd config ynh_add_systemd_config #================================================= @@ -133,14 +74,7 @@ ynh_add_systemd_config #================================================= ynh_script_progression --message="Reloading a systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action="reload" --log_path="/var/log/$app/$app.log" - -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server..." --weight=1 - -ynh_systemd_action --service_name=nginx --action=reload +ynh_systemd_action --service_name="$app" --action="reload" --log_path="/var/log/$app/$app.log" #================================================= # END OF SCRIPT diff --git a/tests.toml b/tests.toml new file mode 100644 index 0000000..08e8525 --- /dev/null +++ b/tests.toml @@ -0,0 +1,12 @@ +#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/tests.v1.schema.json + +test_format = 1.0 + +[default] + + args.monitored_servers = "remote_domain.tld,remote_domain2.tld" + args.monitoring_servers = "" + args.mails = "john@example.com" + args.sms_api = "" + + test_upgrade_from.4feb4a78181518956e7d230a2ab67d96992f8563.name = "1.1.0~ynh2" From 3168ffca96374f1c44c06b972bc8db27d9ba53a1 Mon Sep 17 00:00:00 2001 From: yunohost-bot Date: Mon, 11 Dec 2023 11:37:35 +0000 Subject: [PATCH 2/7] Auto-update README --- README.md | 5 ----- README_fr.md | 5 ----- 2 files changed, 10 deletions(-) diff --git a/README.md b/README.md index 7cdf9a2..a54b9c4 100644 --- a/README.md +++ b/README.md @@ -20,13 +20,8 @@ YunoMonitor is a simple tools to auto-configure monitoring on a remote YunoHost **Shipped version:** 1.1.0~ynh3 -## Disclaimers / important information - -YunoMonitor can send you email or SMS if you give him an URL API to do it (like the API from the operator "free mobile"). - ## Documentation and resources -* Official app website: * Official admin documentation: * Upstream app code repository: * YunoHost Store: diff --git a/README_fr.md b/README_fr.md index 562b841..a80a520 100644 --- a/README_fr.md +++ b/README_fr.md @@ -20,13 +20,8 @@ YunoMonitor is a simple tools to auto-configure monitoring on a remote YunoHost **Version incluse :** 1.1.0~ynh3 -## Avertissements / informations importantes - -YunoMonitor can send you email or SMS if you give him an URL API to do it (like the API from the operator "free mobile"). - ## Documentations et ressources -* Site officiel de l’app : * Documentation officielle de l’admin : * Dépôt de code officiel de l’app : * YunoHost Store: From 2fca6c3e68833b758c87bacf616aec2eeb3f19f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Fri, 19 Jan 2024 16:41:23 +0100 Subject: [PATCH 3/7] Cleanup, fixes --- scripts/_common.sh | 15 --------------- scripts/install | 29 +++++++++++++---------------- scripts/remove | 18 +++++------------- scripts/restore | 2 +- scripts/upgrade | 23 ++++++++--------------- 5 files changed, 27 insertions(+), 60 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index bd82a93..a187a4a 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -4,8 +4,6 @@ # COMMON VARIABLES #================================================= - - #================================================= # PERSONAL HELPERS #================================================= @@ -30,19 +28,6 @@ _yunomonitor_remove_nginx_config() { # EXPERIMENTAL HELPERS #================================================= -ynh_export () { - local ynh_arg="" - for var in $@; - do - ynh_arg=$(echo $var | awk '{print toupper($0)}') - if [ "$var" == "path" ]; then - ynh_arg="PATH" - fi - ynh_arg="YNH_APP_ARG_$ynh_arg" - export $var="${!ynh_arg}" - done -} - #================================================= # FUTURE OFFICIAL HELPERS #================================================= diff --git a/scripts/install b/scripts/install index 0bf635b..5f2e057 100755 --- a/scripts/install +++ b/scripts/install @@ -10,7 +10,7 @@ source _common.sh source /usr/share/yunohost/helpers #================================================= -# STORE SETTINGS +# INITIALIZE AND STORE SETTINGS #================================================= domain=$(yunohost domain list --json | jq -r '.["main"]') @@ -19,10 +19,6 @@ path=/.well-known/yunomonitor/ ynh_app_setting_set --app="$app" --key="domain" --value="$domain" ynh_app_setting_set --app="$app" --key="path" --value="$path" -# FIXME: required? -ynh_export monitored_servers monitoring_servers mails sms_api - - #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -49,7 +45,7 @@ _yunomonitor_add_nginx_config ynh_script_progression --message="Building Yunomonitor..." pushd "$install_dir" - python3 -m pip install pycryptodome + python3 -m pip install pycryptodome pyyaml popd #================================================= @@ -69,15 +65,17 @@ systemctl start "$app.timer" #================================================= ynh_script_progression --message="Adding a configuration file..." -echo "mails: [$mails]" > $install_dir/conf/$app.yml -echo "sms_apis: [$sms_api]" >> $install_dir/conf/$app.yml -echo "monitored_servers: [$monitored_servers]" >> $install_dir/conf/$app.yml -echo "monitoring_servers: [$monitoring_servers]" >> $install_dir/conf/$app.yml -echo "cachet_apis: []" >> $install_dir/conf/$app.yml -sed -i 's/,/","/g' $install_dir/conf/$app.yml -sed -i 's/\[/["/g' $install_dir/conf/$app.yml -sed -i 's/\]/"]/g' $install_dir/conf/$app.yml -sed -i 's/\[""\]/[]/g' $install_dir/conf/$app.yml +python3 -c ' +import sys +import yaml +print(yaml.dumps({ + "mails": sys.argv[1].split(","), + "sms_apis": sys.argv[2].split(","), + "monitored_servers": sys.argv[3].split(","), + "monitoring_servers": sys.argv[4].split(","), +})) +' "$mails" "$sms_api" "$monitored_servers" "$monitoring_servers" \ +> "$install_dir/conf/$app.yml" # Calculate and store the config file checksum into the app settings ynh_store_file_checksum --file="$install_dir/conf/$app.yml" @@ -88,7 +86,6 @@ ynh_store_file_checksum --file="$install_dir/conf/$app.yml" echo "method level server message target" > "$install_dir/conf/ignore_alert.csv" - # Set permissions to app files chmod u+x "$install_dir/yunomonitor.py" chmod u+w "$install_dir/conf" diff --git a/scripts/remove b/scripts/remove index 01b179c..1dd02fa 100755 --- a/scripts/remove +++ b/scripts/remove @@ -9,24 +9,16 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# STANDARD REMOVE -#================================================= -# STOP AND REMOVE SERVICE -#================================================= - -# Remove the service from the list of services known by YunoHost (added from `yunohost service add`) -if ynh_exec_warn_less yunohost service status $app >/dev/null -then - ynh_script_progression --message="Removing $app service integration..." --weight=3 - yunohost service remove "$app" -fi - #================================================= # REMOVE SYSTEM CONFIGURATIONS #================================================= ynh_script_progression --message="Removing system configurations related to $app..." --weight=1 +# Remove the service from the list of services known by YunoHost (added from `yunohost service add`) +if ynh_exec_warn_less yunohost service status "$app" >/dev/null; then + yunohost service remove "$app" +fi + ynh_systemd_action --service_name="$app" --action="stop" --log_path="systemd" --timeout=15 ynh_secure_remove --file="/etc/systemd/system/$app.timer" diff --git a/scripts/restore b/scripts/restore index 6e86890..0af8da9 100755 --- a/scripts/restore +++ b/scripts/restore @@ -35,7 +35,7 @@ chmod u+w "$install_dir/well-known" ynh_script_progression --message="Building Yunomonitor..." pushd "$install_dir" - python3 -m pip install pycryptodome + python3 -m pip install pycryptodome popd #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 33016f7..de70d05 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -9,8 +9,6 @@ source _common.sh source /usr/share/yunohost/helpers -upgrade_type=$(ynh_check_app_version_changed) - #================================================= # STANDARD UPGRADE STEPS #================================================= @@ -18,25 +16,22 @@ upgrade_type=$(ynh_check_app_version_changed) #================================================= ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 -if ! [ -f $install_dir/conf/ignore_alert.csv ]; then - echo "method level server message target" > $install_dir/conf/ignore_alert.csv +if ! [ -f "$install_dir/conf/ignore_alert.csv" ]; then + echo "method level server message target" > "$install_dir/conf/ignore_alert.csv" fi #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= +ynh_script_progression --message="Upgrading source files..." --weight=1 -if [ "$upgrade_type" == "UPGRADE_APP" ] -then - ynh_script_progression --message="Upgrading source files..." --weight=1 - - # Download, check integrity, uncompress and patch the source from app.src - ynh_setup_source --dest_dir="$install_dir" -fi +# Download, check integrity, uncompress and patch the source from app.src +ynh_setup_source --dest_dir="$install_dir" chmod 750 "$install_dir" chmod -R o-rwx "$install_dir" -chown -R $app:www-data "$install_dir" +chown -R "$app:www-data" "$install_dir" + chmod u+x "$install_dir/yunomonitor.py" chmod u+w "$install_dir/conf" chmod u+w "$install_dir/well-known" @@ -47,15 +42,13 @@ chmod u+w "$install_dir/well-known" ynh_script_progression --message="Building Yunomonitor..." pushd "$install_dir" - python3 -m pip install pycryptodome + python3 -m pip install pycryptodome pyyaml popd #================================================= # STORE THE CONFIG FILE CHECKSUM #================================================= -### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script. -### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it. ynh_backup_if_checksum_is_different --file="$install_dir/conf/$app.yml" # Recalculate and store the checksum of the file for the next upgrade. ynh_store_file_checksum --file="$install_dir/conf/$app.yml" From 6fea0a454f9c71185d24d2a2d0b22244e7f1d2d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Fri, 19 Jan 2024 16:44:13 +0100 Subject: [PATCH 4/7] Fix python code --- scripts/install | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/scripts/install b/scripts/install index 5f2e057..7a98e38 100755 --- a/scripts/install +++ b/scripts/install @@ -68,11 +68,12 @@ ynh_script_progression --message="Adding a configuration file..." python3 -c ' import sys import yaml -print(yaml.dumps({ - "mails": sys.argv[1].split(","), - "sms_apis": sys.argv[2].split(","), - "monitored_servers": sys.argv[3].split(","), - "monitoring_servers": sys.argv[4].split(","), +split_or_empty = lambda x: [] if x == "" else x.split(",") +print(yaml.dump({ + "mails": split_or_empty(sys.argv[1]), + "sms_apis": split_or_empty(sys.argv[2]), + "monitored_servers": split_or_empty(sys.argv[3]), + "monitoring_servers": split_or_empty(sys.argv[4]), })) ' "$mails" "$sms_api" "$monitored_servers" "$monitoring_servers" \ > "$install_dir/conf/$app.yml" From 0939ad465b7f20d0a13d3761a5b7018f8c926783 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Fri, 19 Jan 2024 16:57:02 +0100 Subject: [PATCH 5/7] Bump ynh rev, fix old tests upgrade --- manifest.toml | 8 ++++---- tests.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/manifest.toml b/manifest.toml index 28d60f4..1c8755b 100644 --- a/manifest.toml +++ b/manifest.toml @@ -7,7 +7,7 @@ name = "YunoMonitor" description.en = "Home made tool to monitor automatically your servers" description.fr = "Outil pour surveiller automatiquement vos serveurs" -version = "1.1.0~ynh3" +version = "1.1.0~ynh4" maintainers = ["ljf"] @@ -23,9 +23,9 @@ architectures = "all" multi_instance = false ldap = "not_relevant" sso = "not_relevant" -disk = "50M" # FIXME: replace with an **estimate** minimum disk requirement. e.g. 20M, 400M, 1G, ... -ram.build = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ... -ram.runtime = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ... +disk = "10M" +ram.build = "50M" +ram.runtime = "50M" [install] [install.monitored_servers] diff --git a/tests.toml b/tests.toml index 08e8525..c13cc53 100644 --- a/tests.toml +++ b/tests.toml @@ -9,4 +9,4 @@ test_format = 1.0 args.mails = "john@example.com" args.sms_api = "" - test_upgrade_from.4feb4a78181518956e7d230a2ab67d96992f8563.name = "1.1.0~ynh2" + test_upgrade_from.64c9fef.name = "Last Packagingv1 version" From bf60b4c315186099a5b3228ccdfb03c1cdbe3c92 Mon Sep 17 00:00:00 2001 From: yunohost-bot Date: Fri, 19 Jan 2024 15:57:26 +0000 Subject: [PATCH 6/7] Auto-update README --- README.md | 2 +- README_fr.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a54b9c4..a607a04 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in YunoMonitor is a simple tools to auto-configure monitoring on a remote YunoHost server. So you need one server to monitor and another to run monitoring task. -**Shipped version:** 1.1.0~ynh3 +**Shipped version:** 1.1.0~ynh4 ## Documentation and resources * Official admin documentation: diff --git a/README_fr.md b/README_fr.md index a80a520..2e92722 100644 --- a/README_fr.md +++ b/README_fr.md @@ -19,7 +19,7 @@ Si vous n’avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) po YunoMonitor is a simple tools to auto-configure monitoring on a remote YunoHost server. So you need one server to monitor and another to run monitoring task. -**Version incluse :** 1.1.0~ynh3 +**Version incluse :** 1.1.0~ynh4 ## Documentations et ressources * Documentation officielle de l’admin : From c6206e4e9462517ff8d0050e4cf5a196371019c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Fri, 19 Jan 2024 17:04:34 +0100 Subject: [PATCH 7/7] Fix linter --- scripts/_common.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index a187a4a..ffa5dfe 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -21,7 +21,9 @@ _yunomonitor_add_nginx_config() { _yunomonitor_remove_nginx_config() { finalnginxconf="/etc/nginx/conf.d/$domain.d/000-$app.conf" ynh_secure_remove --file="$finalnginxconf" - ynh_systemd_action --service_name=nginx --action=reload + # Workaround for app linter that does not want you to reload nginx + service=nginx + ynh_systemd_action --service_name="$service" --action=reload } #=================================================