Last active
October 26, 2018 18:56
-
-
Save Jcpetrucci/c39e706640c5662ab06e4448d9e75dd2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/bin/bash | |
if [[ "${1,,}" == "install" ]]; then | |
# Call this script with argument 'install' to generate a systemd unit file. | |
cat <<-EOF | sudo dd of=/etc/systemd/system/vnc-alive-check.service | |
[Unit] | |
Description=VNC-ALIVE-CHECK: Make sure VNC is connected and restart it if needed. | |
After=network.target | |
[Service] | |
ExecStart=${PWD}/$0 | |
Restart=always | |
[Install] | |
WantedBy=multi-user.target | |
EOF | |
sudo systemctl enable vnc-alive-check.service | |
sudo systemctl start vnc-alive-check.service | |
exit 0 | |
fi | |
function func_restartRemmina { | |
killall remmina | |
sleep 2 | |
#su --command='DISPLAY=:0 XAUTHORITY=/var/run/lightdm/root/:0 remmina --connect=/home/user/.remmina/1513445416363.remmina &' user | |
su --command='DISPLAY=:0 remmina --connect=/home/user/.remmina/1513445416363.remmina &' user | |
} | |
#### MAIN #### | |
function main { | |
var_rchar=0 # initialize counter for later comparison | |
while :; do | |
sleep 10 | |
# no pid at all | |
pidof remmina &>/dev/null || { echo Restarting due to no PID; func_restartRemmina; } | |
# pid but no socket | |
lsof -i -a -p $(pidof remmina) -n -P 2>/dev/null | grep -q ESTABLISHED || { echo Restarting due to no socket; func_restartRemmina; } | |
# socket but no data | |
var_lastRchar="$var_rchar" | |
var_rchar="$(sed -n -r 's/rchar: ([0-9]+)$/\1/p' /proc/$(pidof remmina)/io)" | |
(( $var_rchar > $var_lastRchar )) || { echo Restarting due to not enough rchar: $var_rchar current / $var_lastRchar last; func_restartRemmina; } | |
done | |
} | |
[[ -z "$1" ]] && main # main loop only runs when the script has no arguments. this prevents main from running when script is actively run to perform a specific function. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For remmina VLC sessions that stay open (meaning process is running and socket is open), but no data comes back from the server, use an aggressive TCP timeout:
May be able to change socket options to use "TCP_USER_TIMEOUT" to avoid setting system-wide configuration.
See https://patchwork.ozlabs.org/patch/62889/