diff --git a/scripts/install b/scripts/install index d39bcaf7..ac3a4cf1 100644 --- a/scripts/install +++ b/scripts/install @@ -7,7 +7,6 @@ #================================================= source _common.sh -source ynh_supervisor source /usr/share/yunohost/helpers #================================================= @@ -177,7 +176,7 @@ pushd "$final_path" php$phpversion artisan migrate --force php$phpversion artisan update php$phpversion artisan horizon:purge - php$phpversion artisan import:cities 2>/dev/null + php$phpversion artisan import:cities 2>/dev/null php$phpversion artisan instance:actor php$phpversion artisan passport:client --personal <<< "\\n" popd @@ -209,7 +208,7 @@ yunohost service add $app --description="Ethical photo sharing platform" --log=" #================================================= # START SUPERVISOR SERVICE #================================================= -ynh_script_progression --message="Starting a supervisor service..." +ynh_script_progression --message="Starting $app service..." # Start a supervisor service ynh_systemd_action --service_name="$app" --action="start" --log_path="systemd" #--line_match="success: ${app}-horizon" diff --git a/scripts/remove b/scripts/remove index d5c6e070..a7a08285 100644 --- a/scripts/remove +++ b/scripts/remove @@ -7,7 +7,6 @@ #================================================= source _common.sh -source ynh_supervisor source /usr/share/yunohost/helpers #================================================= @@ -29,10 +28,10 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) #================================================= # Remove the service from the list of services known by YunoHost (added from `yunohost service add`) -if ynh_exec_warn_less yunohost service status "supervisor" >/dev/null +if ynh_exec_warn_less yunohost service status $app >/dev/null then - ynh_script_progression --message="Removing supervisor service..." - yunohost service remove "$app" + ynh_script_progression --message="Removing $app service integration..." --time --weight=1 + yunohost service remove $app fi #================================================= diff --git a/scripts/restore b/scripts/restore index e0b2da2a..a6bd9b29 100644 --- a/scripts/restore +++ b/scripts/restore @@ -8,7 +8,6 @@ # 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 #================================================= @@ -132,7 +131,7 @@ systemctl enable $app.service --quiet #================================================= ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add $app --description="Supervisor daemon for $app" --log="/var/log/$app/$app.log" +yunohost service add $app --description="Ethical photo sharing platform" --log="/var/log/$app/$app.log" #================================================= # START SUPERVISOR SERVICE diff --git a/scripts/upgrade b/scripts/upgrade index 0f68c21e..3b098dab 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -7,7 +7,6 @@ #================================================= source _common.sh -source ynh_supervisor source /usr/share/yunohost/helpers #================================================= @@ -19,9 +18,7 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) path_url=$(ynh_app_setting_get --app=$app --key=path) -admin=$(ynh_app_setting_get --app=$app --key=admin) final_path=$(ynh_app_setting_get --app=$app --key=final_path) -language=$(ynh_app_setting_get --app=$app --key=language) db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user=$db_name db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) @@ -35,7 +32,6 @@ fpm_usage=$(ynh_app_setting_get --app=$app --key=fpm_usage) #================================================= # CHECK VERSION #================================================= -ynh_script_progression --message="Checking version..." upgrade_type=$(ynh_check_app_version_changed) @@ -84,48 +80,6 @@ if [ -z "$app_key" ]; then 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_script_progression --message="Ensuring upgrade compatibility to 0.9.0~ynh3..." - - ynh_script_progression --message="Configuring a systemd 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 - ynh_script_progression --message="Ensuring upgrade compatibility to 0.10.9~ynh2..." - - ynh_script_progression --message="Stopping and removing the systemd service..." - ynh_remove_systemd_config --service="${app}-horizon" - - ynh_script_progression --message="Installing dependencies..." - ynh_install_app_dependencies "$pkg_dependencies" - - ynh_script_progression --message="Creating log file..." - mkdir -p "/var/log/$app/" - touch "/var/log/$app/${app}-horizon.log" - chown -R $app: "/var/log/$app/" - - ynh_script_progression --message="Configuring a supervisor service..." - phpversion=$YNH_PHP_VERSION - ynh_add_supervisor_config --service="${app}-horizon" --template=horizon.conf - - ynh_script_progression --message="Starting a supervisor service..." - ynh_supervisor_action --service_name="${app}-horizon" --action="start" --log_path="systemd" --line_match="success: ${app}-horizon" -fi - -if dpkg --compare-versions "0.10.9~ynh3" gt "$(ynh_read_manifest --manifest="/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" --manifest_key="version" || echo 1.0)" ; then - ynh_script_progression --message="Ensuring upgrade compatibility to 0.10.9~ynh3..." - - if ynh_exec_warn_less yunohost service status ${app}-horizon >/dev/null - then - ynh_script_progression --message="Removing ${app}-horizon service..." - yunohost service remove "${app}-horizon" - fi - - ynh_script_progression --message="Integrating service in YunoHost..." - yunohost service add "supervisor" --description="Supervisor daemon for $app" --log="/var/log/$app/${app}-horizon.log" -fi - # Cleaning legacy permissions if ynh_legacy_permissions_exists; then ynh_legacy_permissions_delete_all @@ -138,9 +92,9 @@ fi #================================================= # STOP SUPERVISOR SERVICE #================================================= -ynh_script_progression --message="Stopping a supervisor service..." +ynh_script_progression --message="Stopping a systemd service..." -ynh_supervisor_action --service_name="${app}-horizon" --action="stop" --log_path="systemd" --line_match="stopped: ${app}-horizon" +ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" #================================================= # CREATE DEDICATED USER @@ -227,7 +181,7 @@ pushd "$final_path" php$phpversion artisan migrate --force php$phpversion artisan update php$phpversion artisan horizon:purge - php$phpversion artisan import:cities + php$phpversion artisan import:cities 2>/dev/null php$phpversion artisan instance:actor php$phpversion artisan passport:client --personal <<< "\\n" popd @@ -251,7 +205,7 @@ ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/$app" #================================================= # SETUP SUPERVISOR #================================================= -ynh_script_progression --message="Upgrading supervisor configuration..." +ynh_script_progression --message="Upgrading systemd configuration..." # Create a dedicated supervisor config ynh_add_systemd_config @@ -271,12 +225,12 @@ ynh_use_logrotate --non-append #================================================= ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add $app --description="Supervisor daemon for $app" --log="/var/log/$app/$app.log" +yunohost service add $app --description="Ethical photo sharing platform" --log="/var/log/$app/$app.log" #================================================= # START SUPERVISOR SERVICE #================================================= -ynh_script_progression --message="Starting a supervisor service..." +ynh_script_progression --message="Starting a systemd service..." ynh_systemd_action --service_name="$app" --action="start" --log_path="systemd" diff --git a/scripts/ynh_supervisor b/scripts/ynh_supervisor deleted file mode 100644 index 67bd2bd7..00000000 --- a/scripts/ynh_supervisor +++ /dev/null @@ -1,167 +0,0 @@ -#!/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`. -# -# See the documentation of `ynh_add_config` for a description of the template -# format and how placeholders are replaced with actual variables. -# -# Requires YunoHost version 2.7.11 or higher. -ynh_add_supervisor_config () { - # Declare an array to define the options of this helper. - local legacy_args=stv - local -A args_array=( [s]=service= [t]=template= [v]=others_var=) - local service - local template - local others_var - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - local service="${service:-$app}" - local template="${template:-supervisor.service}" - others_var="${others_var:-}" - - [[ -z "$others_var" ]] || ynh_print_warn --message="Packagers: using --others_var is unecessary since Yunohost 4.2" - - ynh_add_config --template="$YNH_APP_BASEDIR/conf/$template" --destination="/etc/supervisor/conf.d/$service.conf" - - 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 - local -A 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 [--service_name=service_name] [--action=action] [ [--line_match="line to match"] [--log_path=log_path] [--timeout=300] [--length=20] ] -# | 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. -# | 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 -# -# Requires YunoHost version 3.5.0 or higher. -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 "$@" - service_name="${service_name:-$app}" - action=${action:-start} - line_match=${line_match:-} - length=${length:-20} - log_path="${log_path:-/var/log/$service_name/$service_name.log}" - 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" == "systemd" ] - then - # Read the supervisor journal - journalctl --unit=supervisor --follow --since=-0 --quiet > "$templog" & - # Get the PID of the journalctl command - local pid_tail=$! - else - # Read the specified log file - tail --follow=name --retry --lines=0 "$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="update" - fi - - # If the service fails to perform the action - if ! supervisorctl $action $service_name - then - # Show syslog for this service - ynh_exec_err journalctl --quiet --no-hostname --no-pager --lines=$length --unit=$service_name - # If a log is specified for this service, show also the content of this log - if [ -e "$log_path" ] - then - ynh_exec_err tail --lines=$length "$log_path" - fi - ynh_clean_check_starting - return 1 - fi - - # Start the timeout and try to find line_match - if [[ -n "${line_match:-}" ]] - then - set +x - 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 --extended-regexp --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 - set -x - 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:" - ynh_exec_warn journalctl --quiet --no-hostname --no-pager --lines=$length --unit=$service_name - if [ -e "$log_path" ] - then - ynh_print_warn --message="\-\-\-" - ynh_exec_warn tail --lines=$length "$log_path" - fi - fi - ynh_clean_check_starting - fi -}