From f2e6dee2a268cc22a59a7256038a40b2678c69e3 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Fri, 12 Apr 2019 22:09:49 +0200 Subject: [PATCH] Cleanup --- check_process | 9 +--- manifest.json | 2 +- scripts/_common.sh | 2 - scripts/backup | 8 ---- scripts/change_url | 1 - scripts/install | 12 +---- scripts/remove | 12 +---- scripts/restore | 13 ++---- scripts/upgrade | 9 ---- scripts/ynh_systemd_action | 89 -------------------------------------- 10 files changed, 9 insertions(+), 148 deletions(-) delete mode 100644 scripts/ynh_systemd_action diff --git a/check_process b/check_process index 9b0178f..6281cc6 100644 --- a/check_process +++ b/check_process @@ -33,10 +33,5 @@ Level 9=0 Level 10=0 ;;; Options -Email= -Notification=none -;;; Upgrade options - ; commit=CommitHash - name=Name and date of the commit. - manifest_arg=domain=DOMAIN&path=PATH&admin=USER&language=fr&is_public=1&password=pass&port=666& - +Email=yalh@yahoo.com +Notification=all diff --git a/manifest.json b/manifest.json index 191700d..2b05fde 100644 --- a/manifest.json +++ b/manifest.json @@ -13,7 +13,7 @@ "name": "yalh76" }, "requirements": { - "yunohost": ">= 3.4" + "yunohost": ">= 3.5" }, "multi_instance": true, "services": [ diff --git a/scripts/_common.sh b/scripts/_common.sh index ff6fb78..7f4630a 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -6,9 +6,7 @@ # dependencies used by the app pkg_dependencies="postgresql postgresql-contrib openssl make git postgis " -# build-essential inotify-tools postgresql-client extra_pkg_dependencies="elixir esl-erlang" -# erlang-dev erlang-tools erlang-parsetools #================================================= # PERSONAL HELPERS diff --git a/scripts/backup b/scripts/backup index 431c7f4..33b76f0 100644 --- a/scripts/backup +++ b/scripts/backup @@ -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_systemd_action source /usr/share/yunohost/helpers #================================================= @@ -57,13 +56,6 @@ ynh_psql_dump_db "$db_name" > db.sql #================================================= # SPECIFIC BACKUP -#================================================= -# BACKUP LOGROTATE -#================================================= -ynh_print_info "Backing up logrotate configuration..." - -ynh_backup "/etc/logrotate.d/$app" - #================================================= # BACKUP SYSTEMD #================================================= diff --git a/scripts/change_url b/scripts/change_url index 321d023..f45bac2 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -7,7 +7,6 @@ #================================================= source _common.sh -source ynh_systemd_action source /usr/share/yunohost/helpers #================================================= diff --git a/scripts/install b/scripts/install index 6023a39..b57f68e 100644 --- a/scripts/install +++ b/scripts/install @@ -7,7 +7,6 @@ #================================================= source _common.sh -source ynh_systemd_action source ynh_add_secure_repos__3 source /usr/share/yunohost/helpers @@ -224,21 +223,12 @@ ynh_store_file_checksum "$config" # Set permissions to app files chown -R "$app":"$app" "$final_path" -#================================================= -# SETUP LOGROTATE -#================================================= -ynh_print_info "Configuring log rotation..." - -# Use logrotate to manage application logfile(s) -ynh_use_logrotate - #================================================= # ADVERTISE SERVICE IN ADMIN PANEL #================================================= -#yunohost service add $app --log "/var/log/$app/APP.log" # if using yunohost version 3.2 or more in the 'manifest.json', a description can be added -yunohost service add $app --description "$app daemon for Mobilizon" --log "/var/log/$app/$app.log" +yunohost service add $app --description "$app daemon for Mobilizon" #================================================= # SETUP SSOWAT diff --git a/scripts/remove b/scripts/remove index dbfdd95..bf80249 100644 --- a/scripts/remove +++ b/scripts/remove @@ -7,7 +7,6 @@ #================================================= source _common.sh -source ynh_systemd_action source /usr/share/yunohost/helpers #================================================= @@ -20,6 +19,7 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get $app domain) port=$(ynh_app_setting_get $app port) db_name=$(ynh_app_setting_get $app db_name) +db_user=$db_name final_path=$(ynh_app_setting_get $app final_path) #================================================= @@ -58,7 +58,7 @@ ynh_psql_execute_as_root "\connect $db_name SELECT pg_terminate_backend (pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = '$db_name';" # Remove a database if it exists, along with the associated user -ynh_psql_remove_db "$db_name" "$db_name" +ynh_psql_remove_db --db_user="$db_user" --db_name="$db_name" #================================================= # REMOVE DEPENDENCIES @@ -86,14 +86,6 @@ ynh_print_info "Removing nginx web server configuration" # Remove the dedicated nginx config ynh_remove_nginx_config -#================================================= -# REMOVE LOGROTATE CONFIGURATION -#================================================= -ynh_print_info "Removing logrotate configuration" - -# Remove the app-specific logrotate config -ynh_remove_logrotate - #================================================= # CLOSE A PORT #================================================= diff --git a/scripts/restore b/scripts/restore index d261694..b56f0ed 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_systemd_action source ../settings/scripts/ynh_add_secure_repos__3 source /usr/share/yunohost/helpers @@ -34,6 +33,7 @@ path_url=$(ynh_app_setting_get $app path) final_path=$(ynh_app_setting_get $app final_path) port=$(ynh_app_setting_get $app port) db_name=$(ynh_app_setting_get $app db_name) +db_user=$db_name db_pwd=$(ynh_app_setting_get $app db_pwd) #================================================= @@ -102,8 +102,7 @@ ynh_install_extra_app_dependencies --repo="deb http://packages.erlang-solutions. ynh_print_info "Restoring the PostgreSQL database..." ynh_psql_test_if_first_run -db_user=$db_name -ynh_psql_create_user "$app" "$db_pwd" +ynh_psql_create_user "$db_user" "$db_pwd" ynh_psql_execute_as_root "CREATE DATABASE $db_name ENCODING 'UTF8' LC_COLLATE='C' LC_CTYPE='C' template=template0 OWNER $db_user;" ynh_psql_execute_as_root "\connect $db_name create extension if not exists postgis;" @@ -126,13 +125,7 @@ systemctl daemon-reload # ADVERTISE SERVICE IN ADMIN PANEL #================================================= -yunohost service add $app --description "$app daemon for Mobilizon" --log "/var/log/$app/$app.log" - -#================================================= -# RESTORE THE LOGROTATE CONFIGURATION -#================================================= - -ynh_restore_file "/etc/logrotate.d/$app" +yunohost service add $app --description "$app daemon for Mobilizon" #================================================= # GENERIC FINALIZATION diff --git a/scripts/upgrade b/scripts/upgrade index a868086..33c5514 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -7,7 +7,6 @@ #================================================= source _common.sh -source ynh_systemd_action source ynh_add_secure_repos__3 source /usr/share/yunohost/helpers @@ -185,14 +184,6 @@ ynh_backup_if_checksum_is_different "$config" # Recalculate and store the checksum of the file for the next upgrade. ynh_store_file_checksum "$config" -#================================================= -# SETUP LOGROTATE -#================================================= -ynh_print_info "Upgrading logrotate configuration..." - -# Use logrotate to manage app-specific logfile(s) -ynh_use_logrotate --non-append - #================================================= # SETUP SYSTEMD #================================================= diff --git a/scripts/ynh_systemd_action b/scripts/ynh_systemd_action deleted file mode 100644 index 6bed6be..0000000 --- a/scripts/ynh_systemd_action +++ /dev/null @@ -1,89 +0,0 @@ -#!/bin/bash - -# Start (or other actions) a service, print a log in case of failure and optionnaly wait until the service is completely started -# -# usage: ynh_systemd_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 reload. Default : $app -# | arg: -a, --action= - Action to perform with systemctl. 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 -ynh_systemd_action() { - # Declare an array to define the options of this helper. - 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" == "systemd" ] ; then - # Read the systemd journal - journalctl -u $service_name -f --since=-45 > "$templog" & - else - # Read the specified log file - tail -F -n0 "$log_path" > "$templog" & - fi - # Get the PID of the tail command - local pid_tail=$! - fi - - echo "${action^} the service $service_name" >&2 - systemctl $action $service_name \ - || ( journalctl --lines=$length -u $service_name >&2 \ - ; test -n "$log_path" && echo "--" && 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 - echo "The service $service_name has correctly started." >&2 - break - fi - echo -n "." >&2 - sleep 1 - done - if [ $i -eq $timeout ] - then - echo "The service $service_name didn't fully started before the timeout." >&2 - journalctl --lines=$length -u $service_name >&2 - test -n "$log_path" && echo "--" && tail --lines=$length "$log_path" >&2 - fi - - echo "" - 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 () { - # Stop the execution of tail. - kill -s 15 $pid_tail 2>&1 - ynh_secure_remove "$templog" 2>&1 -}