diff --git a/conf/systemd.service b/conf/systemd.service index c01e2d4..0e1f965 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -10,7 +10,7 @@ Group=__APP__ ExecStartPre=__NODEJS__ WorkingDirectory=__FINALPATH__ Environment="PATH=__ENV_PATH__" -ExecStart=__NODE__ server.js +ExecStart=/bin/bash -c 'exec __NODE__ server.js | tee /var/log/__APP__/__APP__.log' Restart=always [Install] diff --git a/scripts/_common.sh b/scripts/_common.sh index 5a47419..d8ccf53 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -116,7 +116,7 @@ CHECK_USER () { # Vérifie la validité de l'user admin } CHECK_DOMAINPATH () { # Vérifie la disponibilité du path et du domaine. - if sudo yunohost app --help | grep --quiet url-available + if sudo yunohost domain --help | grep --quiet url-available then # Check availability of a web path ynh_webpath_available $domain $path_url @@ -602,17 +602,27 @@ ynh_remove_app_dependencies () { # Use logrotate to manage the logfile # -# usage: ynh_use_logrotate [logfile] +# usage: ynh_use_logrotate [logfile] [--non-append] # | arg: logfile - absolute path of logfile +# | option: --non-append - Replace the config file instead of appending this new config. # # If no argument provided, a standard directory will be use. /var/log/${app} # You can provide a path with the directory only or with the logfile. # /parentdir/logdir/ # /parentdir/logdir/logfile.log # -# It's possible to use this helper several times, each config will added to same logrotate config file. +# It's possible to use this helper several times, each config will be added to the same logrotate config file. +# Unless you use the option --non-append ynh_use_logrotate () { - if [ "$#" -gt 0 ]; then + local customtee="tee -a" + if [ $# -gt 0 ] && [ "$1" == "--non-append" ]; then + customtee="tee" + # Destroy this argument for the next command. + shift + elif [ $# -gt 1 ] && [ "$2" == "--non-append" ]; then + customtee="tee" + fi + if [ $# -gt 0 ]; then if [ "$(echo ${1##*.})" == "log" ]; then # Keep only the extension to check if it's a logfile logfile=$1 # In this case, focus logrotate on the logfile else @@ -642,7 +652,7 @@ $logfile { } EOF sudo mkdir -p $(dirname "$logfile") # Create the log directory, if not exist - cat ${app}-logrotate | sudo tee -a /etc/logrotate.d/$app > /dev/null # Append this config to the others for this app. If a config file already exist + cat ${app}-logrotate | sudo $customtee /etc/logrotate.d/$app > /dev/null # Append this config to the existing config file, or replace the whole config file (depending on $customtee) } # Remove the app's logrotate config. diff --git a/scripts/backup b/scripts/backup index f19b279..6e7df82 100644 --- a/scripts/backup +++ b/scripts/backup @@ -3,13 +3,6 @@ # Exit on command errors and treat unset variables as an error set -eu -# TODO remove later -# Workaround for bug https://dev.yunohost.org/issues/953 -# Useful for package_check tests (only when restoring just after backuping) -if [ ! -e /usr/bin/archivemount ] ; then - sudo cp /bin/false /usr/bin/archivemount -fi - #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -45,6 +38,11 @@ ynh_backup "$final_path" "sources" ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "nginx.conf" +#================================================= +# BACKUP LOGROTATE CONFIGURATION +#================================================= +ynh_backup "/etc/logrotate.d/$app" "logrotate" + #================================================= # BACKUP SYSTEMD CONFIGURATION #================================================= diff --git a/scripts/remove b/scripts/remove index c13389c..935a16b 100644 --- a/scripts/remove +++ b/scripts/remove @@ -15,6 +15,9 @@ domain=$(ynh_app_setting_get $app domain) # Stop and remove service ynh_remove_systemd_config +# Remove logrotate configuration +ynh_remove_logrotate + # Remove sources ynh_secure_remove "/var/www/$app" diff --git a/scripts/restore b/scripts/restore index 2cc7d82..26451b8 100644 --- a/scripts/restore +++ b/scripts/restore @@ -30,7 +30,11 @@ final_path=$(ynh_app_setting_get $app final_path) # CHECK IF THE APP CAN BE RESTORED #================================================= -CHECK_DOMAINPATH # Check domain and path availability +yunohost app checkurl "${domain}${path_url}" -a "$app" \ + || ynh_die "Path not available: ${domain}${path_url}" +test ! -d $final_path \ +|| ynh_die "There is already a directory: $final_path " + CHECK_FINALPATH # Check if destination directory is not already in use #================================================= @@ -41,6 +45,12 @@ CHECK_FINALPATH # Check if destination directory is not already in use sudo cp -a ./nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf +#================================================= +# RESTORE LOGROTATE CONFIGURATION +#================================================= + +sudo cp -a ./logrotate /etc/logrotate.d/$app + #================================================= # RESTORE APP MAIN DIR #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 74a6f93..68873b3 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -61,16 +61,8 @@ ynh_system_user_create $app # HANDLE LOG FILES AND LOGROTATE #================================================= -# Créer le dossier de log -sudo mkdir -p /var/log/$app -sudo touch /var/log/$app/$app.log -install_log=/var/log/$app/installation.log -sudo touch $install_log -sudo chown $app -R /var/log/$app -sudo chown admin -R $install_log - -# Configuration de logrotate -ynh_use_logrotate +# Setup logrotate +ynh_use_logrotate /var/log/${app}/*.log --non-append #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE