@@ -57,6 +57,34 @@ dbus_rm() {
5757 fi
5858}
5959
60+ check_usb2jffs_used_status () {
61+ # 查看当前/jffs的挂载点是什么设备,如/dev/mtdblock9, /dev/sda1;有usb2jffs的时候,/dev/sda1,无usb2jffs的时候,/dev/mtdblock9,出问题未正确挂载的时候,为空
62+ local cur_patition=$( df -h | /bin/grep /jffs | awk ' {print $1}' )
63+ local jffs_device=" not mount"
64+ if [ -n " ${cur_patition} " ]; then
65+ jffs_device=${cur_patition}
66+ fi
67+ local mounted_nu=$( mount | /bin/grep " ${jffs_device} " | grep -E " /tmp/mnt/|/jffs" | /bin/grep -c " /dev/s" )
68+ if [ " ${mounted_nu} " -eq " 2" ]; then
69+ echo " 1" # 已安装并成功挂载
70+ else
71+ echo " 0" # 未安装或未挂载
72+ fi
73+ }
74+
75+ start_jffs_test (){
76+ if [ $( check_usb2jffs_used_status) == " 1" ] && [ " ${1} " == " start" ]; then
77+ echo_date " ➡️检测到已安装插件usb2jffs并成功挂载,插件可以正常启动!"
78+ else
79+ local LINUX_VER=$( uname -r | awk -F" ." ' {print $1$2}' )
80+ if [ " $LINUX_VER " = 41 ]; then # 报错停止
81+ echo_date " ❌️jffs分区不支持db文件读写,插件停止启动"
82+ echo_date " ❌️请安装安装usb2jffs插件并成功挂载后再次尝试!"
83+ exit 0
84+ fi
85+ fi
86+ }
87+
6088check_port_used () {
6189 local port_used=$( netstat -nat | awk -v p1=" $hbbs_used_port " -v p2=" $hbbs_used_port1 " -v p3=" $hbbs_used_port2 " -v p4=" $hbbr_used_port " -v p5=" $hbbr_used_port1 " ' $4 ~ ":"p1"$" || $4 ~ ":"p2"$" || $4 ~ ":"p3"$" || $4 ~ ":"p4"$" || $4 ~ ":"p5"$"' | head -n 1)
6290 # 最大尝试60次,每次休眠2秒
@@ -85,37 +113,6 @@ check_port_used() {
85113 fi
86114}
87115
88- start () {
89- # 0. config ENV
90- configServerEnv
91-
92- # 1. stop first
93- stop_process
94-
95- # 2. start process
96- # 2.1 check_port_used
97- check_port_used
98- # 2.2 start process
99- start_process
100-
101- # 3. open port
102- close_port > /dev/null 2>&1
103- open_port
104-
105- echo_date " ✅️插件已成功开启!"
106- }
107-
108- stop_plugin () {
109- # 1. stop process
110- stop_process
111- # 2.close prot
112- close_port > /dev/null 2>&1
113-
114- dbus set rustdesk_enable=0
115-
116- echo_date " ❌️插件已停止运行!"
117- }
118-
119116configServerPort (){
120117 if [ $( number_test ${rustdesk_hbbs_port} ) != " 0" ]; then
121118 dbus set rustdesk_hbbs_port=" 21116"
@@ -142,33 +139,6 @@ configServerEnv() {
142139 configServerPort
143140}
144141
145- start_process () {
146- start_hbbs
147- start_hbbr
148- if [ -z ${bin_all_run} ]; then
149- echo_date " ❌️进程启动失败,停止插件..."
150- stop_plugin
151- exit
152- fi
153- }
154-
155- detect_running_status () {
156- local BINNAME=$1
157- local PID
158- local i=40
159- until [ -n " ${PID} " ]; do
160- usleep 250000
161- i=$(( $i - 1 ))
162- PID=$( pidof ${BINNAME} )
163- if [ " $i " -lt 1 ]; then
164- echo_date " 🔴$1 进程启动失败,请检查你的配置!"
165- bin_all_run=" "
166- return
167- fi
168- done
169- echo_date " 🟢$1 启动成功,pid:${PID} "
170- }
171-
172142start_hbbs () {
173143 HBBS_RUN_LOG=/tmp/upload/rustdesk_hbbs_run_log.txt
174144 rm -rf ${HBBS_RUN_LOG}
@@ -229,11 +199,6 @@ start_hbbr() {
229199 detect_running_status hbbr
230200}
231201
232- stop_process () {
233- kill_process " hbbs"
234- kill_process " hbbr"
235- }
236-
237202kill_process () {
238203 if [ -f " /koolshare/perp/$1 /rc.main" ]; then
239204 perpctl d $1 > /dev/null 2>&1
@@ -329,6 +294,70 @@ check_status() {
329294 http_response $status_text
330295}
331296
297+ stop_process () {
298+ kill_process " hbbs"
299+ kill_process " hbbr"
300+ }
301+
302+ stop_plugin () {
303+ # 1. stop process
304+ stop_process
305+ # 2.close prot
306+ close_port > /dev/null 2>&1
307+
308+ dbus set rustdesk_enable=0
309+
310+ echo_date " ❌️插件已停止运行!"
311+ }
312+
313+ start_process () {
314+ start_hbbs
315+ start_hbbr
316+ if [ -z ${bin_all_run} ]; then
317+ echo_date " ❌️进程启动失败,停止插件..."
318+ stop_plugin
319+ exit
320+ fi
321+ }
322+
323+ start () {
324+ # 0. test jffs and config ENV
325+ start_jffs_test " start"
326+ configServerEnv
327+
328+ # 1. stop first
329+ stop_process
330+
331+ # 2. start process
332+ # 2.1 check_port_used
333+ check_port_used
334+ # 2.2 start process
335+ start_process
336+
337+ # 3. open port
338+ close_port > /dev/null 2>&1
339+ open_port
340+
341+ echo_date " ✅️插件已成功开启!"
342+ }
343+
344+ detect_running_status () {
345+ local BINNAME=$1
346+ local PID
347+ local i=40
348+ until [ -n " ${PID} " ]; do
349+ usleep 250000
350+ i=$(( $i - 1 ))
351+ PID=$( pidof ${BINNAME} )
352+ if [ " $i " -lt 1 ]; then
353+ echo_date " 🔴$1 进程启动失败,请检查你的配置!"
354+ bin_all_run=" "
355+ return
356+ fi
357+ done
358+ echo_date " 🟢$1 启动成功,pid:${PID} "
359+ }
360+
332361regenerateKey () {
333362 echo_date " ℹ️开始重新生成安全密钥对..."
334363 /koolshare/bin/rustdesk-utils genkeypair | awk ' {print $3}' > /tmp/upload/rustdesk_key_cert.tmp
0 commit comments