-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
rustdesk-server: add the init.d and uci file for rustdesk-server
- Added an init.d file to enable automatic startup of rustdesk-server on boot. - Added a uci configuration file to uniformly control the behavior of the rustdesk-server program and support integration with the luci application. - Since the program itself does not support custom working directories, and OpenWRT's init.d does not have parameters to set the working directory, using `cd` in the init script seems to be the best solution without patching the source code. This approach will not impact performance under the current requirements. Signed-off-by: Yun Wang <[email protected]> (cherry picked from commit d2f507a)
1 parent
45b174f
commit ac37f27
Showing
3 changed files
with
129 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
config firewall 'firewall' | ||
option auto_fw '0' | ||
option web_client '0' | ||
|
||
config relay 'hbbr' | ||
option enabled '0' | ||
option port '21117' | ||
|
||
config server 'hbbs' | ||
option enabled '0' | ||
option port '21116' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
#!/bin/sh /etc/rc.common | ||
|
||
USE_PROCD=1 | ||
START=99 | ||
|
||
CONF="rustdesk" | ||
WORKDIR="/etc/rustdesk" | ||
|
||
start_service() { | ||
local HBBS_TCP_PORTS="" | ||
local HBBS_UDP_PORTS="" | ||
local HBBR_TCP_PORTS="" | ||
|
||
config_load "$CONF" | ||
config_get_bool auto_fw "firewall" "auto_fw" "0" | ||
config_get_bool web_client "firewall" "web_client" "0" | ||
config_get_bool hbbr_enabled "hbbr" "enabled" "0" | ||
config_get hbbr_port "hbbr" "port" "21117" | ||
config_get_bool hbbs_enabled "hbbs" "enabled" "0" | ||
config_get hbbs_port "hbbs" "port" "21116" | ||
|
||
[ "$hbbr_enabled" -eq "1" ] || [ "$hbbs_enabled" -eq "1" ] || return 1 | ||
|
||
mkdir -p "$WORKDIR" || { | ||
logger -p daemon.error -t "rustdesk" "Failed to create working directory: $WORKDIR" | ||
return 1 | ||
} | ||
|
||
if [ "$hbbr_enabled" -eq "1" ]; then | ||
if [ "$web_client" -eq "0" ]; then | ||
HBBR_TCP_PORTS="$hbbr_port" | ||
else | ||
HBBR_TCP_PORTS="$hbbr_port $(( hbbr_port + 2 ))" | ||
fi | ||
|
||
procd_open_instance "hbbr.relay" | ||
procd_set_param command sh -c "cd $WORKDIR && /usr/bin/hbbr -p ${hbbr_port}" | ||
procd_set_param respawn | ||
if [ "$auto_fw" -eq "1" ]; then | ||
procd_open_data | ||
json_add_array firewall | ||
json_add_object "" | ||
json_add_string type rule | ||
json_add_string name "Allow-rustdesk-relay-tcp" | ||
json_add_string proto "tcp" | ||
json_add_string src "wan" | ||
json_add_string dest_port "$HBBR_TCP_PORTS" | ||
json_add_string target "ACCEPT" | ||
json_close_object | ||
json_close_array | ||
procd_close_data | ||
fi | ||
procd_close_instance | ||
fi | ||
|
||
if [ "$hbbs_enabled" -eq "1" ]; then | ||
if [ "$web_client" -eq "0" ]; then | ||
HBBS_TCP_PORTS="$(( hbbs_port - 1 )) $hbbs_port" | ||
else | ||
HBBS_TCP_PORTS="$(( hbbs_port - 1 )) $hbbs_port $(( hbbs_port + 2 ))" | ||
fi | ||
HBBS_UDP_PORTS="$hbbs_port" | ||
|
||
procd_open_instance "hbbs.server" | ||
procd_set_param command sh -c "cd $WORKDIR && /usr/bin/hbbs -p ${hbbs_port}" | ||
procd_set_param respawn | ||
if [ "$auto_fw" -eq "1" ]; then | ||
procd_open_data | ||
json_add_array firewall | ||
json_add_object "" | ||
json_add_string type rule | ||
json_add_string name "Allow-rustdesk-server-tcp" | ||
json_add_string proto "tcp" | ||
json_add_string src "wan" | ||
json_add_string dest_port "$HBBS_TCP_PORTS" | ||
json_add_string target "ACCEPT" | ||
json_close_object | ||
|
||
json_add_object "" | ||
json_add_string type rule | ||
json_add_string name "Allow-rustdesk-server-udp" | ||
json_add_string proto "udp" | ||
json_add_string src "wan" | ||
json_add_string dest_port "$HBBS_UDP_PORTS" | ||
json_add_string target "ACCEPT" | ||
json_close_object | ||
json_close_array | ||
procd_close_data | ||
fi | ||
procd_close_instance | ||
fi | ||
} | ||
|
||
service_started() { | ||
procd_set_config_changed firewall | ||
} | ||
|
||
service_stopped() { | ||
procd_set_config_changed firewall | ||
} | ||
|
||
service_triggers() { | ||
procd_add_reload_trigger "$CONF" | ||
} |