Advertisement
Bladtman

dropboxd

Jun 5th, 2012
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.36 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Copyright 2008 Evenflow, Inc., 2010 Dropbox
  4. #
  5. # Environment script for the dropbox executable.
  6.  
  7. WAIT_TIME=5 #initial time to wait between checking the internet connection
  8. #HOSTS="www.google.com www.wikipedia.org 8.8.8.8 208.67.222.222"
  9. HOSTS="www.google.com www.wikipedia.org "
  10.  
  11. PAR=$(dirname $(readlink -f $0))
  12. OLD_LD_LIBRARY_PATH=$LD_LIBRARY_PATH
  13. LD_LIBRARY_PATH=$PAR${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH
  14.  
  15. #non-zero exit code iff none of the hosts could be reached
  16. check_net() {
  17.     local ret=1
  18.     for i in $HOSTS; do
  19.         #ping -w2 -c2 $i > /dev/null 2>&1 && ret=0 && break
  20.         curl -o /dev/null $i > /dev/null 2>&1 && ret=0 && break
  21.     done
  22.     echo $ret
  23. }
  24.  
  25. #if dropbox is running; kill it. Then start dropbox
  26. start_dropbox() {
  27. local tmp=`ps ax|grep -E "[0-9] $PAR/dropbox"|grep -v grep`
  28.     if [ -n "$tmp" ]; then
  29.         kill -9 $(pidof dropbox) > /dev/null 2>&1
  30.     fi
  31.     exec $PAR/dropbox $@ > /dev/null 2>&1 &
  32. }
  33.  
  34. #loop over: start dropbox iff check_net returns 0
  35. #loop (and with it, the entire script) terminates when dropbox has been restarted,
  36. #+ or the waiting time has exeeded 1500 seconds (it grows 50% with each iteration of the loop)
  37. attempt_startup() {
  38.     while [ $WAIT_TIME -lt 1500  ] ; do
  39.         if [ $(check_net) -eq 0 ]; then
  40.             start_dropbox
  41.             exit
  42.         fi
  43.         sleep $WAIT_TIME
  44.         #WAIT_TIME=$(($WAIT_TIME+$WAIT_TIME/2))
  45.         let "WAIT_TIME += WAIT_TIME/2"
  46.     done
  47. }
  48.  
  49. start_dropbox
  50. attempt_startup &
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement