Skip to content

Commit

Permalink
Merge pull request #2011 from gaelicWizard/plugin-nginx
Browse files Browse the repository at this point in the history
plugin/nginx: cleanup
  • Loading branch information
NoahGorny authored Jan 8, 2022
2 parents af801cf + 079652e commit 21e7c1f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 51 deletions.
1 change: 1 addition & 0 deletions clean_files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ plugins/available/jekyll.plugin.bash
plugins/available/jump.plugin.bash
plugins/available/less-pretty-cat.plugin.bash
plugins/available/man.plugin.bash
plugins/available/nginx.plugin.bash
plugins/available/node.plugin.bash
plugins/available/nodenv.plugin.bash
plugins/available/osx-timemachine.plugin.bash
Expand Down
91 changes: 40 additions & 51 deletions plugins/available/nginx.plugin.bash
Original file line number Diff line number Diff line change
@@ -1,66 +1,55 @@
cite about-plugin
# shellcheck shell=bash
about-plugin 'manage your nginx service'

export NGINX_PATH='/opt/nginx'
pathmunge $NGINX_PATH/sbin after
pathmunge "${NGINX_PATH:=/opt/nginx}/sbin" after
export NGINX_PATH

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
about 'reload your nginx config'
group 'nginx'

local FILE="${NGINX_PATH?}/logs/nginx.pid"
if [[ -s $FILE ]]; then
echo "Reloading NGINX..."
read -r PID < "${FILE}"
sudo kill -HUP "${PID?}"
else
echo "Nginx pid file not found"
return 0
fi
}

function nginx_stop() {
about 'stop nginx'
group 'nginx'

FILE="${NGINX_PATH}/logs/nginx.pid"
if [ -e $FILE ]; then
echo "Stopping NGINX..."
PID=`cat $NGINX_PATH/logs/nginx.pid`
sudo kill -INT $PID
else
echo "Nginx pid file not found"
return 0
fi
about 'stop nginx'
group 'nginx'

local FILE="${NGINX_PATH?}/logs/nginx.pid"
if [[ -s $FILE ]]; then
echo "Stopping NGINX..."
read -r PID < "${FILE}"
sudo kill -INT "${PID?}"
else
echo "Nginx pid file not found"
return 0
fi
}

function nginx_start() {
about 'start nginx'
group 'nginx'

FILE="${NGINX_PATH}/sbin/nginx"
if [ -e $FILE ]; then
echo "Starting NGINX..."
sudo $NGINX_PATH/sbin/nginx
else
echo "Couldn't start nginx"
fi
about 'start nginx'
group 'nginx'

local FILE="${NGINX_PATH?}/sbin/nginx"
if [[ -x $FILE ]]; then
echo "Starting NGINX..."
sudo "${FILE}"
else
echo "Couldn't start nginx"
fi
}

function nginx_restart() {
about 'restart nginx'
group 'nginx'
about 'restart nginx'
group 'nginx'

FILE="${NGINX_PATH}/logs/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
else
echo "Nginx pid file not found"
return 0
fi
nginx_stop && nginx_start
}

0 comments on commit 21e7c1f

Please sign in to comment.