From f83d8926a1c606248ef0d54f6ed8d62256f33cbb Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 21 Apr 2020 01:54:27 +0200 Subject: [PATCH 1/9] Update dependencies --- scripts/_common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 14ee509d..f23861e7 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -9,7 +9,7 @@ pkg_dependencies="postgresql redis-server \ libfreetype6 libjpeg62-turbo libpng16-16 libxpm4 libvpx4|libvpx5 libmagickwand-6.q16-3|libmagickwand-6.q16-6 libwebp6 \ pngquant jpegoptim gifsicle" -extra_pkg_dependencies="php7.3-bcmath php7.3-cli php7.3-curl php7.3-exif php7.3-gd php7.3-intl php7.3-json php7.3-mbstring php7.3-pgsql php7.3-simplexml php7.3-xml php7.3-zip php7.3-intl" +extra_pkg_dependencies="php7.3-bcmath php7.3-ctype php7.3-curl php7.3-exif php7.3-iconv php7.3-intl php7.3-json php7.3-mbstring php7.3-openssl php7.3-tokenizer php7.3-xml php7.3-zip php7.3-pgsql" #================================================= # PERSONAL HELPERS From b40fc7aaf202f8c94745b9c29d1e33e01e9f2396 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 21 Apr 2020 02:00:48 +0200 Subject: [PATCH 2/9] updating dependencies --- scripts/_common.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index f23861e7..59d849ba 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -5,9 +5,7 @@ #================================================= # dependencies used by the app -pkg_dependencies="postgresql redis-server \ -libfreetype6 libjpeg62-turbo libpng16-16 libxpm4 libvpx4|libvpx5 libmagickwand-6.q16-3|libmagickwand-6.q16-6 libwebp6 \ -pngquant jpegoptim gifsicle" +pkg_dependencies="postgresql redis-server imagemagick jpegoptim optipng pngquant" extra_pkg_dependencies="php7.3-bcmath php7.3-ctype php7.3-curl php7.3-exif php7.3-iconv php7.3-intl php7.3-json php7.3-mbstring php7.3-openssl php7.3-tokenizer php7.3-xml php7.3-zip php7.3-pgsql" From c704b4ac20c9457e7621f764ed4e2d283cb16790 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 21 Apr 2020 02:17:36 +0200 Subject: [PATCH 3/9] Splitting ynh_composer in is own file --- scripts/_common.sh | 47 ------------------------------------ scripts/install | 1 + scripts/upgrade | 1 + scripts/ynh_composer__2 | 53 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 47 deletions(-) create mode 100644 scripts/ynh_composer__2 diff --git a/scripts/_common.sh b/scripts/_common.sh index 59d849ba..0d843eb4 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -17,53 +17,6 @@ extra_pkg_dependencies="php7.3-bcmath php7.3-ctype php7.3-curl php7.3-exif php7. # EXPERIMENTAL HELPERS #================================================= -# Execute a command with Composer -# -# usage: ynh_composer_exec --phpversion=phpversion [--workdir=$final_path] --commands="commands" -# | arg: -w, --workdir - The directory from where the command will be executed. Default $final_path. -# | arg: -c, --commands - Commands to execute. -ynh_composer_exec () { - # Declare an array to define the options of this helper. - local legacy_args=vwc - declare -Ar args_array=( [v]=phpversion= [w]=workdir= [c]=commands= ) - local phpversion - local workdir - local commands - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - workdir="${workdir:-$final_path}" - phpversion="${phpversion:-7.0}" - - COMPOSER_HOME="$workdir/.composer" \ - php${phpversion} "$workdir/composer.phar" $commands \ - -d "$workdir" --quiet --no-interaction -} - -# Install and initialize Composer in the given directory -# -# usage: ynh_install_composer --phpversion=phpversion [--workdir=$final_path] -# | arg: -w, --workdir - The directory from where the command will be executed. Default $final_path. -ynh_install_composer () { - # Declare an array to define the options of this helper. - local legacy_args=vw - declare -Ar args_array=( [v]=phpversion= [w]=workdir= ) - local phpversion - local workdir - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - workdir="${workdir:-$final_path}" - phpversion="${phpversion:-7.0}" - - curl -sS https://getcomposer.org/installer \ - | COMPOSER_HOME="$workdir/.composer" \ - php${phpversion} -- --quiet --install-dir="$workdir" \ - || ynh_die --message="Unable to install Composer." - - # update dependencies to create composer.lock - ynh_composer_exec --phpversion="${phpversion}" --workdir="$workdir" --commands="install --no-dev" \ - || ynh_die --message="Unable to update core dependencies with Composer." -} - # Install another version of php. # # usage: ynh_install_php --phpversion=phpversion [--package=packages] diff --git a/scripts/install b/scripts/install index ec93df8a..26f7611a 100644 --- a/scripts/install +++ b/scripts/install @@ -7,6 +7,7 @@ #================================================= source _common.sh +source ynh_composer__2 source /usr/share/yunohost/helpers #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index dcf158a2..05f54ba1 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -7,6 +7,7 @@ #================================================= source _common.sh +source ynh_composer__2 source /usr/share/yunohost/helpers #================================================= diff --git a/scripts/ynh_composer__2 b/scripts/ynh_composer__2 new file mode 100644 index 00000000..5c8775b0 --- /dev/null +++ b/scripts/ynh_composer__2 @@ -0,0 +1,53 @@ +#!/bin/bash + +# Execute a command with Composer +# +# usage: ynh_composer_exec [--phpversion=phpversion] [--workdir=$final_path] --commands="commands" +# | arg: -v, --phpversion - PHP version to use with composer +# | arg: -w, --workdir - The directory from where the command will be executed. Default $final_path. +# | arg: -c, --commands - Commands to execute. +ynh_composer_exec () { + # Declare an array to define the options of this helper. + local legacy_args=vwc + declare -Ar args_array=( [v]=phpversion= [w]=workdir= [c]=commands= ) + local phpversion + local workdir + local commands + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + workdir="${workdir:-$final_path}" + phpversion="${phpversion:-7.0}" + + COMPOSER_HOME="$workdir/.composer" \ + php${phpversion} "$workdir/composer.phar" $commands \ + -d "$workdir" --quiet --no-interaction +} + +# Install and initialize Composer in the given directory +# +# usage: ynh_install_composer [--phpversion=phpversion] [--workdir=$final_path] [--install_args="--optimize-autoloader"] +# | arg: -v, --phpversion - PHP version to use with composer +# | arg: -w, --workdir - The directory from where the command will be executed. Default $final_path. +# | arg: -a, --install_args - Additional arguments provided to the composer install. Argument --no-dev already include +ynh_install_composer () { + # Declare an array to define the options of this helper. + local legacy_args=vwa + declare -Ar args_array=( [v]=phpversion= [w]=workdir= [a]=install_args=) + local phpversion + local workdir + local install_args + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + workdir="${workdir:-$final_path}" + phpversion="${phpversion:-7.0}" + install_args="${install_args:-}" + + curl -sS https://getcomposer.org/installer \ + | COMPOSER_HOME="$workdir/.composer" \ + php${phpversion} -- --quiet --install-dir="$workdir" \ + || ynh_die "Unable to install Composer." + + # update dependencies to create composer.lock + ynh_composer_exec --phpversion="${phpversion}" --workdir="$workdir" --commands="install --no-dev $install_args" \ + || ynh_die "Unable to update core dependencies with Composer." +} From 1fe8e3a79ec47ee51ea2f665391d6c4cef6aa0c0 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 21 Apr 2020 02:23:35 +0200 Subject: [PATCH 4/9] Splitting ynh_install_php in is own file --- scripts/_common.sh | 77 ------------------------------------- scripts/install | 1 + scripts/remove | 1 + scripts/restore | 1 + scripts/upgrade | 1 + scripts/ynh_install_php__3 | 78 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 82 insertions(+), 77 deletions(-) create mode 100644 scripts/ynh_install_php__3 diff --git a/scripts/_common.sh b/scripts/_common.sh index 0d843eb4..94741695 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -17,83 +17,6 @@ extra_pkg_dependencies="php7.3-bcmath php7.3-ctype php7.3-curl php7.3-exif php7. # EXPERIMENTAL HELPERS #================================================= -# Install another version of php. -# -# usage: ynh_install_php --phpversion=phpversion [--package=packages] -# | arg: -v, --phpversion - Version of php to install. Can be one of 7.1, 7.2 or 7.3 -# | arg: -p, --package - Additionnal php packages to install -ynh_install_php () { - # Declare an array to define the options of this helper. - local legacy_args=vp - declare -Ar args_array=( [v]=phpversion= [p]=package= ) - local phpversion - local package - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - package=${package:-} - - # Store php_version into the config of this app - ynh_app_setting_set $app php_version $phpversion - - if [ "$phpversion" == "7.0" ] - then - ynh_die --message="Do not use ynh_install_php to install php7.0" - fi - - # Store the ID of this app and the version of php requested for it - echo "$YNH_APP_INSTANCE_NAME:$phpversion" | tee --append "/etc/php/ynh_app_version" - - # Add an extra repository for those packages - ynh_install_extra_repo --repo="https://packages.sury.org/php/ $(lsb_release -sc) main" --key="https://packages.sury.org/php/apt.gpg" --priority=995 --name=extra_php_version - - # Install requested dependencies from this extra repository. - # Install php-fpm first, otherwise php will install apache as a dependency. - ynh_add_app_dependencies --package="php${phpversion}-fpm" - ynh_add_app_dependencies --package="php$phpversion php${phpversion}-common $package" - - # Set php7.0 back as the default version for php-cli. - update-alternatives --set php /usr/bin/php7.0 - - # Pin this extra repository after packages are installed to prevent sury of doing shit - ynh_pin_repo --package="*" --pin="origin \"packages.sury.org\"" 200 --name=extra_php_version - ynh_pin_repo --package="php7.0*" --pin="origin \"packages.sury.org\"" 600 --name=extra_php_version --append - - # INTEGRATE SERVICE IN YUNOHOST - yunohost service add php${phpversion}-fpm --log "/var/log/php${phpversion}-fpm.log" -} - -ynh_remove_php () { - # Get the version of php used by this app - local phpversion=$(ynh_app_setting_get $app php_version) - - if [ "$phpversion" == "7.0" ] || [ -z "$phpversion" ] - then - if [ "$phpversion" == "7.0" ] - then - ynh_print_err "Do not use ynh_remove_php to install php7.0" - fi - return 0 - fi - - # Remove the line for this app - sed --in-place "/$YNH_APP_INSTANCE_NAME:$phpversion/d" "/etc/php/ynh_app_version" - - # If no other app uses this version of php, remove it. - if ! grep --quiet "$phpversion" "/etc/php/ynh_app_version" - then - # Purge php dependences for this version. - ynh_package_autopurge "php$phpversion php${phpversion}-fpm php${phpversion}-common" - # Remove the service from the admin panel - yunohost service remove php${phpversion}-fpm - fi - - # If no other app uses alternate php versions, remove the extra repo for php - if [ ! -s "/etc/php/ynh_app_version" ] - then - ynh_secure_remove /etc/php/ynh_app_version - fi -} - #================================================= # FUTURE OFFICIAL HELPERS #================================================= diff --git a/scripts/install b/scripts/install index 26f7611a..b331c8c4 100644 --- a/scripts/install +++ b/scripts/install @@ -8,6 +8,7 @@ source _common.sh source ynh_composer__2 +source ynh_install_php__3 source /usr/share/yunohost/helpers #================================================= diff --git a/scripts/remove b/scripts/remove index cced37cf..4fd279ac 100644 --- a/scripts/remove +++ b/scripts/remove @@ -7,6 +7,7 @@ #================================================= source _common.sh +source ynh_install_php__3 source /usr/share/yunohost/helpers #================================================= diff --git a/scripts/restore b/scripts/restore index 19b2e1fe..ee544421 100644 --- a/scripts/restore +++ b/scripts/restore @@ -8,6 +8,7 @@ #Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh +source ../settings/scripts/ynh_install_php__3 source /usr/share/yunohost/helpers #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 05f54ba1..4b76eab0 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -8,6 +8,7 @@ source _common.sh source ynh_composer__2 +source ynh_install_php__3 source /usr/share/yunohost/helpers #================================================= diff --git a/scripts/ynh_install_php__3 b/scripts/ynh_install_php__3 new file mode 100644 index 00000000..ca72f7f4 --- /dev/null +++ b/scripts/ynh_install_php__3 @@ -0,0 +1,78 @@ +#!/bin/bash + +# Install another version of php. +# +# usage: ynh_install_php --phpversion=phpversion [--package=packages] +# | arg: -v, --phpversion - Version of php to install. Can be one of 7.1, 7.2 or 7.3 +# | arg: -p, --package - Additionnal php packages to install +ynh_install_php () { + # Declare an array to define the options of this helper. + local legacy_args=vp + declare -Ar args_array=( [v]=phpversion= [p]=package= ) + local phpversion + local package + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + package=${package:-} + + # Store php_version into the config of this app + ynh_app_setting_set $app php_version $phpversion + + if [ "$phpversion" == "7.0" ] + then + ynh_die "Do not use ynh_install_php to install php7.0" + fi + + # Store the ID of this app and the version of php requested for it + echo "$YNH_APP_INSTANCE_NAME:$phpversion" | tee --append "/etc/php/ynh_app_version" + + # Add an extra repository for those packages + ynh_install_extra_repo --repo="https://packages.sury.org/php/ $(lsb_release -sc) main" --key="https://packages.sury.org/php/apt.gpg" --priority=995 --name=extra_php_version + + # Install requested dependencies from this extra repository. + # Install php-fpm first, otherwise php will install apache as a dependency. + ynh_add_app_dependencies --package="php${phpversion}-fpm" + ynh_add_app_dependencies --package="php$phpversion php${phpversion}-common $package" + + # Set php7.0 back as the default version for php-cli. + update-alternatives --set php /usr/bin/php7.0 + + # Pin this extra repository after packages are installed to prevent sury of doing shit + ynh_pin_repo --package="*" --pin="origin \"packages.sury.org\"" 200 --name=extra_php_version + ynh_pin_repo --package="php7.0*" --pin="origin \"packages.sury.org\"" 600 --name=extra_php_version --append + + # Advertise service in admin panel + yunohost service add php${phpversion}-fpm --log "/var/log/php${phpversion}-fpm.log" +} + +ynh_remove_php () { + # Get the version of php used by this app + local phpversion=$(ynh_app_setting_get $app php_version) + + if [ "$phpversion" == "7.0" ] || [ -z "$phpversion" ] + then + if [ "$phpversion" == "7.0" ] + then + ynh_print_err "Do not use ynh_remove_php to install php7.0" + fi + return 0 + fi + + # Remove the line for this app + sed --in-place "/$YNH_APP_INSTANCE_NAME:$phpversion/d" "/etc/php/ynh_app_version" + + # If no other app uses this version of php, remove it. + if ! grep --quiet "$phpversion" "/etc/php/ynh_app_version" + then + # Purge php dependences for this version. + ynh_package_autopurge "php$phpversion php${phpversion}-fpm php${phpversion}-common" + # Remove the service from the admin panel + yunohost service remove php${phpversion}-fpm + fi + + # If no other app uses alternate php versions, remove the extra repo for php + if [ ! -s "/etc/php/ynh_app_version" ] + then + ynh_secure_remove /etc/php/ynh_app_version + fi +} From 56f747d47a51ad6a92900234dd4caa2ea6e7f5bc Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 21 Apr 2020 02:27:30 +0200 Subject: [PATCH 5/9] Splitting ynh_add_extra_apt_repos in is own file --- scripts/_common.sh | 292 ---------------------------- scripts/install | 1 + scripts/remove | 1 + scripts/restore | 1 + scripts/upgrade | 1 + scripts/ynh_add_extra_apt_repos__3 | 294 +++++++++++++++++++++++++++++ 6 files changed, 298 insertions(+), 292 deletions(-) create mode 100644 scripts/ynh_add_extra_apt_repos__3 diff --git a/scripts/_common.sh b/scripts/_common.sh index 94741695..e26a1941 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -20,295 +20,3 @@ extra_pkg_dependencies="php7.3-bcmath php7.3-ctype php7.3-curl php7.3-exif php7. #================================================= # FUTURE OFFICIAL HELPERS #================================================= -# Pin a repository. -# -# usage: ynh_pin_repo --package=packages --pin=pin_filter [--priority=priority_value] [--name=name] [--append] -# | arg: -p, --package - Packages concerned by the pin. Or all, *. -# | arg: -i, --pin - Filter for the pin. -# | arg: -p, --priority - Priority for the pin -# | arg: -n, --name - Name for the files for this repo, $app as default value. -# | arg: -a, --append - Do not overwrite existing files. -# -# See https://manpages.debian.org/stretch/apt/apt_preferences.5.en.html for information about pinning. -# -ynh_pin_repo () { - # Declare an array to define the options of this helper. - local legacy_args=pirna - declare -Ar args_array=( [p]=package= [i]=pin= [r]=priority= [n]=name= [a]=append ) - local package - local pin - local priority - local name - local append - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - package="${package:-*}" - priority=${priority:-50} - name="${name:-$app}" - append=${append:-0} - - if [ $append -eq 1 ] - then - append="tee -a" - else - append="tee" - fi - - mkdir -p "/etc/apt/preferences.d" - echo "Package: $package -Pin: $pin -Pin-Priority: $priority" \ - | $append "/etc/apt/preferences.d/$name" -} - -# Add a repository. -# -# usage: ynh_add_repo --uri=uri --suite=suite --component=component [--name=name] [--append] -# | arg: -u, --uri - Uri of the repository. -# | arg: -s, --suite - Suite of the repository. -# | arg: -c, --component - Component of the repository. -# | arg: -n, --name - Name for the files for this repo, $app as default value. -# | arg: -a, --append - Do not overwrite existing files. -# -# Example for a repo like deb http://forge.yunohost.org/debian/ stretch stable -# uri suite component -# ynh_add_repo --uri=http://forge.yunohost.org/debian/ --suite=stretch --component=stable -# -ynh_add_repo () { - # Declare an array to define the options of this helper. - local legacy_args=uscna - declare -Ar args_array=( [u]=uri= [s]=suite= [c]=component= [n]=name= [a]=append ) - local uri - local suite - local component - local name - local append - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - name="${name:-$app}" - append=${append:-0} - - if [ $append -eq 1 ] - then - append="tee -a" - else - append="tee" - fi - - mkdir -p "/etc/apt/sources.list.d" - # Add the new repo in sources.list.d - echo "deb $uri $suite $component" \ - | $append "/etc/apt/sources.list.d/$name.list" -} - -# Add an extra repository correctly, pin it and get the key. -# -# usage: ynh_install_extra_repo --repo="repo" [--key=key_url] [--priority=priority_value] [--name=name] [--append] -# | arg: -r, --repo - Complete url of the extra repository. -# | arg: -k, --key - url to get the public key. -# | arg: -p, --priority - Priority for the pin -# | arg: -n, --name - Name for the files for this repo, $app as default value. -# | arg: -a, --append - Do not overwrite existing files. -ynh_install_extra_repo () { - # Declare an array to define the options of this helper. - local legacy_args=rkpna - declare -Ar args_array=( [r]=repo= [k]=key= [p]=priority= [n]=name= [a]=append ) - local repo - local key - local priority - local name - local append - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - name="${name:-$app}" - append=${append:-0} - key=${key:-0} - priority=${priority:-} - - if [ $append -eq 1 ] - then - append="--append" - wget_append="tee -a" - else - append="" - wget_append="tee" - fi - - # Split the repository into uri, suite and components. - # Remove "deb " at the beginning of the repo. - repo="${repo#deb }" - - # Get the uri - local uri="$(echo "$repo" | awk '{ print $1 }')" - - # Get the suite - local suite="$(echo "$repo" | awk '{ print $2 }')" - - # Get the components - local component="${repo##$uri $suite }" - - # Add the repository into sources.list.d - ynh_add_repo --uri="$uri" --suite="$suite" --component="$component" --name="$name" $append - - # Pin the new repo with the default priority, so it won't be used for upgrades. - # Build $pin from the uri without http and any sub path - local pin="${uri#*://}" - pin="${pin%%/*}" - # Set a priority only if asked - if [ -n "$priority" ] - then - priority="--priority=$priority" - fi - ynh_pin_repo --package="*" --pin="origin \"$pin\"" $priority --name="$name" $append - - # Get the public key for the repo - if [ -n "$key" ] - then - mkdir -p "/etc/apt/trusted.gpg.d" - wget -q "$key" -O - | gpg --dearmor | $wget_append /etc/apt/trusted.gpg.d/$name.gpg > /dev/null - fi - - # Update the list of package with the new repo - ynh_package_update -} - -# Remove an extra repository and the assiociated configuration. -# -# usage: ynh_remove_extra_repo [--name=name] -# | arg: -n, --name - Name for the files for this repo, $app as default value. -ynh_remove_extra_repo () { - # Declare an array to define the options of this helper. - local legacy_args=n - declare -Ar args_array=( [n]=name= ) - local name - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - name="${name:-$app}" - - ynh_secure_remove "/etc/apt/sources.list.d/$name.list" - ynh_secure_remove "/etc/apt/preferences.d/$name" - ynh_secure_remove "/etc/apt/trusted.gpg.d/$name.gpg" - ynh_secure_remove "/etc/apt/trusted.gpg.d/$name.asc" - - # Update the list of package to exclude the old repo - ynh_package_update -} - -# Install packages from an extra repository properly. -# -# usage: ynh_install_extra_app_dependencies --repo="repo" --package="dep1 dep2" [--key=key_url] [--name=name] -# | arg: -r, --repo - Complete url of the extra repository. -# | arg: -p, --package - The packages to install from this extra repository -# | arg: -k, --key - url to get the public key. -# | arg: -n, --name - Name for the files for this repo, $app as default value. -ynh_install_extra_app_dependencies () { - # Declare an array to define the options of this helper. - local legacy_args=rpkn - declare -Ar args_array=( [r]=repo= [p]=package= [k]=key= [n]=name= ) - local repo - local package - local key - local name - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - name="${name:-$app}" - key=${key:-0} - - # Set a key only if asked - if [ -n "$key" ] - then - key="--key=$key" - fi - # Add an extra repository for those packages - ynh_install_extra_repo --repo="$repo" $key --priority=995 --name=$name - - # Install requested dependencies from this extra repository. - ynh_add_app_dependencies --package="$package" - - # Remove this extra repository after packages are installed - ynh_remove_extra_repo --name=$app -} - -#================================================= - -# patched version of ynh_install_app_dependencies to be used with ynh_add_app_dependencies - -# Define and install dependencies with a equivs control file -# This helper can/should only be called once per app -# -# usage: ynh_install_app_dependencies dep [dep [...]] -# | arg: dep - the package name to install in dependence -# You can give a choice between some package with this syntax : "dep1|dep2" -# Example : ynh_install_app_dependencies dep1 dep2 "dep3|dep4|dep5" -# This mean in the dependence tree : dep1 & dep2 & (dep3 | dep4 | dep5) -# -# Requires YunoHost version 2.6.4 or higher. -ynh_install_app_dependencies () { - local dependencies=$@ - dependencies="$(echo "$dependencies" | sed 's/\([^\<=\>]\)\ \([^(]\)/\1, \2/g')" - dependencies=${dependencies//|/ | } - local manifest_path="../manifest.json" - if [ ! -e "$manifest_path" ]; then - manifest_path="../settings/manifest.json" # Into the restore script, the manifest is not at the same place - fi - - local version=$(grep '\"version\": ' "$manifest_path" | cut -d '"' -f 4) # Retrieve the version number in the manifest file. - if [ ${#version} -eq 0 ]; then - version="1.0" - fi - local dep_app=${app//_/-} # Replace all '_' by '-' - - # Handle specific versions - if [[ "$dependencies" =~ [\<=\>] ]] - then - # Replace version specifications by relationships syntax - # https://www.debian.org/doc/debian-policy/ch-relationships.html - # Sed clarification - # [^(\<=\>] ignore if it begins by ( or < = >. To not apply twice. - # [\<=\>] matches < = or > - # \+ matches one or more occurence of the previous characters, for >= or >>. - # [^,]\+ matches all characters except ',' - # Ex: package>=1.0 will be replaced by package (>= 1.0) - dependencies="$(echo "$dependencies" | sed 's/\([^(\<=\>]\)\([\<=\>]\+\)\([^,]\+\)/\1 (\2 \3)/g')" - fi - - cat > /tmp/${dep_app}-ynh-deps.control << EOF # Make a control file for equivs-build -Section: misc -Priority: optional -Package: ${dep_app}-ynh-deps -Version: ${version} -Depends: ${dependencies} -Architecture: all -Description: Fake package for $app (YunoHost app) dependencies - This meta-package is only responsible of installing its dependencies. -EOF - ynh_package_install_from_equivs /tmp/${dep_app}-ynh-deps.control \ - || ynh_die --message="Unable to install dependencies" # Install the fake package and its dependencies - rm /tmp/${dep_app}-ynh-deps.control - ynh_app_setting_set --app=$app --key=apt_dependencies --value="$dependencies" -} - -ynh_add_app_dependencies () { - # Declare an array to define the options of this helper. - local legacy_args=pr - declare -Ar args_array=( [p]=package= [r]=replace) - local package - local replace - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - replace=${replace:-0} - - local current_dependencies="" - if [ $replace -eq 0 ] - then - local dep_app=${app//_/-} # Replace all '_' by '-' - if ynh_package_is_installed --package="${dep_app}-ynh-deps" - then - current_dependencies="$(dpkg-query --show --showformat='${Depends}' ${dep_app}-ynh-deps) " - fi - - current_dependencies=${current_dependencies// | /|} - fi - - ynh_install_app_dependencies "${current_dependencies}${package}" -} diff --git a/scripts/install b/scripts/install index b331c8c4..4466a2b2 100644 --- a/scripts/install +++ b/scripts/install @@ -8,6 +8,7 @@ source _common.sh source ynh_composer__2 +source ynh_add_extra_apt_repos__3 source ynh_install_php__3 source /usr/share/yunohost/helpers diff --git a/scripts/remove b/scripts/remove index 4fd279ac..7ba06c6f 100644 --- a/scripts/remove +++ b/scripts/remove @@ -7,6 +7,7 @@ #================================================= source _common.sh +source ynh_add_extra_apt_repos__3 source ynh_install_php__3 source /usr/share/yunohost/helpers diff --git a/scripts/restore b/scripts/restore index ee544421..15192fba 100644 --- a/scripts/restore +++ b/scripts/restore @@ -8,6 +8,7 @@ #Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh +source ../settings/scripts/ynh_add_extra_apt_repos__3 source ../settings/scripts/ynh_install_php__3 source /usr/share/yunohost/helpers diff --git a/scripts/upgrade b/scripts/upgrade index 4b76eab0..95826f98 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -8,6 +8,7 @@ source _common.sh source ynh_composer__2 +source ynh_add_extra_apt_repos__3 source ynh_install_php__3 source /usr/share/yunohost/helpers diff --git a/scripts/ynh_add_extra_apt_repos__3 b/scripts/ynh_add_extra_apt_repos__3 new file mode 100644 index 00000000..3276f003 --- /dev/null +++ b/scripts/ynh_add_extra_apt_repos__3 @@ -0,0 +1,294 @@ +#!/bin/bash + +# Pin a repository. +# +# usage: ynh_pin_repo --package=packages --pin=pin_filter [--priority=priority_value] [--name=name] [--append] +# | arg: -p, --package - Packages concerned by the pin. Or all, *. +# | arg: -i, --pin - Filter for the pin. +# | arg: -p, --priority - Priority for the pin +# | arg: -n, --name - Name for the files for this repo, $app as default value. +# | arg: -a, --append - Do not overwrite existing files. +# +# See https://manpages.debian.org/stretch/apt/apt_preferences.5.en.html for information about pinning. +# +ynh_pin_repo () { + # Declare an array to define the options of this helper. + local legacy_args=pirna + declare -Ar args_array=( [p]=package= [i]=pin= [r]=priority= [n]=name= [a]=append ) + local package + local pin + local priority + local name + local append + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + package="${package:-*}" + priority=${priority:-50} + name="${name:-$app}" + append=${append:-0} + + if [ $append -eq 1 ] + then + append="tee -a" + else + append="tee" + fi + + mkdir -p "/etc/apt/preferences.d" + echo "Package: $package +Pin: $pin +Pin-Priority: $priority" \ + | $append "/etc/apt/preferences.d/$name" +} + +# Add a repository. +# +# usage: ynh_add_repo --uri=uri --suite=suite --component=component [--name=name] [--append] +# | arg: -u, --uri - Uri of the repository. +# | arg: -s, --suite - Suite of the repository. +# | arg: -c, --component - Component of the repository. +# | arg: -n, --name - Name for the files for this repo, $app as default value. +# | arg: -a, --append - Do not overwrite existing files. +# +# Example for a repo like deb http://forge.yunohost.org/debian/ stretch stable +# uri suite component +# ynh_add_repo --uri=http://forge.yunohost.org/debian/ --suite=stretch --component=stable +# +ynh_add_repo () { + # Declare an array to define the options of this helper. + local legacy_args=uscna + declare -Ar args_array=( [u]=uri= [s]=suite= [c]=component= [n]=name= [a]=append ) + local uri + local suite + local component + local name + local append + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + name="${name:-$app}" + append=${append:-0} + + if [ $append -eq 1 ] + then + append="tee -a" + else + append="tee" + fi + + mkdir -p "/etc/apt/sources.list.d" + # Add the new repo in sources.list.d + echo "deb $uri $suite $component" \ + | $append "/etc/apt/sources.list.d/$name.list" +} + +# Add an extra repository correctly, pin it and get the key. +# +# usage: ynh_install_extra_repo --repo="repo" [--key=key_url] [--priority=priority_value] [--name=name] [--append] +# | arg: -r, --repo - Complete url of the extra repository. +# | arg: -k, --key - url to get the public key. +# | arg: -p, --priority - Priority for the pin +# | arg: -n, --name - Name for the files for this repo, $app as default value. +# | arg: -a, --append - Do not overwrite existing files. +ynh_install_extra_repo () { + # Declare an array to define the options of this helper. + local legacy_args=rkpna + declare -Ar args_array=( [r]=repo= [k]=key= [p]=priority= [n]=name= [a]=append ) + local repo + local key + local priority + local name + local append + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + name="${name:-$app}" + append=${append:-0} + key=${key:-0} + priority=${priority:-} + + if [ $append -eq 1 ] + then + append="--append" + wget_append="tee -a" + else + append="" + wget_append="tee" + fi + + # Split the repository into uri, suite and components. + # Remove "deb " at the beginning of the repo. + repo="${repo#deb }" + + # Get the uri + local uri="$(echo "$repo" | awk '{ print $1 }')" + + # Get the suite + local suite="$(echo "$repo" | awk '{ print $2 }')" + + # Get the components + local component="${repo##$uri $suite }" + + # Add the repository into sources.list.d + ynh_add_repo --uri="$uri" --suite="$suite" --component="$component" --name="$name" $append + + # Pin the new repo with the default priority, so it won't be used for upgrades. + # Build $pin from the uri without http and any sub path + local pin="${uri#*://}" + pin="${pin%%/*}" + # Set a priority only if asked + if [ -n "$priority" ] + then + priority="--priority=$priority" + fi + ynh_pin_repo --package="*" --pin="origin \"$pin\"" $priority --name="$name" $append + + # Get the public key for the repo + if [ -n "$key" ] + then + mkdir -p "/etc/apt/trusted.gpg.d" + wget -q "$key" -O - | gpg --dearmor | $wget_append /etc/apt/trusted.gpg.d/$name.gpg > /dev/null + fi + + # Update the list of package with the new repo + ynh_package_update +} + +# Remove an extra repository and the assiociated configuration. +# +# usage: ynh_remove_extra_repo [--name=name] +# | arg: -n, --name - Name for the files for this repo, $app as default value. +ynh_remove_extra_repo () { + # Declare an array to define the options of this helper. + local legacy_args=n + declare -Ar args_array=( [n]=name= ) + local name + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + name="${name:-$app}" + + ynh_secure_remove "/etc/apt/sources.list.d/$name.list" + ynh_secure_remove "/etc/apt/preferences.d/$name" + ynh_secure_remove "/etc/apt/trusted.gpg.d/$name.gpg" + ynh_secure_remove "/etc/apt/trusted.gpg.d/$name.asc" + + # Update the list of package to exclude the old repo + ynh_package_update +} + +# Install packages from an extra repository properly. +# +# usage: ynh_install_extra_app_dependencies --repo="repo" --package="dep1 dep2" [--key=key_url] [--name=name] +# | arg: -r, --repo - Complete url of the extra repository. +# | arg: -p, --package - The packages to install from this extra repository +# | arg: -k, --key - url to get the public key. +# | arg: -n, --name - Name for the files for this repo, $app as default value. +ynh_install_extra_app_dependencies () { + # Declare an array to define the options of this helper. + local legacy_args=rpkn + declare -Ar args_array=( [r]=repo= [p]=package= [k]=key= [n]=name= ) + local repo + local package + local key + local name + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + name="${name:-$app}" + key=${key:-0} + + # Set a key only if asked + if [ -n "$key" ] + then + key="--key=$key" + fi + # Add an extra repository for those packages + ynh_install_extra_repo --repo="$repo" $key --priority=995 --name=$name + + # Install requested dependencies from this extra repository. + ynh_add_app_dependencies --package="$package" + + # Remove this extra repository after packages are installed + ynh_remove_extra_repo --name=$app +} + +#================================================= + +# patched version of ynh_install_app_dependencies to be used with ynh_add_app_dependencies + +# Define and install dependencies with a equivs control file +# This helper can/should only be called once per app +# +# usage: ynh_install_app_dependencies dep [dep [...]] +# | arg: dep - the package name to install in dependence +# You can give a choice between some package with this syntax : "dep1|dep2" +# Example : ynh_install_app_dependencies dep1 dep2 "dep3|dep4|dep5" +# This mean in the dependence tree : dep1 & dep2 & (dep3 | dep4 | dep5) +# +# Requires YunoHost version 2.6.4 or higher. +ynh_install_app_dependencies () { + local dependencies=$@ + dependencies="$(echo "$dependencies" | sed 's/\([^\<=\>]\)\ \([^(]\)/\1, \2/g')" + dependencies=${dependencies//|/ | } + local manifest_path="../manifest.json" + if [ ! -e "$manifest_path" ]; then + manifest_path="../settings/manifest.json" # Into the restore script, the manifest is not at the same place + fi + + local version=$(grep '\"version\": ' "$manifest_path" | cut -d '"' -f 4) # Retrieve the version number in the manifest file. + if [ ${#version} -eq 0 ]; then + version="1.0" + fi + local dep_app=${app//_/-} # Replace all '_' by '-' + + # Handle specific versions + if [[ "$dependencies" =~ [\<=\>] ]] + then + # Replace version specifications by relationships syntax + # https://www.debian.org/doc/debian-policy/ch-relationships.html + # Sed clarification + # [^(\<=\>] ignore if it begins by ( or < = >. To not apply twice. + # [\<=\>] matches < = or > + # \+ matches one or more occurence of the previous characters, for >= or >>. + # [^,]\+ matches all characters except ',' + # Ex: package>=1.0 will be replaced by package (>= 1.0) + dependencies="$(echo "$dependencies" | sed 's/\([^(\<=\>]\)\([\<=\>]\+\)\([^,]\+\)/\1 (\2 \3)/g')" + fi + + cat > /tmp/${dep_app}-ynh-deps.control << EOF # Make a control file for equivs-build +Section: misc +Priority: optional +Package: ${dep_app}-ynh-deps +Version: ${version} +Depends: ${dependencies} +Architecture: all +Description: Fake package for $app (YunoHost app) dependencies + This meta-package is only responsible of installing its dependencies. +EOF + ynh_package_install_from_equivs /tmp/${dep_app}-ynh-deps.control \ + || ynh_die --message="Unable to install dependencies" # Install the fake package and its dependencies + rm /tmp/${dep_app}-ynh-deps.control + ynh_app_setting_set --app=$app --key=apt_dependencies --value="$dependencies" +} + +ynh_add_app_dependencies () { + # Declare an array to define the options of this helper. + local legacy_args=pr + declare -Ar args_array=( [p]=package= [r]=replace) + local package + local replace + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + replace=${replace:-0} + + local current_dependencies="" + if [ $replace -eq 0 ] + then + local dep_app=${app//_/-} # Replace all '_' by '-' + if ynh_package_is_installed --package="${dep_app}-ynh-deps" + then + current_dependencies="$(dpkg-query --show --showformat='${Depends}' ${dep_app}-ynh-deps) " + fi + + current_dependencies=${current_dependencies// | /|} + fi + + ynh_install_app_dependencies "${current_dependencies}${package}" +} From 496f080193f9b85ad0e571b431f0d37c0ef03306 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 21 Apr 2020 05:44:31 +0200 Subject: [PATCH 6/9] Replacing horizon systemd service by supervisor --- check_process | 2 + conf/horizon.conf | 9 +++ conf/horizon.service | 14 ---- manifest.json | 2 +- scripts/_common.sh | 5 +- scripts/backup | 26 +++--- scripts/change_url | 14 ++++ scripts/install | 34 ++++++-- scripts/remove | 25 +++++- scripts/restore | 31 ++++++-- scripts/upgrade | 73 ++++++++++++----- scripts/ynh_supervisor | 177 +++++++++++++++++++++++++++++++++++++++++ 12 files changed, 348 insertions(+), 64 deletions(-) create mode 100644 conf/horizon.conf delete mode 100644 conf/horizon.service create mode 100644 scripts/ynh_supervisor diff --git a/check_process b/check_process index ed1eab47..0da03b43 100644 --- a/check_process +++ b/check_process @@ -14,6 +14,8 @@ # upgrade=1 from_commit=605a47aac7553fdcc6012531ee67add8dbe37b97 # 0.10.7 # upgrade=1 from_commit=7fa86c3e6e6db6668be0a165213d554850b9fce8 + # 0.10.8 + upgrade=1 from_commit=10c3703567d1e9504ea4f298778464c7dd561470 backup_restore=1 multi_instance=1 # This test is no longer necessary since the version 2.7 (PR: https://github.com/YunoHost/yunohost/pull/304), you can still do it if your app could be installed with this version. diff --git a/conf/horizon.conf b/conf/horizon.conf new file mode 100644 index 00000000..0b7996cd --- /dev/null +++ b/conf/horizon.conf @@ -0,0 +1,9 @@ +[program:__APP__-horizon] +process_name=%(program_name)s +command=php7.3 __FINALPATH__/artisan horizon +autostart=true +autorestart=true +user=__APP__ +redirect_stderr=true +stdout_logfile=/var/log/__APP__/__APP__-horizon.log +stopwaitsecs=3600 \ No newline at end of file diff --git a/conf/horizon.service b/conf/horizon.service deleted file mode 100644 index eb53dfd2..00000000 --- a/conf/horizon.service +++ /dev/null @@ -1,14 +0,0 @@ -[Unit] -Description=__APP__ Horizon Service -After=network.target - -[Service] -Type=simple -User=__APP__ -Group=__APP__ -WorkingDirectory=__FINALPATH__/ -ExecStart=/usr/bin/php7.3 __FINALPATH__/artisan horizon -Restart=on-failure - -[Install] -WantedBy=multi-user.target diff --git a/manifest.json b/manifest.json index 6c543005..b89b30dd 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "ActivityPub Federated Image Sharing", "fr": "Logiciel de partage d'image fédéré via ActivityPub" }, - "version": "0.10.9~ynh1", + "version": "0.10.9~ynh2", "url": "https://pixelfed.org/", "license": "AGPL-3.0-or-later", "maintainer": [ diff --git a/scripts/_common.sh b/scripts/_common.sh index e26a1941..f644938f 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -5,9 +5,10 @@ #================================================= # dependencies used by the app -pkg_dependencies="postgresql redis-server imagemagick jpegoptim optipng pngquant" +pkg_dependencies="postgresql redis-server imagemagick jpegoptim optipng pngquant supervisor" -extra_pkg_dependencies="php7.3-bcmath php7.3-ctype php7.3-curl php7.3-exif php7.3-iconv php7.3-intl php7.3-json php7.3-mbstring php7.3-openssl php7.3-tokenizer php7.3-xml php7.3-zip php7.3-pgsql" +extra_pkg_dependencies="php7.3-bcmath php7.3-ctype php7.3-curl php7.3-exif php7.3-iconv php7.3-intl php7.3-json php7.3-mbstring php7.3-tokenizer php7.3-xml php7.3-zip php7.3-pgsql" +# php7.3-openssl #================================================= # PERSONAL HELPERS diff --git a/scripts/backup b/scripts/backup index 8c6b7521..057cb238 100644 --- a/scripts/backup +++ b/scripts/backup @@ -8,6 +8,7 @@ #Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh +source ../settings/scripts/ynh_supervisor source /usr/share/yunohost/helpers #================================================= @@ -35,11 +36,11 @@ db_name=$(ynh_app_setting_get --app="$app" --key=db_name) #================================================= # STANDARD BACKUP STEPS #================================================= -# STOP SYSTEMD SERVICE +# STOP SUPERVISOR SERVICE #================================================= -ynh_print_info --message="Stopping a systemd service..." +ynh_print_info --message="Stopping a supervisor service..." -ynh_systemd_action --service_name="${app}-horizon" --action="stop" --log_path=systemd +ynh_supervisor_action --service_name="${app}-horizon" --action="stop" --log_path="/var/log/$app/${app}-horizon.log" #================================================= # BACKUP THE APP MAIN DIR @@ -72,18 +73,25 @@ ynh_psql_dump_db --database="$db_name" > db.sql #================================================= # SPECIFIC BACKUP #================================================= -# BACKUP SYSTEMD +# BACKUP LOGROTATE #================================================= -ynh_print_info --message="Backing up systemd configuration..." +ynh_print_info --message="Backing up logrotate configuration..." -ynh_backup --src_path="/etc/systemd/system/${app}-horizon.service" +ynh_backup --src_path="/etc/logrotate.d/$app" #================================================= -# START SYSTEMD SERVICE +# BACKUP SUPERVISOR #================================================= -ynh_print_info --message="Starting a systemd service..." +ynh_print_info --message="Backing up supervisor configuration..." -ynh_systemd_action --service_name="${app}-horizon" --action="start" --log_path=systemd +ynh_backup --src_path="/etc/supervisor/conf.d/${app}-horizon.conf" + +#================================================= +# START SUPERVISOR SERVICE +#================================================= +ynh_print_info --message="Starting a supervisor service..." + +ynh_supervisor_action --service_name="${app}-horizon" --action="start" --log_path="/var/log/$app/${app}-horizon.log" #================================================= # END OF SCRIPT diff --git a/scripts/change_url b/scripts/change_url index e541478d..946f8232 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -64,6 +64,13 @@ fi #================================================= # STANDARD MODIFICATIONS +#================================================= +# STOP SUPERVISOR SERVICE +#================================================= +ynh_print_info --message="Stopping a supervisor service..." + +ynh_supervisor_action --service_name="${app}-horizon" --action="stop" --log_path="/var/log/$app/${app}-horizon.log" + #================================================= # MODIFY URL IN NGINX CONF #================================================= @@ -119,6 +126,13 @@ popd #================================================= # GENERIC FINALISATION +#================================================= +# START SUPERVISOR SERVICE +#================================================= +ynh_print_info --message="Starting a supervisor service..." + +ynh_supervisor_action --service_name="${app}-horizon" --action="start" --log_path="/var/log/$app/${app}-horizon.log" + #================================================= # RELOAD NGINX #================================================= diff --git a/scripts/install b/scripts/install index 4466a2b2..f34c2c6e 100644 --- a/scripts/install +++ b/scripts/install @@ -10,6 +10,7 @@ source _common.sh source ynh_composer__2 source ynh_add_extra_apt_repos__3 source ynh_install_php__3 +source ynh_supervisor source /usr/share/yunohost/helpers #================================================= @@ -138,12 +139,21 @@ ynh_install_composer --phpversion="7.3" --workdir="$final_path" #================================================= # SPECIFIC SETUP #================================================= -# SETUP SYSTEMD +# CREATE LOG FILE #================================================= -ynh_print_info --message="Configuring a systemd service..." +ynh_print_info --message="Creating log file..." -# Create a dedicated systemd config -ynh_add_systemd_config --service="${app}-horizon" --template=horizon.service +mkdir -p "/var/log/$app/" +touch "/var/log/$app/${app}-horizon.log" +chown -R root: "/var/log/$app/" + +#================================================= +# SETUP SUPERVISOR +#================================================= +ynh_print_info --message="Configuring a supervisor service..." + +# Create a dedicated supervisor config +ynh_add_supervisor_config --service="${app}-horizon" --template=horizon.conf #================================================= # MODIFY A CONFIG FILE @@ -199,6 +209,14 @@ ynh_print_info --message="Securing files and directories..." chown -R root: "$final_path" chown -R "$app": "$final_path/storage/" +#================================================= +# SETUP LOGROTATE +#================================================= +ynh_print_info --message="Configuring log rotation..." + +# Use logrotate to manage application logfile(s) +ynh_use_logrotate --logfile="/var/log/$app/${app}-horizon.log" + #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= @@ -207,12 +225,12 @@ ynh_print_info --message="Integrating service in YunoHost..." yunohost service add "${app}-horizon" --description "${app}-horizon daemon for $app" --log "/var/log/$app/${app}-horizon.log" #================================================= -# START SYSTEMD SERVICE +# START SUPERVISOR SERVICE #================================================= -ynh_print_info --message="Starting a systemd service..." +ynh_print_info --message="Starting a supervisor service..." -# Start a systemd service -ynh_systemd_action --service_name="${app}-horizon" --action="start" --log_path=systemd +# Start a supervisor service +ynh_supervisor_action --service_name="${app}-horizon" --action="start" --log_path="/var/log/$app/${app}-horizon.log" --line_match="Horizon started successfully" #================================================= # SETUP SSOWAT diff --git a/scripts/remove b/scripts/remove index e73ea107..7a7fd426 100644 --- a/scripts/remove +++ b/scripts/remove @@ -9,6 +9,7 @@ source _common.sh source ynh_add_extra_apt_repos__3 source ynh_install_php__3 +source ynh_supervisor source /usr/share/yunohost/helpers #================================================= @@ -40,10 +41,10 @@ fi #================================================= # STOP AND REMOVE SERVICE #================================================= -ynh_print_info --message="Stopping and removing the systemd service..." +ynh_print_info --message="Stopping and removing the supervisor service..." -# Remove the dedicated systemd config -ynh_remove_systemd_config --service="${app}-horizon" +# Remove the dedicated supervisor config +ynh_remove_supervisor_config --service="${app}-horizon" #================================================= # REMOVE THE POSTGRESQL DATABASE @@ -88,6 +89,24 @@ ynh_print_info --message="Removing php-fpm configuration..." # Remove the dedicated php-fpm config ynh_remove_fpm_config +#================================================= +# REMOVE LOGROTATE CONFIGURATION +#================================================= +ynh_print_info --message="Removing logrotate configuration..." + +# Remove the app-specific logrotate config +ynh_remove_logrotate + +#================================================= +# SPECIFIC REMOVE +#================================================= +# REMOVE THE LOG FILE +#================================================= +ynh_print_info --message="Removing the log file..." + +# Remove the log files +ynh_secure_remove --file="/var/log/$app" + #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/restore b/scripts/restore index 15192fba..7882de6a 100644 --- a/scripts/restore +++ b/scripts/restore @@ -10,6 +10,7 @@ source ../settings/scripts/_common.sh source ../settings/scripts/ynh_add_extra_apt_repos__3 source ../settings/scripts/ynh_install_php__3 +source ../settings/scripts/ynh_supervisor source /usr/share/yunohost/helpers #================================================= @@ -117,12 +118,21 @@ ynh_psql_setup_db --db_user="$db_user" --db_name="$db_name" --db_pwd="$db_pwd" ynh_psql_execute_file_as_root --file="./db.sql" --database="$db_name" #================================================= -# RESTORE SYSTEMD +# CREATE LOG FILE #================================================= -ynh_print_info --message="Restoring the systemd configuration..." +ynh_print_info --message="Creating log file..." -ynh_restore_file --origin_path="/etc/systemd/system/${app}-horizon.service" -systemctl enable ${app}-horizon.service +mkdir -p "/var/log/$app/" +touch "/var/log/$app/${app}-horizon.log" +chown -R root: "/var/log/$app/" + +#================================================= +# RESTORE SUPERVISOR +#================================================= +ynh_print_info --message="Restoring the supervisor configuration..." + +ynh_restore_file --origin_path="/etc/supervisor/conf.d/${app}-horizon.conf" +supervisorctl reread && supervisorctl update #================================================= # INTEGRATE SERVICE IN YUNOHOST @@ -132,11 +142,18 @@ ynh_print_info --message="Integrating service in YunoHost..." yunohost service add "${app}-horizon" --log "/var/log/$app/${app}-horizon.log" #================================================= -# START SYSTEMD SERVICE +# START SUPERVISOR SERVICE #================================================= -ynh_print_info --message="Starting a systemd service..." +ynh_print_info --message="Starting a supervisor service..." -ynh_systemd_action --service_name="${app}-horizon" --action="start" --log_path=systemd +ynh_supervisor_action --service_name="${app}-horizon" --action="start" --log_path="/var/log/$app/${app}-horizon.log" + +#================================================= +# RESTORE THE LOGROTATE CONFIGURATION +#================================================= +ynh_print_info --message="Restoring the logrotate configuration..." + +ynh_restore_file --origin_path="/etc/logrotate.d/$app" #================================================= # GENERIC FINALIZATION diff --git a/scripts/upgrade b/scripts/upgrade index 95826f98..cbe5aed8 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -10,6 +10,7 @@ source _common.sh source ynh_composer__2 source ynh_add_extra_apt_repos__3 source ynh_install_php__3 +source ynh_supervisor source /usr/share/yunohost/helpers #================================================= @@ -63,16 +64,6 @@ if [ -z "$final_path" ]; then ynh_app_setting_set --app="$app" --key=final_path --value="$final_path" fi -# If app_key doesn't exist, retrieve it -if [ -z "$app_key" ]; then - app_key=$(grep -oP "APP_KEY=\Kbase64.*" "$final_path/.env") - ynh_app_setting_set --app="$app" --key=app_key --value="$app_key" -fi - -if dpkg --compare-versions "0.9.0~ynh3" gt "$(ynh_read_manifest --manifest="/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" --manifest_key="version" || echo 1.0)" ; then - ynh_add_systemd_config --service="${app}-horizon" --template=horizon.service -fi - #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= @@ -87,14 +78,39 @@ ynh_clean_setup () { # Exit if an error occurs during the execution of the script ynh_abort_if_errors +#================================================= +# ENSURE UPGRADE COMPATIBILITY +#================================================= +ynh_print_info --message="Ensuring upgrade compatibility..." + +# If app_key doesn't exist, retrieve it +if [ -z "$app_key" ]; then + app_key=$(grep -oP "APP_KEY=\Kbase64.*" "$final_path/.env") + ynh_app_setting_set --app="$app" --key=app_key --value="$app_key" +fi + +if dpkg --compare-versions "0.9.0~ynh3" gt "$(ynh_read_manifest --manifest="/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" --manifest_key="version" || echo 1.0)" ; then + ynh_add_systemd_config --service="${app}-horizon" --template=horizon.service +fi + +if dpkg --compare-versions "0.10.9~ynh2" gt "$(ynh_read_manifest --manifest="/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" --manifest_key="version" || echo 1.0)" ; then + ynh_remove_systemd_config --service="${app}-horizon" + ynh_install_app_dependencies "$pkg_dependencies" + mkdir -p "/var/log/$app/" + touch "/var/log/$app/${app}-horizon.log" + chown -R root: "/var/log/$app/" + ynh_add_supervisor_config --service="${app}-horizon" --template=horizon.conf + ynh_supervisor_action --service_name="${app}-horizon" --action="start" --log_path="/var/log/$app/${app}-horizon.log" +fi + #================================================= # STANDARD UPGRADE STEPS #================================================= -# STOP SYSTEMD SERVICE +# STOP SUPERVISOR SERVICE #================================================= -ynh_print_info --message="Stopping a systemd service..." +ynh_print_info --message="Stopping a supervisor service..." -ynh_systemd_action --service_name="${app}-horizon" --action="stop" --log_path=systemd +ynh_supervisor_action --service_name="${app}-horizon" --action="stop" --log_path="/var/log/$app/${app}-horizon.log" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE @@ -202,12 +218,29 @@ pushd "$final_path" popd #================================================= -# SETUP SYSTEMD +# CREATE LOG FILE #================================================= -ynh_print_info --message="Upgrading systemd configuration..." +ynh_print_info --message="Creating log file..." -# Create a dedicated systemd config -ynh_add_systemd_config --service="${app}-horizon" --template=horizon.service +mkdir -p "/var/log/$app/" +touch "/var/log/$app/${app}-horizon.log" +chown -R root: "/var/log/$app/" + +#================================================= +# SETUP LOGROTATE +#================================================= +ynh_script_progression --message="Upgrading logrotate configuration..." --time --weight=1 + +# Use logrotate to manage app-specific logfile(s) +ynh_use_logrotate --non-append + +#================================================= +# SETUP SUPERVISOR +#================================================= +ynh_print_info --message="Upgrading supervisor configuration..." + +# Create a dedicated supervisor config +ynh_add_supervisor_config --service="${app}-horizon" --template=horizon.service #================================================= # GENERIC FINALIZATION @@ -232,11 +265,11 @@ then fi #================================================= -# START SYSTEMD SERVICE +# START SUPERVISOR SERVICE #================================================= -ynh_print_info --message="Starting a systemd service..." +ynh_print_info --message="Starting a supervisor service..." -ynh_systemd_action --service_name="${app}-horizon" --action="start" --log_path=systemd +ynh_supervisor_action --service_name="${app}-horizon" --action="start" --log_path="/var/log/$app/${app}-horizon.log" #================================================= # RELOAD NGINX diff --git a/scripts/ynh_supervisor b/scripts/ynh_supervisor new file mode 100644 index 00000000..838224d6 --- /dev/null +++ b/scripts/ynh_supervisor @@ -0,0 +1,177 @@ +#!/bin/bash + +# Create a dedicated supervisor config +# +# usage: ynh_add_supervisor_config [--service=service] [--template=template] +# | arg: -s, --service - Service name (optionnal, $app by default) +# | arg: -t, --template - Name of template file (optionnal, this is 'supervisor' by default, meaning ./conf/supervisor.service will be used as template) +# +# This will use the template ../conf/.service +# to generate a supervisor config, by replacing the following keywords +# with global variables that should be defined before calling +# this helper : +# +# __APP__ by $app +# __FINALPATH__ by $final_path +# +# Requires YunoHost version 2.7.2 or higher. +ynh_add_supervisor_config () { + # Declare an array to define the options of this helper. + local legacy_args=st + declare -Ar args_array=( [s]=service= [t]=template= ) + local service + local template + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + local service="${service:-$app}" + local template="${template:-supervisor.service}" + + finalsupervisorconf="/etc/supervisor/conf.d/$service.conf" + ynh_backup_if_checksum_is_different --file="$finalsupervisorconf" + cp ../conf/$template "$finalsupervisorconf" + + # To avoid a break by set -u, use a void substitution ${var:-}. If the variable is not set, it's simply set with an empty variable. + # Substitute in a nginx config file only if the variable is not empty + if test -n "${final_path:-}"; then + ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$finalsupervisorconf" + fi + if test -n "${app:-}"; then + ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$finalsupervisorconf" + fi + ynh_store_file_checksum --file="$finalsupervisorconf" + + chown root: "$finalsupervisorconf" + supervisorctl reread + supervisorctl update +} + +# Remove the dedicated supervisor config +# +# usage: ynh_remove_supervisor_config [--service=service] +# | arg: -s, --service - Service name (optionnal, $app by default) +# +# Requires YunoHost version 2.7.2 or higher. +ynh_remove_supervisor_config () { + # Declare an array to define the options of this helper. + local legacy_args=s + declare -Ar args_array=( [s]=service= ) + local service + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + local service="${service:-$app}" + + local finalsupervisorconf="/etc/supervisor/conf.d/$service.conf" + if [ -e "$finalsupervisorconf" ]; then + ynh_supervisor_action --service_name=$service --action=stop + ynh_secure_remove --file="$finalsupervisorconf" + supervisorctl reread + supervisorctl update + fi +} + +# Start (or other actions) a service, print a log in case of failure and optionnaly wait until the service is completely started +# +# usage: ynh_supervisor_action [-n service_name] [-a action] [ [-l "line to match"] [-p log_path] [-t timeout] [-e length] ] +# | arg: -n, --service_name= - Name of the service to start. Default : $app +# | arg: -a, --action= - Action to perform with supervisorctl. Default: start +# | arg: -l, --line_match= - Line to match - The line to find in the log to attest the service have finished to boot. If not defined it don't wait until the service is completely started. WARNING: When using --line_match, you should always add `ynh_clean_check_starting` into your `ynh_clean_setup` at the beginning of the script. Otherwise, tail will not stop in case of failure of the script. The script will then hang forever. +# | arg: -p, --log_path= - Log file - Path to the log file. Default : /var/log/$app/$app.log +# | arg: -t, --timeout= - Timeout - The maximum time to wait before ending the watching. Default : 300 seconds. +# | arg: -e, --length= - Length of the error log : Default : 20 +ynh_supervisor_action() { + # Declare an array to define the options of this helper. + local legacy_args=nalpte + declare -Ar args_array=( [n]=service_name= [a]=action= [l]=line_match= [p]=log_path= [t]=timeout= [e]=length= ) + local service_name + local action + local line_match + local length + local log_path + local timeout + + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + + local service_name="${service_name:-$app}" + local action=${action:-start} + local log_path="${log_path:-/var/log/$service_name/$service_name.log}" + local length=${length:-20} + local timeout=${timeout:-300} + + # Start to read the log + if [[ -n "${line_match:-}" ]] + then + local templog="$(mktemp)" + # Following the starting of the app in its log + if [ "$log_path" == "supervisor" ] ; then + # Read the supervisor journal + journalctl --unit=$service_name --follow --since=-0 --quiet > "$templog" & + # Get the PID of the journalctl command + local pid_tail=$! + else + # Read the specified log file + tail -F -n0 "$log_path" > "$templog" 2>&1 & + # Get the PID of the tail command + local pid_tail=$! + fi + fi + + # Use reload-or-restart instead of reload. So it wouldn't fail if the service isn't running. + if [ "$action" == "reload" ]; then + action="reload-or-restart" + fi + + supervisorctl $action $service_name \ + || ( journalctl --no-pager --lines=$length -u $service_name >&2 \ + ; test -e "$log_path" && echo "--" >&2 && tail --lines=$length "$log_path" >&2 \ + ; false ) + + # Start the timeout and try to find line_match + if [[ -n "${line_match:-}" ]] + then + local i=0 + for i in $(seq 1 $timeout) + do + # Read the log until the sentence is found, that means the app finished to start. Or run until the timeout + if grep --quiet "$line_match" "$templog" + then + ynh_print_info --message="The service $service_name has correctly executed the action ${action}." + break + fi + if [ $i -eq 3 ]; then + echo -n "Please wait, the service $service_name is ${action}ing" >&2 + fi + if [ $i -ge 3 ]; then + echo -n "." >&2 + fi + sleep 1 + done + if [ $i -ge 3 ]; then + echo "" >&2 + fi + if [ $i -eq $timeout ] + then + ynh_print_warn --message="The service $service_name didn't fully executed the action ${action} before the timeout." + ynh_print_warn --message="Please find here an extract of the end of the log of the service $service_name:" + journalctl --no-pager --lines=$length -u $service_name >&2 + test -e "$log_path" && echo "--" >&2 && tail --lines=$length "$log_path" >&2 + fi + ynh_clean_check_starting + fi +} + +# Clean temporary process and file used by ynh_check_starting +# (usually used in ynh_clean_setup scripts) +# +# usage: ynh_clean_check_starting +ynh_clean_check_starting () { + if [ -n "$pid_tail" ] + then + # Stop the execution of tail. + kill -s 15 $pid_tail 2>&1 + fi + if [ -n "$templog" ] + then + ynh_secure_remove "$templog" 2>&1 + fi +} \ No newline at end of file From b1a0c2a5cdb2591214b8a0920fed43830fdc3de0 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 21 Apr 2020 10:43:14 +0200 Subject: [PATCH 7/9] Add CRON --- conf/cron | 1 + scripts/backup | 7 +++++++ scripts/install | 10 +++++++++- scripts/remove | 8 ++++++++ scripts/restore | 9 ++++++++- scripts/upgrade | 8 ++++++++ 6 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 conf/cron diff --git a/conf/cron b/conf/cron new file mode 100644 index 00000000..d7b99655 --- /dev/null +++ b/conf/cron @@ -0,0 +1 @@ +* * * * * cd __FINALPATH__/ && php7.3 artisan schedule:run >> /dev/null 2>&1 diff --git a/scripts/backup b/scripts/backup index 057cb238..7d81e8e5 100644 --- a/scripts/backup +++ b/scripts/backup @@ -86,6 +86,13 @@ ynh_print_info --message="Backing up supervisor configuration..." ynh_backup --src_path="/etc/supervisor/conf.d/${app}-horizon.conf" +#================================================= +# BACKUP A CRON FILE +#================================================= +ynh_print_info --message="Backing up a cron file..." + +ynh_backup --src_path="/etc/cron.d/$app" + #================================================= # START SUPERVISOR SERVICE #================================================= diff --git a/scripts/install b/scripts/install index f34c2c6e..6afa9e81 100644 --- a/scripts/install +++ b/scripts/install @@ -198,6 +198,14 @@ pushd "$final_path" php7.3 artisan horizon:assets popd +#================================================= +# INSTALL THE CRON FILE +#================================================= +ynh_print_info --message="Installing cron file..." + +cp ../conf/cron "/etc/cron.d/$app" +ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="/etc/cron.d/$app" + #================================================= # GENERIC FINALIZATION #================================================= @@ -222,7 +230,7 @@ ynh_use_logrotate --logfile="/var/log/$app/${app}-horizon.log" #================================================= ynh_print_info --message="Integrating service in YunoHost..." -yunohost service add "${app}-horizon" --description "${app}-horizon daemon for $app" --log "/var/log/$app/${app}-horizon.log" +yunohost service add "supervisor" --description "${app}-horizon daemon for $app" --log "/var/log/$app/${app}-horizon.log" #================================================= # START SUPERVISOR SERVICE diff --git a/scripts/remove b/scripts/remove index 7a7fd426..bbe6783e 100644 --- a/scripts/remove +++ b/scripts/remove @@ -99,6 +99,14 @@ ynh_remove_logrotate #================================================= # SPECIFIC REMOVE +#================================================= +# REMOVE THE CRON FILE +#================================================= +ynh_print_info --message="Removing the cron file..." + +# Remove a cron file +ynh_secure_remove --file="/etc/cron.d/$app" + #================================================= # REMOVE THE LOG FILE #================================================= diff --git a/scripts/restore b/scripts/restore index 7882de6a..ac7f329d 100644 --- a/scripts/restore +++ b/scripts/restore @@ -139,7 +139,7 @@ supervisorctl reread && supervisorctl update #================================================= ynh_print_info --message="Integrating service in YunoHost..." -yunohost service add "${app}-horizon" --log "/var/log/$app/${app}-horizon.log" +yunohost service add "supervisor" --log "/var/log/$app/${app}-horizon.log" #================================================= # START SUPERVISOR SERVICE @@ -148,6 +148,13 @@ ynh_print_info --message="Starting a supervisor service..." ynh_supervisor_action --service_name="${app}-horizon" --action="start" --log_path="/var/log/$app/${app}-horizon.log" +#================================================= +# RESTORE THE CRON FILE +#================================================= +ynh_print_info --message="Restoring the cron file..." + +ynh_restore_file --origin_path="/etc/cron.d/$app" + #================================================= # RESTORE THE LOGROTATE CONFIGURATION #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index cbe5aed8..551b2724 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -226,6 +226,14 @@ mkdir -p "/var/log/$app/" touch "/var/log/$app/${app}-horizon.log" chown -R root: "/var/log/$app/" +#================================================= +# UPGRADE THE CRON FILE +#================================================= +ynh_print_info --message="Upgrading cron file..." + +cp ../conf/cron "/etc/cron.d/$app" +ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="/etc/cron.d/$app" + #================================================= # SETUP LOGROTATE #================================================= From fdd125cfa5c3dd819b73927416635538aafe7d56 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 22 Apr 2020 05:25:01 +0200 Subject: [PATCH 8/9] forgotten change --- scripts/upgrade | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index 551b2724..9e07e125 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -90,7 +90,7 @@ if [ -z "$app_key" ]; then fi if dpkg --compare-versions "0.9.0~ynh3" gt "$(ynh_read_manifest --manifest="/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" --manifest_key="version" || echo 1.0)" ; then - ynh_add_systemd_config --service="${app}-horizon" --template=horizon.service + ynh_add_systemd_config --service="${app}-horizon" --template=horizon.conf fi if dpkg --compare-versions "0.10.9~ynh2" gt "$(ynh_read_manifest --manifest="/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" --manifest_key="version" || echo 1.0)" ; then @@ -248,7 +248,7 @@ ynh_use_logrotate --non-append ynh_print_info --message="Upgrading supervisor configuration..." # Create a dedicated supervisor config -ynh_add_supervisor_config --service="${app}-horizon" --template=horizon.service +ynh_add_supervisor_config --service="${app}-horizon" --template=horizon.conf #================================================= # GENERIC FINALIZATION From 4526934ec540f50cecec752c2731fd9e5bff6afe Mon Sep 17 00:00:00 2001 From: yalh76 Date: Thu, 23 Apr 2020 19:49:58 +0200 Subject: [PATCH 9/9] Update check_process --- check_process | 2 ++ 1 file changed, 2 insertions(+) diff --git a/check_process b/check_process index 0da03b43..031833be 100644 --- a/check_process +++ b/check_process @@ -16,6 +16,8 @@ # upgrade=1 from_commit=7fa86c3e6e6db6668be0a165213d554850b9fce8 # 0.10.8 upgrade=1 from_commit=10c3703567d1e9504ea4f298778464c7dd561470 + # 0.10.9~ynh1 + upgrade=1 from_commit=8c5e710060da43a946336d66a30b9c311cfdbc37 backup_restore=1 multi_instance=1 # This test is no longer necessary since the version 2.7 (PR: https://github.com/YunoHost/yunohost/pull/304), you can still do it if your app could be installed with this version.