From e2567c82f1a1871985163ad4b308e78aa5a276a6 Mon Sep 17 00:00:00 2001 From: Josue-T Date: Tue, 31 Jul 2018 17:30:26 +0200 Subject: [PATCH 1/4] Add su directive as option for logroate --- data/helpers.d/backend | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/data/helpers.d/backend b/data/helpers.d/backend index 8dce2df06..43cbec1f0 100644 --- a/data/helpers.d/backend +++ b/data/helpers.d/backend @@ -1,8 +1,9 @@ # Use logrotate to manage the logfile # -# usage: ynh_use_logrotate [logfile] [--non-append] +# usage: ynh_use_logrotate [logfile] [--non-append|--append] [specific_user/specific_group] # | arg: logfile - absolute path of logfile # | arg: --non-append - (Option) Replace the config file instead of appending this new config. +# | arg: specific_user : run logrotate as the specified user and group. If not specified logrotate is runned as root. # # 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. @@ -13,6 +14,7 @@ # Unless you use the option --non-append ynh_use_logrotate () { local customtee="tee -a" + local user_group="${3:-}" if [ $# -gt 0 ] && [ "$1" == "--non-append" ]; then customtee="tee" # Destroy this argument for the next command. @@ -29,6 +31,12 @@ ynh_use_logrotate () { else local logfile="/var/log/${app}/*.log" # Without argument, use a defaut directory in /var/log fi + local su_directive="" + if [[ -n $user_group ]]; then + su_directive=" # Run logorotate as specific user - group + su ${user_group#*/} ${user_group%/*}" + fi + cat > ./${app}-logrotate << EOF # Build a config file for logrotate $logfile { # Rotate if the logfile exceeds 100Mo @@ -47,6 +55,7 @@ $logfile { notifempty # Keep old logs in the same dir noolddir + $su_directive } EOF sudo mkdir -p $(dirname "$logfile") # Create the log directory, if not exist From 36fd98e0207da5063456e52ff333f5b00ebd13b8 Mon Sep 17 00:00:00 2001 From: Josue-T Date: Fri, 3 Aug 2018 09:38:39 +0200 Subject: [PATCH 2/4] Fix switch user/group --- data/helpers.d/backend | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/helpers.d/backend b/data/helpers.d/backend index 43cbec1f0..94e26350c 100644 --- a/data/helpers.d/backend +++ b/data/helpers.d/backend @@ -34,7 +34,7 @@ ynh_use_logrotate () { local su_directive="" if [[ -n $user_group ]]; then su_directive=" # Run logorotate as specific user - group - su ${user_group#*/} ${user_group%/*}" + su ${user_group%/*} ${user_group#*/}" fi cat > ./${app}-logrotate << EOF # Build a config file for logrotate From 26fe3d8c95e691f56f793fcfb9957565f0a844a2 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Sun, 2 Sep 2018 18:02:32 +0200 Subject: [PATCH 3/4] Indentation typo --- data/helpers.d/backend | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/helpers.d/backend b/data/helpers.d/backend index 94e26350c..48031d415 100644 --- a/data/helpers.d/backend +++ b/data/helpers.d/backend @@ -34,7 +34,7 @@ ynh_use_logrotate () { local su_directive="" if [[ -n $user_group ]]; then su_directive=" # Run logorotate as specific user - group - su ${user_group%/*} ${user_group#*/}" + su ${user_group%/*} ${user_group#*/}" fi cat > ./${app}-logrotate << EOF # Build a config file for logrotate From 22cff38bbb700dedc904b771b3af8b481259d10a Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Wed, 5 Sep 2018 19:57:11 +0200 Subject: [PATCH 4/4] Revert Indentation typo It's part of the syntax --- data/helpers.d/backend | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/helpers.d/backend b/data/helpers.d/backend index 48031d415..94e26350c 100644 --- a/data/helpers.d/backend +++ b/data/helpers.d/backend @@ -34,7 +34,7 @@ ynh_use_logrotate () { local su_directive="" if [[ -n $user_group ]]; then su_directive=" # Run logorotate as specific user - group - su ${user_group%/*} ${user_group#*/}" + su ${user_group%/*} ${user_group#*/}" fi cat > ./${app}-logrotate << EOF # Build a config file for logrotate