From f4df9203092e961c0a07ae60b60ebb9e79f3a047 Mon Sep 17 00:00:00 2001 From: Willy Barro Date: Wed, 17 Oct 2012 16:52:50 -0300 Subject: [PATCH] Improvements on nginx plugin. Fixed nginx_reload and added NGINX_PID_PATH variable. - Modify nginx_reload function to use the correct "-s reload" attribute on nginx executable. - Add NGINX_PID_PATH variable on bash_profile.template.bash to allow users to provide pid files on any directory, not just on $NGINX_PATH/logs/. - Modify nginx_restart to call nginx_stop and nginx_start - Add path information on pid not found error. --- plugins/available/nginx.plugin.bash | 34 ++++++++++------------------- template/bash_profile.template.bash | 5 +++-- 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/plugins/available/nginx.plugin.bash b/plugins/available/nginx.plugin.bash index 660b5035..e03943be 100644 --- a/plugins/available/nginx.plugin.bash +++ b/plugins/available/nginx.plugin.bash @@ -5,28 +5,21 @@ function nginx_reload() { about 'reload your nginx config' group 'nginx' - FILE="${NGINX_PATH}/logs/nginx.pid" - if [ -e $FILE ]; then - echo "Reloading NGINX..." - PID=`cat $NGINX_PATH/logs/nginx.pid` - sudo kill -HUP $PID - else - echo "Nginx pid file not found" - return 0 - fi + echo "Reloading NGINX..." + sudo $NGINX_PATH/nginx -s reload } function nginx_stop() { about 'stop nginx' group 'nginx' - FILE="${NGINX_PATH}/logs/nginx.pid" + FILE="${NGINX_PID_PATH}/nginx.pid" if [ -e $FILE ]; then echo "Stopping NGINX..." - PID=`cat $NGINX_PATH/logs/nginx.pid` + PID=`cat $NGINX_PID_PATH/nginx.pid` sudo kill -INT $PID else - echo "Nginx pid file not found" + echo "Nginx pid file not found at: ${FILE}" return 0 fi } @@ -35,10 +28,10 @@ function nginx_start() { about 'start nginx' group 'nginx' - FILE="${NGINX_PATH}/sbin/nginx" + FILE="${NGINX_PATH}/nginx" if [ -e $FILE ]; then echo "Starting NGINX..." - sudo $NGINX_PATH/sbin/nginx + sudo $NGINX_PATH/nginx else echo "Couldn't start nginx" fi @@ -48,16 +41,13 @@ function nginx_restart() { about 'restart nginx' group 'nginx' - FILE="${NGINX_PATH}/logs/nginx.pid" + FILE="${NGINX_PID_PATH}/nginx.pid" if [ -e $FILE ]; then - echo "Stopping NGINX..." - PID=`cat $NGINX_PATH/logs/nginx.pid` - sudo kill -INT $PID - sleep 1 - echo "Starting NGINX..." - sudo $NGINX_PATH/sbin/nginx + nginx_stop + nginx_start + echo "Done!" else - echo "Nginx pid file not found" + echo "Nginx pid file not found at: ${FILE}" return 0 fi } diff --git a/template/bash_profile.template.bash b/template/bash_profile.template.bash index 60cac9ea..170da832 100644 --- a/template/bash_profile.template.bash +++ b/template/bash_profile.template.bash @@ -17,11 +17,12 @@ export BASH_IT_THEME='bobby' export GIT_HOSTING='git@git.domain.com' # Set my editor and git editor -export EDITOR="/usr/bin/mate -w" +export EDITOR='/usr/bin/mate -w' export GIT_EDITOR='/usr/bin/mate -w' # Set the path nginx -export NGINX_PATH='/opt/nginx' +export NGINX_PATH='/opt/nginx/sbin' +export NGINX_PID_PATH=${NGINX_PATH}'/logs' # Don't check mail when opening terminal. unset MAILCHECK