diff --git a/scripts/_common.sh b/scripts/_common.sh index 9a09472..5f85ebc 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -133,3 +133,61 @@ SECURE_REMOVE () { # Suppression de dossier avec vérification des variable return 1 fi } + +#================================================= +# FUTURE YUNOHOST HELPERS - TO BE REMOVED LATER +#================================================= + +# Use logrotate to manage the logfile +# +# usage: ynh_use_logrotate [logfile] +# | arg: logfile - absolute path of logfile +# +# 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. +ynh_use_logrotate () { + 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 + logfile=$1/.log # Else, uses the directory and all logfile into it. + fi + else + logfile="/var/log/${app}/.log" # Without argument, use a defaut directory in /var/log + fi + cat > ./${app}-logrotate << EOF # Build a config file for logrotate +$logfile { + # Rotate if the logfile exceeds 100Mo + size 100M + # Keep 12 old log maximum + rotate 12 + # Compress the logs with gzip + compress + # Compress the log at the next cycle. So keep always 2 non compressed logs + delaycompress + # Copy and truncate the log to allow to continue write on it. Instead of move the log. + copytruncate + # Do not do an error if the log is missing + missingok + # Not rotate if the log is empty + notifempty + # Keep old logs in the same dir + noolddir +} +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 +} + +# Remove the app's logrotate config. +# +# usage: ynh_remove_logrotate +ynh_remove_logrotate () { + if [ -e "/etc/logrotate.d/$app" ]; then + sudo rm "/etc/logrotate.d/$app" + fi +} \ No newline at end of file diff --git a/scripts/backup b/scripts/backup index 1231263..df8d966 100755 --- a/scripts/backup +++ b/scripts/backup @@ -43,3 +43,6 @@ mysqldump -u "$dbuser" -p"$dbpass" --no-create-db "$dbname" > ./db.sql # Copy the control file of the dependency package # FIXME: find a way to retrieve package name from _common.sh? dpkg-query -s nextcloud-deps > ./nextcloud-deps.control + +# Backup the logrotate configuration file +ynh_backup "/etc/logrotate.d/$app" "logrotate" \ No newline at end of file diff --git a/scripts/install b/scripts/install index 4897649..bc56e53 100755 --- a/scripts/install +++ b/scripts/install @@ -186,3 +186,6 @@ sed -i "s@#DESTDIR#@${DESTDIR}@g" ../conf/nextcloud.cron sudo cp ../conf/nextcloud.cron "$cron_path" sudo chmod 644 "$cron_path" _exec_occ background:cron + +# Setup log rotation +ynh_use_logrotate "/home/yunohost.app/nextcloud/data/nextcloud.log" \ No newline at end of file diff --git a/scripts/remove b/scripts/remove index 4e74409..7bae392 100755 --- a/scripts/remove +++ b/scripts/remove @@ -45,3 +45,6 @@ done # Remove the user account id "$app" >/dev/null 2>&1 \ && sudo deluser --quiet --remove-home "$app" >/dev/null + +# Remove logrotate configuration +ynh_remove_logrotate \ No newline at end of file diff --git a/scripts/restore b/scripts/restore index 2b285cc..579e9af 100755 --- a/scripts/restore +++ b/scripts/restore @@ -88,6 +88,9 @@ sudo cp -a ./conf/php-fpm.conf "$phpfpm_conf" # Restore cron job sudo cp -a ./conf/cron "/etc/cron.d/${app}" +# Restore logrotate configuration file +sudo cp -a ./logrotate /etc/logrotate.d/$app + # Reload services sudo service php5-fpm restart || true sudo service nginx reload || true diff --git a/scripts/upgrade b/scripts/upgrade index 2ebf4ef..22c169f 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -239,6 +239,12 @@ you don't see Nextcloud as installed." >&2 sudo chmod 644 "$cron_path" fi +# Setup log rotation +if [ ! -f "/etc/logrotate.d/$app" ]; then + # Don't change the logrotate conf file if already existing + # (the helper only appends the log file configuration) + ynh_use_logrotate "/home/yunohost.app/nextcloud/data/nextcloud.log" +fi # Warn about possible disabled apps echo "Note that if you've installed some third-parties Nextcloud applications, \ they are probably disabled and you'll have to manually activate them again." >&2