소스 검색

Remove warning message when restarting (systemctl restart)

Laurent HUBERT 9 달 전
부모
커밋
fb292cb305
1개의 변경된 파일23개의 추가작업 그리고 9개의 파일을 삭제
  1. 23 9
      scripts/lfirewall

+ 23 - 9
scripts/lfirewall

@@ -86,6 +86,8 @@ find_systemctl_pids(){
 }
 process_and_parent=`find_systemctl_pids`
 
+restart_mode=no
+
 if [ -n "${process_and_parent}" ]
 then
 	if has_parent_process ${process_and_parent}
@@ -93,6 +95,15 @@ then
 		shell_process=`echo ${process_and_parent} | awk '{print $1}'`
 		parent_term=`readlink /proc/${shell_process}/fd/2`
 	fi
+
+	# Find if systemctl is in restart mode
+	for process_id in ${process_and_parent}
+	do
+		if [ `ps -o comm= -p $process_id` = "systemctl" ]
+		then
+			restart_mode=`ps -o args -p $process_id | grep -v COMMAND | grep restart && echo yes || echo no`
+		fi
+	done
 fi
 
 set -eu
@@ -754,15 +765,18 @@ case "$1" in
 		then
 			exec 2>${parent_term}
 		fi
-		printf "###############################################################\n\r" >&2
-		printf "#                   IMPORTANT WARNING !!!                     #\n\r" >&2
-		printf "# From now any new SSH session or INPUT                       #\n\r" >&2
-		printf "#                      WILL BE REFUSED                        #\n\r" >&2
-		printf "# If you NEED to continue working remotely,                   #\n\r" >&2
-		printf "# run one of the 'lfirewall clear', 'lfirewall stop'          #\n\r" >&2
-		printf "# 'lfirewall start' commands                                  #\n\r" >&2
-		printf "#                           NOW !!!                           #\n\r" >&2
-		printf "###############################################################\n\r" >&2
+		if [ "${restart_mode}" = "no" ]
+		then
+			printf "###############################################################\n\r" >&2
+			printf "#                   IMPORTANT WARNING !!!                     #\n\r" >&2
+			printf "# From now any new SSH session or INPUT                       #\n\r" >&2
+			printf "#                      WILL BE REFUSED                        #\n\r" >&2
+			printf "# If you NEED to continue working remotely,                   #\n\r" >&2
+			printf "# run one of the 'lfirewall clear', 'lfirewall stop'          #\n\r" >&2
+			printf "# 'lfirewall start' commands                                  #\n\r" >&2
+			printf "#                           NOW !!!                           #\n\r" >&2
+			printf "###############################################################\n\r" >&2
+		fi
 	;;
 	test)
 		echo "Test Firewall rules..."