From cca49230d9458c3393fcd739ed98623af433d9c7 Mon Sep 17 00:00:00 2001 From: Jiahao Li Date: Thu, 30 Jul 2015 00:43:32 -0700 Subject: [PATCH 1/2] Add nginx:access-logs and nginx:error-logs. Add two nginx subcommands to display nginx error/access logs for a particular app. --- plugins/nginx-vhosts/commands | 21 +++++++++++++++++++++ plugins/nginx-vhosts/install | 2 ++ 2 files changed, 23 insertions(+) diff --git a/plugins/nginx-vhosts/commands b/plugins/nginx-vhosts/commands index be64d1751..3699f25f7 100755 --- a/plugins/nginx-vhosts/commands +++ b/plugins/nginx-vhosts/commands @@ -159,9 +159,30 @@ EOF fi fi ;; + + nginx:access-logs|nginx:error-logs) + [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 + verify_app_name "$2" + APP="$2" + + NGINX_LOGS_TYPE=${1#nginx:} + NGINX_LOGS_TYPE=${NGINX_LOGS_TYPE%-logs} + NGINX_LOGS_PATH="/var/log/nginx/$APP-$NGINX_LOGS_TYPE.log" + + if [[ $3 == "-t" ]]; then + NGINX_LOGS_ARGS="-F" + else + NGINX_LOGS_ARGS="-n 20" + fi + + sudo tail "$NGINX_LOGS_ARGS" "$NGINX_LOGS_PATH" + ;; + help | nginx:help) cat<, (Re)builds nginx config for given app + nginx:access-logs [-t], Show the nginx access logs for an application (-t follows) + nginx:error-logs [-t], Show the nginx error logs for an application (-t follows) EOF ;; diff --git a/plugins/nginx-vhosts/install b/plugins/nginx-vhosts/install index c348c3b22..674b00a87 100755 --- a/plugins/nginx-vhosts/install +++ b/plugins/nginx-vhosts/install @@ -4,10 +4,12 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x case "$DOKKU_DISTRO" in ubuntu) echo "%dokku ALL=(ALL) NOPASSWD:/etc/init.d/nginx reload, /usr/sbin/nginx -t" > /etc/sudoers.d/dokku-nginx + echo "%dokku ALL=(ALL) NOPASSWD:/usr/bin/tail" >> /etc/sudoers.d/dokku-nginx ;; opensuse) echo "%dokku ALL=(ALL) NOPASSWD:/sbin/service nginx reload, /usr/sbin/nginx -t" > /etc/sudoers.d/dokku-nginx + echo "%dokku ALL=(ALL) NOPASSWD:/usr/bin/tail" >> /etc/sudoers.d/dokku-nginx ;; esac From 72a1b76b6380e6fee28549569f7e856090dbd2e8 Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Tue, 15 Sep 2015 10:15:22 -0700 Subject: [PATCH 2/2] don't require sudo for tailing logs since we're root anyway --- dokku | 2 +- plugins/nginx-vhosts/commands | 2 +- plugins/nginx-vhosts/install | 2 -- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/dokku b/dokku index 3dd1f314c..d335e8508 100755 --- a/dokku +++ b/dokku @@ -41,7 +41,7 @@ if [[ "${args[0]}" =~ ^--.* ]]; then fi ! has_tty && DOKKU_QUIET_OUTPUT=1 -if [[ $(id -un) != "dokku" && $1 != plugin:*install* && $1 != "plugin:update" ]]; then +if [[ $(id -un) != "dokku" && $1 != plugin:*install* && $1 != "plugin:update" && $1 != nginx:*-logs ]]; then sudo -u dokku -E -H $0 "$@" exit fi diff --git a/plugins/nginx-vhosts/commands b/plugins/nginx-vhosts/commands index 3699f25f7..b965951ff 100755 --- a/plugins/nginx-vhosts/commands +++ b/plugins/nginx-vhosts/commands @@ -175,7 +175,7 @@ EOF NGINX_LOGS_ARGS="-n 20" fi - sudo tail "$NGINX_LOGS_ARGS" "$NGINX_LOGS_PATH" + tail "$NGINX_LOGS_ARGS" "$NGINX_LOGS_PATH" ;; help | nginx:help) diff --git a/plugins/nginx-vhosts/install b/plugins/nginx-vhosts/install index 674b00a87..c348c3b22 100755 --- a/plugins/nginx-vhosts/install +++ b/plugins/nginx-vhosts/install @@ -4,12 +4,10 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x case "$DOKKU_DISTRO" in ubuntu) echo "%dokku ALL=(ALL) NOPASSWD:/etc/init.d/nginx reload, /usr/sbin/nginx -t" > /etc/sudoers.d/dokku-nginx - echo "%dokku ALL=(ALL) NOPASSWD:/usr/bin/tail" >> /etc/sudoers.d/dokku-nginx ;; opensuse) echo "%dokku ALL=(ALL) NOPASSWD:/sbin/service nginx reload, /usr/sbin/nginx -t" > /etc/sudoers.d/dokku-nginx - echo "%dokku ALL=(ALL) NOPASSWD:/usr/bin/tail" >> /etc/sudoers.d/dokku-nginx ;; esac