mirror of
https://github.com/YunoHost-Apps/synapse_ynh.git
synced 2024-09-03 20:26:38 +02:00
Fix logrotate and helper ynh_install_app_dependencies
This commit is contained in:
parent
c63e47c355
commit
45007ecb53
5 changed files with 62 additions and 46 deletions
|
@ -148,16 +148,6 @@ set_access() { # example : set_access USER FILE
|
||||||
|
|
||||||
####### Solve issue https://dev.yunohost.org/issues/1006
|
####### Solve issue https://dev.yunohost.org/issues/1006
|
||||||
|
|
||||||
# Install package(s)
|
|
||||||
#
|
|
||||||
# usage: ynh_package_install name [name [...]]
|
|
||||||
# | arg: name - the package name to install
|
|
||||||
ynh_package_try_install() {
|
|
||||||
ynh_apt -o Dpkg::Options::=--force-confdef \
|
|
||||||
-o Dpkg::Options::=--force-confold install $@
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# Build and install a package from an equivs control file
|
# Build and install a package from an equivs control file
|
||||||
#
|
#
|
||||||
# example: generate an empty control file with `equivs-control`, adjust its
|
# example: generate an empty control file with `equivs-control`, adjust its
|
||||||
|
@ -192,44 +182,66 @@ ynh_package_install_from_equivs () {
|
||||||
&& equivs-build ./control 1>/dev/null \
|
&& equivs-build ./control 1>/dev/null \
|
||||||
&& sudo dpkg --force-depends \
|
&& sudo dpkg --force-depends \
|
||||||
-i "./${pkgname}_${pkgversion}_all.deb" 2>&1 \
|
-i "./${pkgname}_${pkgversion}_all.deb" 2>&1 \
|
||||||
&& ynh_package_try_install -f)
|
&& ynh_package_install -f) || ynh_die "Unable to install dependencies"
|
||||||
[[ -n "$TMPDIR" ]] && rm -rf $TMPDIR # Remove the temp dir.
|
[[ -n "$TMPDIR" ]] && rm -rf $TMPDIR # Remove the temp dir.
|
||||||
|
|
||||||
# check if the package is actually installed
|
# check if the package is actually installed
|
||||||
ynh_package_is_installed "$pkgname"
|
ynh_package_is_installed "$pkgname"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Define and install dependencies with a equivs control file
|
# Implement PR : https://github.com/YunoHost/yunohost/pull/392
|
||||||
# This helper can/should only be called once per app
|
|
||||||
|
# Use logrotate to manage the logfile
|
||||||
#
|
#
|
||||||
# usage: ynh_install_app_dependencies dep [dep [...]]
|
# usage: ynh_use_logrotate [logfile] [--non-append]
|
||||||
# | arg: dep - the package name to install in dependence
|
# | arg: logfile - absolute path of logfile
|
||||||
ynh_install_app_dependencies () {
|
# | option: --non-append - Replace the config file instead of appending this new config.
|
||||||
dependencies=$@
|
#
|
||||||
manifest_path="../manifest.json"
|
# If no argument provided, a standard directory will be use. /var/log/${app}
|
||||||
if [ ! -e "$manifest_path" ]; then
|
# You can provide a path with the directory only or with the logfile.
|
||||||
manifest_path="../settings/manifest.json" # Into the restore script, the manifest is not at the same place
|
# /parentdir/logdir
|
||||||
fi
|
# /parentdir/logdir/logfile.log
|
||||||
version=$(grep '\"version\": ' "$manifest_path" | cut -d '"' -f 4) # Retrieve the version number in the manifest file.
|
#
|
||||||
dep_app=${app//_/-} # Replace all '_' by '-'
|
# 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
|
||||||
if ynh_package_is_installed "${dep_app}-ynh-deps"; then
|
ynh_use_logrotate () {
|
||||||
echo "A package named ${dep_app}-ynh-deps is already installed" >&2
|
local customtee="tee -a"
|
||||||
else
|
if [ $# -gt 0 ] && [ "$1" == "--non-append" ]; then
|
||||||
cat > /tmp/${dep_app}-ynh-deps.control << EOF # Make a control file for equivs-build
|
customtee="tee"
|
||||||
Section: misc
|
# Destroy this argument for the next command.
|
||||||
Priority: optional
|
shift
|
||||||
Package: ${dep_app}-ynh-deps
|
elif [ $# -gt 1 ] && [ "$2" == "--non-append" ]; then
|
||||||
Version: ${version}
|
customtee="tee"
|
||||||
Depends: ${dependencies// /, }
|
fi
|
||||||
Architecture: all
|
if [ $# -gt 0 ]; then
|
||||||
Description: Fake package for ${app} (YunoHost app) dependencies
|
if [ "$(echo ${1##*.})" == "log" ]; then # Keep only the extension to check if it's a logfile
|
||||||
This meta-package is only responsible of installing its dependencies.
|
logfile=$1 # In this case, focus logrotate on the logfile
|
||||||
EOF
|
else
|
||||||
ynh_package_install_from_equivs /tmp/${dep_app}-ynh-deps.control \
|
logfile=$1/*.log # Else, uses the directory and all logfile into it.
|
||||||
|| (ynh_package_autopurge; ynh_die "Unable to install dependencies") # Install the fake package and its dependencies
|
fi
|
||||||
rm /tmp/${dep_app}-ynh-deps.control
|
else
|
||||||
ynh_app_setting_set $app apt_dependencies $dependencies
|
logfile="/var/log/${app}/*.log" # Without argument, use a defaut directory in /var/log
|
||||||
fi
|
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 $customtee /etc/logrotate.d/$app > /dev/null # Append this config to the existing config file, or replace the whole config file (depending on $customtee)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,11 +30,9 @@ ynh_backup "/var/lib/matrix-synapse" "data" 1
|
||||||
# Backup Postgresql database
|
# Backup Postgresql database
|
||||||
sudo su -c "pg_dump $synapse_db_name" postgres > ${YNH_CWD}/dump.sql
|
sudo su -c "pg_dump $synapse_db_name" postgres > ${YNH_CWD}/dump.sql
|
||||||
|
|
||||||
# Copie la configuration de logrotate
|
|
||||||
ynh_backup "/etc/logrotate.d/$app" "logrotate"
|
|
||||||
|
|
||||||
# Copy the logs
|
# Copy the logs
|
||||||
ynh_backup "/var/log/matrix-synapse" "log"
|
ynh_backup "/var/log/matrix-synapse" "log"
|
||||||
|
ynh_backup "/var/log/turnserver" "log_turnserver"
|
||||||
|
|
||||||
# Backup systemd service
|
# Backup systemd service
|
||||||
ynh_backup "/etc/default/matrix-synapse"
|
ynh_backup "/etc/default/matrix-synapse"
|
||||||
|
|
|
@ -90,6 +90,7 @@ set_certificat_access
|
||||||
|
|
||||||
# Configuration de logrotate
|
# Configuration de logrotate
|
||||||
ynh_use_logrotate /var/log/matrix-synapse
|
ynh_use_logrotate /var/log/matrix-synapse
|
||||||
|
ynh_use_logrotate /var/log/turnserver
|
||||||
|
|
||||||
# register yunohost service
|
# register yunohost service
|
||||||
yunohost service add matrix-synapse
|
yunohost service add matrix-synapse
|
||||||
|
|
|
@ -47,6 +47,7 @@ ynh_remove_app_dependencies || true
|
||||||
ynh_secure_remove $final_path
|
ynh_secure_remove $final_path
|
||||||
ynh_secure_remove /var/lib/matrix-synapse
|
ynh_secure_remove /var/lib/matrix-synapse
|
||||||
ynh_secure_remove /var/log/matrix-synapse
|
ynh_secure_remove /var/log/matrix-synapse
|
||||||
|
ynh_secure_remove /var/log/turnserver
|
||||||
ynh_secure_remove /etc/matrix-synapse
|
ynh_secure_remove /etc/matrix-synapse
|
||||||
ynh_secure_remove /etc/default/matrix-synapse
|
ynh_secure_remove /etc/default/matrix-synapse
|
||||||
|
|
||||||
|
|
|
@ -62,6 +62,10 @@ su -c "psql $synapse_db_name" postgres < ${YNH_CWD}/dump.sql
|
||||||
systemctl daemon-reload
|
systemctl daemon-reload
|
||||||
systemctl enable matrix-synapse.service
|
systemctl enable matrix-synapse.service
|
||||||
|
|
||||||
|
# Configuration de logrotate
|
||||||
|
ynh_use_logrotate /var/log/matrix-synapse
|
||||||
|
ynh_use_logrotate /var/log/turnserver
|
||||||
|
|
||||||
# register yunohost service
|
# register yunohost service
|
||||||
yunohost service add matrix-synapse
|
yunohost service add matrix-synapse
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue