mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[fix] Logrotate append (#328)
* [fix] Logrotate append * Typo fix by JimboJoe
This commit is contained in:
parent
3afbf0f7b9
commit
390835e96a
1 changed files with 14 additions and 4 deletions
|
@ -1,16 +1,26 @@
|
||||||
# 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
|
||||||
|
@ -40,7 +50,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.
|
||||||
|
|
Loading…
Add table
Reference in a new issue