Skip to content

Commit 21e7c1f

Browse files
authored
Merge pull request #2011 from gaelicWizard/plugin-nginx
plugin/nginx: cleanup
2 parents af801cf + 079652e commit 21e7c1f

File tree

2 files changed

+41
-51
lines changed

2 files changed

+41
-51
lines changed

clean_files.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ plugins/available/jekyll.plugin.bash
105105
plugins/available/jump.plugin.bash
106106
plugins/available/less-pretty-cat.plugin.bash
107107
plugins/available/man.plugin.bash
108+
plugins/available/nginx.plugin.bash
108109
plugins/available/node.plugin.bash
109110
plugins/available/nodenv.plugin.bash
110111
plugins/available/osx-timemachine.plugin.bash

plugins/available/nginx.plugin.bash

Lines changed: 40 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,55 @@
1-
cite about-plugin
1+
# shellcheck shell=bash
22
about-plugin 'manage your nginx service'
33

4-
export NGINX_PATH='/opt/nginx'
5-
pathmunge $NGINX_PATH/sbin after
4+
pathmunge "${NGINX_PATH:=/opt/nginx}/sbin" after
5+
export NGINX_PATH
66

77
function nginx_reload() {
8-
about 'reload your nginx config'
9-
group 'nginx'
10-
11-
FILE="${NGINX_PATH}/logs/nginx.pid"
12-
if [ -e $FILE ]; then
13-
echo "Reloading NGINX..."
14-
PID=`cat $NGINX_PATH/logs/nginx.pid`
15-
sudo kill -HUP $PID
16-
else
17-
echo "Nginx pid file not found"
18-
return 0
19-
fi
8+
about 'reload your nginx config'
9+
group 'nginx'
10+
11+
local FILE="${NGINX_PATH?}/logs/nginx.pid"
12+
if [[ -s $FILE ]]; then
13+
echo "Reloading NGINX..."
14+
read -r PID < "${FILE}"
15+
sudo kill -HUP "${PID?}"
16+
else
17+
echo "Nginx pid file not found"
18+
return 0
19+
fi
2020
}
2121

2222
function nginx_stop() {
23-
about 'stop nginx'
24-
group 'nginx'
25-
26-
FILE="${NGINX_PATH}/logs/nginx.pid"
27-
if [ -e $FILE ]; then
28-
echo "Stopping NGINX..."
29-
PID=`cat $NGINX_PATH/logs/nginx.pid`
30-
sudo kill -INT $PID
31-
else
32-
echo "Nginx pid file not found"
33-
return 0
34-
fi
23+
about 'stop nginx'
24+
group 'nginx'
25+
26+
local FILE="${NGINX_PATH?}/logs/nginx.pid"
27+
if [[ -s $FILE ]]; then
28+
echo "Stopping NGINX..."
29+
read -r PID < "${FILE}"
30+
sudo kill -INT "${PID?}"
31+
else
32+
echo "Nginx pid file not found"
33+
return 0
34+
fi
3535
}
3636

3737
function nginx_start() {
38-
about 'start nginx'
39-
group 'nginx'
40-
41-
FILE="${NGINX_PATH}/sbin/nginx"
42-
if [ -e $FILE ]; then
43-
echo "Starting NGINX..."
44-
sudo $NGINX_PATH/sbin/nginx
45-
else
46-
echo "Couldn't start nginx"
47-
fi
38+
about 'start nginx'
39+
group 'nginx'
40+
41+
local FILE="${NGINX_PATH?}/sbin/nginx"
42+
if [[ -x $FILE ]]; then
43+
echo "Starting NGINX..."
44+
sudo "${FILE}"
45+
else
46+
echo "Couldn't start nginx"
47+
fi
4848
}
4949

5050
function nginx_restart() {
51-
about 'restart nginx'
52-
group 'nginx'
51+
about 'restart nginx'
52+
group 'nginx'
5353

54-
FILE="${NGINX_PATH}/logs/nginx.pid"
55-
if [ -e $FILE ]; then
56-
echo "Stopping NGINX..."
57-
PID=`cat $NGINX_PATH/logs/nginx.pid`
58-
sudo kill -INT $PID
59-
sleep 1
60-
echo "Starting NGINX..."
61-
sudo $NGINX_PATH/sbin/nginx
62-
else
63-
echo "Nginx pid file not found"
64-
return 0
65-
fi
54+
nginx_stop && nginx_start
6655
}

0 commit comments

Comments
 (0)