mirror of
https://github.com/YunoHost-Apps/cryptpad_ynh.git
synced 2024-09-03 18:26:14 +02:00
Fix logs output and logrotate configuration
This commit is contained in:
parent
910d0f6962
commit
b207d5aa5e
6 changed files with 37 additions and 24 deletions
|
@ -10,7 +10,7 @@ Group=__APP__
|
||||||
ExecStartPre=__NODEJS__
|
ExecStartPre=__NODEJS__
|
||||||
WorkingDirectory=__FINALPATH__
|
WorkingDirectory=__FINALPATH__
|
||||||
Environment="PATH=__ENV_PATH__"
|
Environment="PATH=__ENV_PATH__"
|
||||||
ExecStart=__NODE__ server.js
|
ExecStart=/bin/bash -c 'exec __NODE__ server.js | tee /var/log/__APP__/__APP__.log'
|
||||||
Restart=always
|
Restart=always
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
|
|
|
@ -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.
|
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
|
then
|
||||||
# Check availability of a web path
|
# Check availability of a web path
|
||||||
ynh_webpath_available $domain $path_url
|
ynh_webpath_available $domain $path_url
|
||||||
|
@ -602,17 +602,27 @@ ynh_remove_app_dependencies () {
|
||||||
|
|
||||||
# Use logrotate to manage the logfile
|
# Use logrotate to manage the logfile
|
||||||
#
|
#
|
||||||
# usage: ynh_use_logrotate [logfile]
|
# usage: ynh_use_logrotate [logfile] [--non-append]
|
||||||
# | arg: logfile - absolute path of logfile
|
# | 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}
|
# 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.
|
# You can provide a path with the directory only or with the logfile.
|
||||||
# /parentdir/logdir/
|
# /parentdir/logdir/
|
||||||
# /parentdir/logdir/logfile.log
|
# /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 () {
|
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
|
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
|
logfile=$1 # In this case, focus logrotate on the logfile
|
||||||
else
|
else
|
||||||
|
@ -642,7 +652,7 @@ $logfile {
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
sudo mkdir -p $(dirname "$logfile") # Create the log directory, if not exist
|
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.
|
# Remove the app's logrotate config.
|
||||||
|
|
|
@ -3,13 +3,6 @@
|
||||||
# Exit on command errors and treat unset variables as an error
|
# Exit on command errors and treat unset variables as an error
|
||||||
set -eu
|
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
|
# IMPORT GENERIC HELPERS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -45,6 +38,11 @@ ynh_backup "$final_path" "sources"
|
||||||
|
|
||||||
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "nginx.conf"
|
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
|
# BACKUP SYSTEMD CONFIGURATION
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
|
@ -15,6 +15,9 @@ domain=$(ynh_app_setting_get $app domain)
|
||||||
# Stop and remove service
|
# Stop and remove service
|
||||||
ynh_remove_systemd_config
|
ynh_remove_systemd_config
|
||||||
|
|
||||||
|
# Remove logrotate configuration
|
||||||
|
ynh_remove_logrotate
|
||||||
|
|
||||||
# Remove sources
|
# Remove sources
|
||||||
ynh_secure_remove "/var/www/$app"
|
ynh_secure_remove "/var/www/$app"
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,11 @@ final_path=$(ynh_app_setting_get $app final_path)
|
||||||
# CHECK IF THE APP CAN BE RESTORED
|
# 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
|
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
|
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
|
# RESTORE APP MAIN DIR
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
|
@ -61,16 +61,8 @@ ynh_system_user_create $app
|
||||||
# HANDLE LOG FILES AND LOGROTATE
|
# HANDLE LOG FILES AND LOGROTATE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
# Créer le dossier de log
|
# Setup logrotate
|
||||||
sudo mkdir -p /var/log/$app
|
ynh_use_logrotate /var/log/${app}/*.log --non-append
|
||||||
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
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||||
|
|
Loading…
Reference in a new issue