This commit is contained in:
2023-03-23 21:40:52 -05:00
parent 545f92d03e
commit 8e248af881
3 changed files with 45 additions and 27 deletions

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env bash
VERS='3.03222023'
VERS='3.03232023'
MMFOLDER="/opt/idssys/mediamanager"
MMSRV=$(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1)

View File

@@ -49,6 +49,8 @@ MMSTART(){
GOFORSTART=true;
echo "$(date) - Attempting to restart systems after VPN failure..." >> $logfile
echo -e "${idsCL[LightCyan]}Attempting to restart systems after VPN failure...${idsCL[Default]}"
SENDNOTICE "Attempting to start systems after VPN failure..."
else
GOFORSTART=false;
@@ -115,8 +117,8 @@ PersistentKeepalive = 25" >> /etc/wireguard/${VPN_INTERFACE}.conf
rm -f ${MMFOLDER}/mm.vpn.fail
MMSTOP
sleep 5m
"${VPN_START[@]}" >/dev/null 2>&1
sleep 10s
# "${VPN_START[@]}" >/dev/null 2>&1
# sleep 10s
rm -f ${MMFOLDER}/mm.stop*
[ $VERBOSE = true ] && DEBUGLOGSTOP
exit 1
@@ -133,8 +135,8 @@ PersistentKeepalive = 25" >> /etc/wireguard/${VPN_INTERFACE}.conf
touch ${MMFOLDER}/mm.vpn.fail
MMSTOP
sleep 30s
"${VPN_START[@]}" >/dev/null 2>&1
sleep 10s
# "${VPN_START[@]}" >/dev/null 2>&1
# sleep 10s
rm -f ${MMFOLDER}/mm.stop*
[ $VERBOSE = true ] && DEBUGLOGSTOP
exit 1
@@ -179,8 +181,8 @@ PersistentKeepalive = 25" >> /etc/wireguard/${VPN_INTERFACE}.conf
touch ${MMFOLDER}/mm.vpn.fail
MMSTOP
sleep 30s
"${VPN_START[@]}" >/dev/null 2>&1
sleep 10s
# "${VPN_START[@]}" >/dev/null 2>&1
# sleep 10s
rm -f ${MMFOLDER}/mm.stop*
[ $VERBOSE = true ] && DEBUGLOGSTOP
exit 1
@@ -230,8 +232,8 @@ PersistentKeepalive = 25" >> /etc/wireguard/${VPN_INTERFACE}.conf
touch ${MMFOLDER}/mm.vpn.fail
MMSTOP
sleep 30s
"${VPN_START[@]}" >/dev/null 2>&1
sleep 10s
# "${VPN_START[@]}" >/dev/null 2>&1
# sleep 10s
rm -f ${MMFOLDER}/mm.stop*
[ $VERBOSE = true ] && DEBUGLOGSTOP
exit 1
@@ -322,6 +324,14 @@ MMSTOP(){
fi
echo
touch ${MMFOLDER}/mm.stop
echo -en "${idsCL[LightCyan]}Stopping background MM scripts... ${idsCL[Default]}"
getMMbash=$(pgrep -f '/mm')
for i in $getMMbash; do
/bin/kill $i
done
echo -e "${idsCL[Green]} done${idsCL[Default]}"
echo -en "${idsCL[LightCyan]}Stopping Services... ${idsCL[Default]}"
#for srvc in "${SERVICES_CHECK[@]}"; do
for i in "${!NM_SERVICES[@]}"; do
@@ -366,9 +376,11 @@ MMSTOP(){
done
[ "$(/sbin/ip route show | grep default | cut -d' ' -f 3)" != "10.10.0.1" ] && /bin/ip route add default via 10.10.0.1 && ip route del $(cat ${MMFOLDER}/vpninfo.address)
[ $VERBOSE = true ] && echo "$(date) - Added default route back in" >> $logfile
rm -f ${MMFOLDER}/vpninfo.*
rm -f ${MMFOLDER}/noservices*
[ $VERBOSE = true ] && echo "$(date) - Added default route back in" >> $logfile
rm -f ${MMFOLDER}/mm.stop.checking
echo -e "${idsCL[Green]} done${idsCL[Default]}"
echo "$(date) - Media Management systems stopped" >> $logfile
@@ -406,16 +418,19 @@ MMSTATUS(){
if [ "${zerogw}" == "${defaultgw}" ] && [ "${zerogw}" == "${VPN_INTERFACE}" ]; then
echo -e "${idsCL[Green]}$defaultgw${idsCL[Default]}"
else
echo -e "${idsCL[Red]}Not correct${idsCL[Default]}"
if [ ! -f ${MMFOLDER}/mm.stop ] && [ ! -f ${MMFOLDER}/mm.stop.checking ]; then
echo -e "${idsCL[Red]}$defaultgw - Incorrect Gateways${idsCL[Default]}"
if ([ ! -f ${MMFOLDER}/mm.stop* ] && [ "${1}" == "fix" ]) || ([ ! -f ${MMFOLDER}/mm.stop ] && [ -f ${MMFOLDER}/mm.stop.checking ] && [ "${1}" == "fix" ]); then
echo
echo -e "${idsCL[LightCyan]}Restarting system...${idsCL[Default]}"
MMSTOP
echo -en "${idsCL[LightCyan]}Pausing for 30secs... ${idsCL[Default]}"
sleep 30s
echo -en "${idsCL[LightCyan]}Pausing for 10secs... ${idsCL[Default]}"
sleep 10s
echo -e "${idsCL[Green]}Done${idsCL[Default]}"
echo
echo -e "${idsCL[LightCyan]}Starting system back up...${idsCL[Default]}"
echo
MMSTART
echo -e " ${NM_SERVICES[wireguard]} : ${idsCL[Green]}Running${idsCL[Default]}"
zerogw=$(/sbin/ip route show | grep 0.0.0.0 | cut -d' ' -f 3)
defaultgw=$(/sbin/ip route show | grep default | cut -d' ' -f 3)
@@ -424,7 +439,7 @@ MMSTATUS(){
if [ "${zerogw}" == "${defaultgw}" ] && [ "${zerogw}" == "${VPN_INTERFACE}" ]; then
echo -e "${idsCL[Green]}$defaultgw${idsCL[Default]}"
else
echo -e "${idsCL[Red]}Not correct${idsCL[Default]}"
echo -e "${idsCL[Red]}$defaultgw - Incorrect Gateways${idsCL[Default]}"
echo
if [ ! -f ${MMFOLDER}/mm.stop.checking ]; then
echo -e "${idsCL[LightCyan]}Shutting down system... fix yo shit${idsCL[Default]}"
@@ -442,14 +457,17 @@ MMSTATUS(){
if [ "${scip}" != "${mmip}" ]; then
echo -e "${idsCL[Green]}Good${idsCL[Default]}"
else
echo -e "${idsCL[Red]}Not Good${idsCL[Default]}"
if [ ! -f ${MMFOLDER}/mm.stop ] && [ ! -f ${MMFOLDER}/mm.stop.checking ]; then
echo -e "${idsCL[Red]}Not Routing${idsCL[Default]}"
if ([ ! -f ${MMFOLDER}/mm.stop* ] && [ "${1}" == "fix" ]) || ([ ! -f ${MMFOLDER}/mm.stop ] && [ -f ${MMFOLDER}/mm.stop.checking ] && [ "${1}" == "fix" ]); then
echo
echo -e "${idsCL[LightCyan]}Restarting system...${idsCL[Default]}"
MMSTOP
echo -en "${idsCL[LightCyan]}Pausing for 30secs... ${idsCL[Default]}"
sleep 30s
echo -en "${idsCL[LightCyan]}Pausing for 10secs... ${idsCL[Default]}"
sleep 10s
echo -e "${idsCL[Green]}Done${idsCL[Default]}"
echo
echo -e "${idsCL[LightCyan]}Starting system back up...${idsCL[Default]}"
echo
MMSTART
fi
fi
@@ -470,10 +488,10 @@ if [ ! -f ${MMFOLDER}/mm.update.stop ]; then
fi
case $action in
start | check)
if [ -f ${MMFOLDER}/mm.stop ] && [ "${action}" = "check" ]; then
if ([ -f ${MMFOLDER}/mm.stop ] || [ -f ${MMFOLDER}/mm.stop.checking ]) && [ "${action}" = "check" ]; then
if [ -f ${MMFOLDER}/mm.stop.checking ]; then
checkstopped=`expr $(date +%s) - $(stat -c %Y ${MMFOLDER}/mm.stop.checking)`
if [ $checkstopped -gt 1800 ]; then
if [ $checkstopped -gt 900 ]; then
rm -f ${MMFOLDER}/mm.stop*
getStuckMM=$(pgrep -f '/mm')
for i in $getStuckMM; do
@@ -496,7 +514,7 @@ if [ ! -f ${MMFOLDER}/mm.update.stop ]; then
echo
exit 1
fi
touch ${MMFOLDER}/mm.stop
# touch ${MMFOLDER}/mm.stop
[ "${action}" = "check" ] && touch ${MMFOLDER}/mm.stop.checking
MMSTART ${action} ${2};;
@@ -520,7 +538,7 @@ if [ ! -f ${MMFOLDER}/mm.update.stop ]; then
echo -e "${stopmsg}"
echo
fi
MMSTATUS;;
MMSTATUS ${2};;
update);;
clear) echo -e "${idsCL[LightCyan]}Clearing all mm.* files ${idsCL[Default]}"

6
run.sh
View File

@@ -74,7 +74,7 @@ else
#fd=$(expr $(date +%s) - $(stat -L --format %Y ${MMFOLDER}/mm.stop.checking))
if [ $(expr $(date +%s) - $(stat -L --format %Y ${MMFOLDER}/mm.stop.checking)) -gt 900 ]; then
rm -f ${MMFOLDER}/mm.stop*
elif [ "${1}" = "check" ] && [ "$(ip link | grep "${VPN_INTERFACE}")" = "" ] && [ ! -f ${MMFOLDER}/mm.vpn* ] && [ $(uptime_minutes) -lt 2 ]; then
elif [ "${1}" = "check" ] && [ "$(ip link | grep "${VPN_INTERFACE}")" = "" ] && [ ! -f ${MMFOLDER}/mm.vpn* ] && [ $(uptime_minutes) -lt 3 ]; then
rm -f ${MMFOLDER}/mm.stop*
else
echo -e "${idsCL[LightCyan]}Try again later, 'mm' program currently in use...${idsCL[Default]}"
@@ -82,9 +82,9 @@ else
fi
if [ ! -f ${MMFOLDER}/mm.stop.checking ] || [ "${1}" == "status" ]; then
touch ${MMFOLDER}/mm.stop.checking
[ "${1}" != "status" ] && touch ${MMFOLDER}/mm.stop.checking
${MMFOLDER}/mm-scripts.sh ${1} ${2} ${3} ${4} ${5} ${6} ${7} ${8} ${9} ${10} ${11} ${12} ${13} ${14}
rm -f ${MMFOLDER}/mm.stop.checking
[ "${1}" != "status" ] && rm -f ${MMFOLDER}/mm.stop.checking
fi
fi