Skip to content

Instantly share code, notes, and snippets.

@dimacus
Created September 24, 2014 18:36
Show Gist options
  • Save dimacus/9142f13facd11d6a24fd to your computer and use it in GitHub Desktop.
Save dimacus/9142f13facd11d6a24fd to your computer and use it in GitHub Desktop.
#!/bin/bash +e
# allow change to pass-in display argument
DISPLAY=$1
: ${DISPLAY:=:1}
export DISPLAY
echo "=== network before $0 ==="
netstat -na | grep "LISTEN "
echo
echo "=== was running ==="
(ps -fwC Xvnc4 --no-header || ps -fwC Xvnc --no-header) && vncserver -kill ${DISPLAY}
sleep 1
echo "=== cleanup ==="
XDISPLAY=X`echo $DISPLAY | cut -d : -f 2`
[ -f /var/tmp/Xvfb_\${DISPLAY}.pid ] && rm -f /var/tmp/Xvfb_\${DISPLAY}.pid
[ -f /tmp/.${XDISPLAY}-lock ] && rm -f /tmp/.${XDISPLAY}-lock
rm -f /tmp/.X11-unix/${XDISPLAY}
#kill fluxbox after run. If flux persists too long, it tends to consume 100% after a while.
ps ax | grep -v grep | grep fluxbox
flux_box_check=$?
if [[ $flux_box_check == 0 ]]; then
echo "#######################################"
echo "# killing fluxbox #"
echo "#######################################"
killall -9 fluxbox
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment