Skip to content

Commit ebf389e

Browse files
committed
v1.9.0 新特性
- 增加nginx运行状态提示 - 增加DNS解析检测提醒 - 优化DNS解析检查 - 解决nginx重载失败问题
1 parent 70e174a commit ebf389e

File tree

1 file changed

+41
-18
lines changed

1 file changed

+41
-18
lines changed

httpsok.sh

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# Try to run "bash -version" to check the version.
77
# Try to visit WIKI to find a solution.
88

9-
VER=1.8.2
9+
VER=1.9.0
1010

1111
PROJECT_NAME="httpsok"
1212
PROJECT_ENTRY="httpsok.sh"
@@ -128,11 +128,20 @@ _no_nginx_here(){
128128
echo
129129
_err "Can’t detected nginx\n"
130130
_err "Please confirm that nginx has been successfully installed on your system"
131+
_detecte_is_root_run
131132
echo
132133
echo
133134
exit
134135
}
135136

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+
136145
_initparams() {
137146

138147
if [ "$OS" != "" ]; then
@@ -163,7 +172,7 @@ _initparams() {
163172
# again to verify
164173
$nginx_bin -V > /dev/null 2>&1
165174
if [ $? -ne 0 ]; then
166-
_no_nginx_here
175+
_no_nginx_here
167176
else
168177
echo "Nginx executable path: $nginx_bin"
169178
fi
@@ -211,7 +220,7 @@ _post2() {
211220
_inithttp
212221
url="${BASE_API_URL}$1"
213222
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"
215224
}
216225

217226
_get() {
@@ -505,7 +514,7 @@ _preparse() {
505514
tmp_name="/tmp/2nLN3ZspTMGifYtO.tmp"
506515
echo "$config_text" > $tmp_name
507516
preparse=$(_post2 "/preparse" "$tmp_name")
508-
rm -rf "$tmp_name" > /etc/null 2&>1
517+
rm -rf "$tmp_name" > /dev/null 2&>1
509518
if [ "$preparse" = "" ]; then
510519
return 4
511520
fi
@@ -577,23 +586,37 @@ _reload_nginx() {
577586
return 0
578587
fi
579588

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"
589596
echo
590-
_suc "Nginx reload success."
597+
_err "Nginx test failed."
591598
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
595618
fi
596-
fi
619+
)
597620
}
598621

599622
version() {

0 commit comments

Comments
 (0)