1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-feeds.git synced 2025-03-09 15:40:03 +00:00

Restart services only when needed

This commit is contained in:
Ycarus (Yannick Chabanois) 2020-05-28 18:51:40 +02:00
parent d7a7ec3e36
commit 67c295dbd7

View file

@ -280,17 +280,21 @@ _get_vps_config() {
set shadowsocks-libev.sss0.server="$vpsip" set shadowsocks-libev.sss0.server="$vpsip"
commit shadowsocks-libev commit shadowsocks-libev
EOF EOF
if [ "$(uci -q get shadowsocks-libev.sss0.disabled)" = "0" ]; then
logger -t "OMR-VPS" "Restart shadowsocks..." logger -t "OMR-VPS" "Restart shadowsocks..."
/etc/init.d/shadowsocks-libev restart /etc/init.d/shadowsocks-libev restart
fi fi
fi
if [ "$(uci -q get openvpn.omr.remote)" != "127.0.0.1" ] && [ "$(uci -q get openvpn.omr.remote)" != "$vpsip" ] && [ "$(uci -q get openmptcprouter.settings.ha)" != "1" ]; then if [ "$(uci -q get openvpn.omr.remote)" != "127.0.0.1" ] && [ "$(uci -q get openvpn.omr.remote)" != "$vpsip" ] && [ "$(uci -q get openmptcprouter.settings.ha)" != "1" ]; then
uci -q batch <<-EOF >/dev/null uci -q batch <<-EOF >/dev/null
set openvpn.omr.remote="$vpsip" set openvpn.omr.remote="$vpsip"
commit openvpn commit openvpn
EOF EOF
if [ "$(uci -q get openvpn.omr.enabled)" = "1" ]; then
logger -t "OMR-VPS" "Restart OpenVPN..." logger -t "OMR-VPS" "Restart OpenVPN..."
/etc/init.d/openvpn restart /etc/init.d/openvpn restart
fi fi
fi
port="$(echo "$vps_config" | jsonfilter -q -e '@.dsvpn.port')" port="$(echo "$vps_config" | jsonfilter -q -e '@.dsvpn.port')"
localip="$(echo "$vps_config" | jsonfilter -q -e '@.dsvpn.client_ip')" localip="$(echo "$vps_config" | jsonfilter -q -e '@.dsvpn.client_ip')"
remoteip="$(echo "$vps_config" | jsonfilter -q -e '@.dsvpn.host_ip')" remoteip="$(echo "$vps_config" | jsonfilter -q -e '@.dsvpn.host_ip')"
@ -302,9 +306,11 @@ _get_vps_config() {
set dsvpn.vpn.host="$vpsip" set dsvpn.vpn.host="$vpsip"
commit dsvpn commit dsvpn
EOF EOF
if [ "$(uci -q get dsvpn.vpn.enable)" = "1" ]; then
logger -t "OMR-VPS" "Restart DSVPN..." logger -t "OMR-VPS" "Restart DSVPN..."
/etc/init.d/dsvpn restart /etc/init.d/dsvpn restart
fi fi
fi
if [ "$(uci -q get mlvpn.general.host)" != "127.0.0.1" ] && [ "$(uci -q get mlvpn.general.host)" != "$vpsip" ] && [ "$(uci -q get openmptcprouter.settings.ha)" != "1" ] && [ -f /etc/init.d/mlvpn ]; then if [ "$(uci -q get mlvpn.general.host)" != "127.0.0.1" ] && [ "$(uci -q get mlvpn.general.host)" != "$vpsip" ] && [ "$(uci -q get openmptcprouter.settings.ha)" != "1" ] && [ -f /etc/init.d/mlvpn ]; then
uci -q batch <<-EOF >/dev/null uci -q batch <<-EOF >/dev/null
@ -312,9 +318,11 @@ _get_vps_config() {
set mlvpn.general.host="$vpsip" set mlvpn.general.host="$vpsip"
commit mlvpn commit mlvpn
EOF EOF
if [ "$(uci -q get mlvpn.general.enable)" = "1" ]; then
logger -t "OMR-VPS" "Restart MLVPN..." logger -t "OMR-VPS" "Restart MLVPN..."
/etc/init.d/mlvpn restart /etc/init.d/mlvpn restart
fi fi
fi
if [ "$(uci -q get glorytun.vpn.host)" != "127.0.0.1" ] && [ "$(uci -q get glorytun.vpn.host)" != "$vpsip" ] && [ "$(uci -q get openmptcprouter.settings.ha)" != "1" ]; then if [ "$(uci -q get glorytun.vpn.host)" != "127.0.0.1" ] && [ "$(uci -q get glorytun.vpn.host)" != "$vpsip" ] && [ "$(uci -q get openmptcprouter.settings.ha)" != "1" ]; then
uci -q batch <<-EOF >/dev/null uci -q batch <<-EOF >/dev/null
set glorytun.vpn.host="$vpsip" set glorytun.vpn.host="$vpsip"
@ -323,13 +331,15 @@ _get_vps_config() {
fi fi
if [ "$glorytun_change" != "0" ]; then if [ "$glorytun_change" != "0" ]; then
logger -t "OMR-VPS" "Restart glorytun..."
uci -q batch <<-EOF >/dev/null uci -q batch <<-EOF >/dev/null
commit glorytun commit glorytun
EOF EOF
if [ "$(uci -q get glorytun.vpn.enable)" = "1" ]; then
logger -t "OMR-VPS" "Restart glorytun..."
/etc/init.d/glorytun restart >/dev/null 2>&1 /etc/init.d/glorytun restart >/dev/null 2>&1
/etc/init.d/glorytun-udp restart >/dev/null 2>&1 /etc/init.d/glorytun-udp restart >/dev/null 2>&1
fi fi
fi
} }
_set_pihole() { _set_pihole() {
@ -524,7 +534,7 @@ _set_vpn_ip() {
ula="$(uci -q get network.globals.ula_prefix)" ula="$(uci -q get network.globals.ula_prefix)"
ula_current="$(echo "$vps_config" | jsonfilter -q -e '@.ip6in4.ula')" ula_current="$(echo "$vps_config" | jsonfilter -q -e '@.ip6in4.ula')"
if [ "$vpnip_remote" != "" ] && [ "$vpnip_local" != "" ] && ([ "$vpnip_remote" != "$vpnip_remote_current" ] || [ "$vpnip_local" != "$vpnip_local_current" ] || [ "$ula" != "$ula_current" ]); then if [ "$vpnip_remote" != "" ] && [ "$vpnip_local" != "" ] && ([ "$vpnip_remote" != "$vpnip_remote_current" ] || [ "$vpnip_local" != "$vpnip_local_current" ] || [ "$ula" != "$ula_current" ]); then
settings='{"remoteip" : "'$vpnip_local'","localip" : "'$vpnip_remote'","ula" : "'$ula'"}' settings='{"remoteip" : "'$vpnip_local'","localip" : "'$vpnip_remote'","ula" : ["'$ula'"]}'
result=$(_set_json "vpnips" "$settings") result=$(_set_json "vpnips" "$settings")
fi fi
} }
@ -708,7 +718,7 @@ _set_config_from_vps() {
[ -z "$vps_config" ] && return [ -z "$vps_config" ] && return
logger -t "OMR-VPS" "Get config from VPS..." logger -t "OMR-VPS" "Get config from VPS..."
noerror=1
# get VPS ip # get VPS ip
vpsip="$(uci -q get openmptcprouter.${servername}.ip)" vpsip="$(uci -q get openmptcprouter.${servername}.ip)"
vps_lastchange="$(echo "$vps_config" | jsonfilter -q -e '@.vps.lastchange')" vps_lastchange="$(echo "$vps_config" | jsonfilter -q -e '@.vps.lastchange')"
@ -725,7 +735,7 @@ _set_config_from_vps() {
fi fi
ula="$(echo "$vps_config" | jsonfilter -q -e '@.ip6in4.ula')" ula="$(echo "$vps_config" | jsonfilter -q -e '@.ip6in4.ula')"
if [ -n "$ula" ]; then if [ -n "$ula" ] && [[ "$ula" != *" "* ]]; then
uci -q batch <<-EOF >/dev/null uci -q batch <<-EOF >/dev/null
set network.globals.ula_prefix=$ula set network.globals.ula_prefix=$ula
EOF EOF
@ -1032,10 +1042,12 @@ _set_config_from_vps() {
done done
fi fi
fi fi
if [ "$noerror" = "1" ]; then
uci -q batch <<-EOF >/dev/null uci -q batch <<-EOF >/dev/null
set openmptcprouter.${servername}.get_config=0 set openmptcprouter.${servername}.get_config=0
commit openmptcprouter commit openmptcprouter
EOF EOF
fi
} }
_backup_send() { _backup_send() {