1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/nextcloud_ynh.git synced 2024-09-03 19:55:57 +02:00

Setup log rotation (closes #25)

This commit is contained in:
Jimmy Monin 2017-04-17 14:12:15 +02:00
parent ebb198f3e9
commit 34e1085a9f
6 changed files with 76 additions and 0 deletions

View file

@ -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
}

View file

@ -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"

View file

@ -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"

View file

@ -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

View file

@ -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

View file

@ -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