|
1 |
| -cite about-plugin |
| 1 | +# shellcheck shell=bash |
2 | 2 | about-plugin 'manage your nginx service'
|
3 | 3 |
|
4 |
| -export NGINX_PATH='/opt/nginx' |
5 |
| -pathmunge $NGINX_PATH/sbin after |
| 4 | +pathmunge "${NGINX_PATH:=/opt/nginx}/sbin" after |
| 5 | +export NGINX_PATH |
6 | 6 |
|
7 | 7 | 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 |
20 | 20 | }
|
21 | 21 |
|
22 | 22 | 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 |
35 | 35 | }
|
36 | 36 |
|
37 | 37 | 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 |
48 | 48 | }
|
49 | 49 |
|
50 | 50 | function nginx_restart() {
|
51 |
| - about 'restart nginx' |
52 |
| - group 'nginx' |
| 51 | + about 'restart nginx' |
| 52 | + group 'nginx' |
53 | 53 |
|
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 |
66 | 55 | }
|
0 commit comments