|
6 | 6 | # Try to run "bash -version" to check the version. |
7 | 7 | # Try to visit WIKI to find a solution. |
8 | 8 |
|
9 | | -VER=1.8.2 |
| 9 | +VER=1.9.0 |
10 | 10 |
|
11 | 11 | PROJECT_NAME="httpsok" |
12 | 12 | PROJECT_ENTRY="httpsok.sh" |
@@ -128,11 +128,20 @@ _no_nginx_here(){ |
128 | 128 | echo |
129 | 129 | _err "Can’t detected nginx\n" |
130 | 130 | _err "Please confirm that nginx has been successfully installed on your system" |
| 131 | + _detecte_is_root_run |
131 | 132 | echo |
132 | 133 | echo |
133 | 134 | exit |
134 | 135 | } |
135 | 136 |
|
| 137 | +_detecte_is_root_run(){ |
| 138 | + YELLOW='\033[1;33m' |
| 139 | + NC='\033[0m' # No Color |
| 140 | + if [ "$(id -u)" -ne 0 ]; then |
| 141 | + echo -e "${YELLOW}Detected non-root user running, it's recommended to run as root user.${NC}\n" |
| 142 | + fi |
| 143 | +} |
| 144 | + |
136 | 145 | _initparams() { |
137 | 146 |
|
138 | 147 | if [ "$OS" != "" ]; then |
@@ -163,7 +172,7 @@ _initparams() { |
163 | 172 | # again to verify |
164 | 173 | $nginx_bin -V > /dev/null 2>&1 |
165 | 174 | if [ $? -ne 0 ]; then |
166 | | - _no_nginx_here |
| 175 | + _no_nginx_here |
167 | 176 | else |
168 | 177 | echo "Nginx executable path: $nginx_bin" |
169 | 178 | fi |
@@ -211,7 +220,7 @@ _post2() { |
211 | 220 | _inithttp |
212 | 221 | url="${BASE_API_URL}$1" |
213 | 222 | fiename="$2" |
214 | | - curl -s -X POST -H "$_H0" -H "$_H1" -H "$_H2" -H "$_H3" -H "$_H4" -H "$_H5" -H "$_H6" -H "$_H7" -H "$_H8" --data-binary "@$fiename" "$url" |
| 223 | + curl -s -X POST -H "$_H0" -H "$_H1" -H "$_H2" -H "$_H3" -H "$_H4" -H "$_H5" -H "$_H6" -H "$_H7" -H "$_H8" --data-binary "@$fiename" "$url" |
215 | 224 | } |
216 | 225 |
|
217 | 226 | _get() { |
@@ -505,7 +514,7 @@ _preparse() { |
505 | 514 | tmp_name="/tmp/2nLN3ZspTMGifYtO.tmp" |
506 | 515 | echo "$config_text" > $tmp_name |
507 | 516 | preparse=$(_post2 "/preparse" "$tmp_name") |
508 | | - rm -rf "$tmp_name" > /etc/null 2&>1 |
| 517 | + rm -rf "$tmp_name" > /dev/null 2&>1 |
509 | 518 | if [ "$preparse" = "" ]; then |
510 | 519 | return 4 |
511 | 520 | fi |
@@ -577,23 +586,37 @@ _reload_nginx() { |
577 | 586 | return 0 |
578 | 587 | fi |
579 | 588 |
|
580 | | - msg=$($nginx_bin -t 2>&1) |
581 | | - if [ $? != 0 ]; then |
582 | | - _remote_log "nginx-test-failed" "$latest_code" "$msg" |
583 | | - echo |
584 | | - _err "Nginx test failed." |
585 | | - else |
586 | | - msg=$($nginx_bin -s reload 2>&1) |
587 | | - if [ "$msg" = "" ]; then |
588 | | - _remote_log "nginx-reload-success" "$latest_code" "Nginx reload success." |
| 589 | + ( |
| 590 | + # fixbug: signal process started |
| 591 | + cd $NGINX_CONFIG_HOME |
| 592 | + |
| 593 | + msg=$($nginx_bin -t 2>&1) |
| 594 | + if [ $? != 0 ]; then |
| 595 | + _remote_log "nginx-test-failed" "$latest_code" "$msg" |
589 | 596 | echo |
590 | | - _suc "Nginx reload success." |
| 597 | + _err "Nginx test failed." |
591 | 598 | else |
592 | | - _remote_log "nginx-reload-failed" "$latest_code" "$msg" |
593 | | - echo |
594 | | - _err "Nginx reload failed. \n\n\n$msg" |
| 599 | + msg=$($nginx_bin -s reload 2>&1) |
| 600 | + if [ "$msg" = "" ]; then |
| 601 | + _remote_log "nginx-reload-success" "$latest_code" "Nginx reload success." |
| 602 | + echo |
| 603 | + _suc "Nginx reload success." |
| 604 | + else |
| 605 | + |
| 606 | + # Check if nginx is running |
| 607 | + show_msg=$msg |
| 608 | + pid=$(ps -e | grep nginx | grep -v 'grep' | head -n 1 | awk '{print $1}') |
| 609 | + if [ -z "$pid" ]; then |
| 610 | + msg="Nginx is not started. \n\n$msg" |
| 611 | + show_msg="\033[33mNginx is not started. You can run \"service nginx start\" to start the Nginx. \033[31m\n\n$show_msg" |
| 612 | + fi |
| 613 | + |
| 614 | + _remote_log "nginx-reload-failed" "$latest_code" "$msg" |
| 615 | + echo |
| 616 | + _err "Nginx reload failed. \n\n$show_msg" |
| 617 | + fi |
595 | 618 | fi |
596 | | - fi |
| 619 | + ) |
597 | 620 | } |
598 | 621 |
|
599 | 622 | version() { |
|
0 commit comments