Setup Headless Dropbox Sync Client on Linux

Setup Headless Dropbox Sync Client on Linux

Category : How-to

Get Social!

dropbox-logoDropbox is a cloud based file storage service which makes your files available from almost any internet connected device. You simply synchronize a folder with the service on each device and Dropbox keeps them in sync, automatically updating each folder as files are added and removed on each machine.

You can register for a free account which gives you a limited amount of storage to use – no strings attached. To register, visit Dropbox (Please note, that is my affiliate link which gives me a bonus if you sign up. If you’re not happy with this, you can simply visit dropbox.com and sign up. I’d be most grateful if you’d use the link :) ).

Dropbox offers a client to use on Windows, Mac OSX, Linux, iPhone and Android which you can download for free. These are all graphical interfaces and do not work for deployment on a headless server.

Thankfully, the Dropbox team have created an easily deployable Dropbox client which works without a desktop installed and can be managed by a Python script. To get started, download the Python script to your home directory on your headless server with wget.

cd ~
wget https://www.dropbox.com/download?dl=packages/dropbox.py -O dropbox.py

Give the script the permission to execute.

chmod +x dropbox.py

You can now use the Python script to download the Dropbox client. The client will be downloaded to your users home directory so make sure that you are logged in with the correct user.

./dropbox.py start -i

The client binaries will now be downloaded and installed. The next step is to register your account with the Dropbox client so that synchronization can begin. Start Dropbox for the first time with the Python script and you will be presented with a link. Paste the link into a web browser and login to your Dropbox account to grant access to the client. As soon as this process completes, your Dropbox client will begin synchronization.

./dropbox.py start
This client is not linked to any account... Please visit hhttps://www.dropbox.com/cli_link?host_id=10a5ce48e41d50f8135dd6fd55b70a91 to link this machine.

Once you have got all this working and the Dropbox client is synchronizing your first files, it’s time to add an init.d script so that the Dropbox client starts with your operating system. Things may differ here, depending on your Linux distribution. Add one of the below scripts to your init.d folder and substitute [USER] for the list of users who will use the client.

vi /etc/init.d/dropbox

Ubuntu/ Debian

#!/bin/sh
#dropbox service
DROPBOX_USERS="[USER]"

DAEMON=.dropbox-dist/dropboxd

start() {
   echo "Starting dropbox..."
   for dbuser in $DROPBOX_USERS; do
       HOMEDIR=`getent passwd $dbuser | cut -d: -f6`
       if [ -x $HOMEDIR/$DAEMON ]; then
           HOME="$HOMEDIR" start-stop-daemon -b -o -c $dbuser -S -u $dbuser -x $HOMEDIR/$DAEMON
       fi
   done
}

stop() {
   echo "Stopping dropbox..."
   for dbuser in $DROPBOX_USERS; do
       HOMEDIR=`getent passwd $dbuser | cut -d: -f6`
       if [ -x $HOMEDIR/$DAEMON ]; then
           start-stop-daemon -o -c $dbuser -K -u $dbuser -x $HOMEDIR/$DAEMON
       fi
   done
}

status() {
   for dbuser in $DROPBOX_USERS; do
       dbpid=`pgrep -u $dbuser dropbox`
       if [ -z $dbpid ] ; then
           echo "dropboxd for USER $dbuser: not running."
       else
           echo "dropboxd for USER $dbuser: running (pid $dbpid)"
       fi
   done
}

case "$1" in

   start)
       start
       ;;
   stop)
       stop
       ;;
   restart|reload|force-reload)
       stop
       start
       ;;
   status)
       status
       ;;
   *)
       echo "Usage: /etc/init.d/dropbox {start|stop|reload|force-reload|restart|status}"
       exit 1

esac

exit 0

Then add the execute permission and add it to the startup routine.

chmod +x /etc/init.d/dropbox 
update-rc.d dropbox defaults

RedHat/ Fedora/ CentOS

# chkconfig: 345 85 15
# description: Startup script for dropbox daemon
#
# processname: dropboxd
# pidfile: /var/run/dropbox.pid
# config: /etc/sysconfig/dropbox
#

### BEGIN INIT INFO
# Provides: dropboxd
# Required-Start: $local_fs $network $syslog
# Required-Stop: $local_fs $syslog
# Should-Start: $syslog
# Should-Stop: $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start up the Dropbox file syncing daemon
# Description: Dropbox is a filesyncing sevice provided by dropbox.com
# This service starts up the dropbox daemon.
### END INIT INFO

# Source function library.
. /etc/rc.d/init.d/functions

# To configure, add line with DROPBOX_USERS="[USERS]" to /etc/sysconfig/dropbox
# Probably should use a dropbox group in /etc/groups instead.

[ -f /etc/sysconfig/dropbox ] && . /etc/sysconfig/dropbox
prog=dropboxd
lockfile=${LOCKFILE-/var/lock/subsys/$prog}
config=${CONFIG-/etc/sysconfig/dropbox}
RETVAL=0

start() {
   echo -n $"Starting $prog"
   if [ -z $DROPBOX_USERS ] ; then
      echo -n ": unconfigured: $config"
      echo_failure
      echo
      rm -f ${lockfile} ${pidfile}
      RETURN=6
      return $RETVAL
   fi
   for dbuser in $DROPBOX_USERS; do
      daemon --user $dbuser /bin/sh -c "~$dbuser/.dropbox-dist/dropboxd&"
   done
   RETVAL=$?
   echo
   [ $RETVAL = 0 ] && touch ${lockfile}
   return $RETVAL
}

status() {
   for dbuser in $DROPBOX_USERS; do
      dbpid=`pgrep -u $dbuser dropbox | grep -v grep`
      if [ -z $dbpid ] ; then
         echo "dropboxd for USER $dbuser: not running."
      else
         echo "dropboxd for USER $dbuser: running (pid $dbpid)"
      fi
      done
}

stop() {
   echo -n $"Stopping $prog"
   for dbuser in $DROPBOX_USERS; do
      killproc ~$dbuser/.dropbox-dist/dropbox
   done
   RETVAL=$?
   echo
   [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}

# See how we were called.
case "$1" in
   start)
      start
      ;;
   status)
      status
      ;;
   stop)
      stop
      ;;
   restart)
      stop
      start
      ;;
   *)
      echo $"Usage: $prog {start|status|stop|restart}"
      RETVAL=3

esac

exit $RETVAL

Change permissions and add to the startup routine.

chmod 0755 /etc/init.d/dropbox 
chmod 0644 /etc/sysconfig/dropbox
chkconfig dropbox on


13 Comments

Roman

2-Oct-2014 at 9:23 am

Thanks, very useful script.

Chris R. Chamberlain

15-Oct-2014 at 9:52 am

Best tutorial found – one gotcha on current 32bit Ubuntu 14.04 LTS install is line 5 in Ubuntu/Debian /etc/init.d/dropbox.

The file ‘.dropbox-dist/dropbox’ needs to be ‘.dropbox-dist/dropboxd’

    james.coyle

    15-Oct-2014 at 12:12 pm

    Thanks, Chris. I have updated line 5 in the script as the filename may have changed since I installed it myself.

Henry Armitage

9-Nov-2014 at 4:38 pm

Hey, I just thought I’d let you know that I tried a few of the init.d scripts out there to start Dropbox and this was the only one that actually worked with the version posted on Dropbox.com at the time (ver 1.6.2 as of 9 Nov 2014). Thanks for posting this!

Martin Dell

25-Feb-2015 at 10:08 am

Awesome thank you. Exactly what I was looking for and worked first time – even though I’m no Linux expert

Jason Penney

11-Jun-2015 at 1:01 pm

Thanks, this works great.

I added the following to ‘status()’, just after the if/else, to get more details:

sudo -H -u $dbuser dropbox status

Output looks like this:

dropboxd for USER XXXXX: running (pid xxxxx)
Syncing (5,449 files remaining, 3 mins left)
Downloading 5,449 files (2,714 KB/sec, 3 mins left)
dropboxd for USER YYYYY: running (pid eye)
Syncing (64 files remaining, 5 mins left)
Downloading 64 files (2,949 KB/sec, 5 mins left)

Morgan

13-Jun-2015 at 3:04 pm

Thanks for this!

I’m wondering if it’s possible to have the dropbox folder placed somewhere other than it’s default using this method?

I’m fairly new to linux so I apologize if this has an obvious answer.

Cheers,
Morgan

Simon Lee

23-Nov-2015 at 6:10 am

Question: I am using this script on Ubuntu Desktop 14.04.04 and , find that stop() doesn’t work well on Nov-2015.

As you know, start() uses “.dropbox-dist/dropboxd” , and this is symbolic link to “.dropbox-dist/dropbox-lnx.x86_64_3.10.11/dropbox” (no ‘d’ in last)
This symbolic link works well when start() is called. But in stop(), this link doesn’t work well. I am not sure that this might be caused from Ubuntu version.

I slightly changed stop() part like below, to avoid the issue.
“start-stop-daemon -o -c $dbuser -K -u $dbuser -n dropbox”

If anyone know better way, please share it.
Thanks.

    Dimitris

    12-Feb-2016 at 12:18 pm

    @Simon Lee, works great, thanks!

    Dainius Žiūra

    22-Jun-2016 at 1:31 pm

    This works on Ubuntu Server 14.04
    stop() {
    echo “Stopping dropbox…”
    for dbuser in $DROPBOX_USERS; do
    dbpid=`pgrep -u $dbuser dropbox`
    HOMEDIR=`getent passwd $dbuser | cut -d: -f6`
    FULLPATH=`ls -l /proc/$dbpid/exe | rev| cut -d’ ‘ -f 1 | rev`
    if [ -x $HOMEDIR/$DAEMON ]; then
    start-stop-daemon -o -c $dbuser -K -u $dbuser -x $FULLPATH
    fi
    done
    }

Monte Price

10-May-2016 at 7:25 pm

solved my problem. thanks

Dan

4-Jul-2016 at 3:20 pm

I was trying this out, not on a server, but rather on a separate user on my laptop which I’ve su’d into (just trying to keep proprietary stuff in its own corner as much as I can). It gives a GTK error and even a segfault. Turns out that su still sets the `DISPLAY` environmental variable to something, so you want to unset it:

export DISPLAY=

After this, that problem went away.

Dan

4-Jul-2016 at 4:08 pm

Another strange bit, perhaps related to my environment. I never get the prompt telling me to visit the website. Instead it just looks like dropbox starts. However when I directly run:

.dropbox-dist/dropboxd

I do get that prompt.

Leave a Reply to Henry Armitage Cancel reply

Visit our advertisers

Quick Poll

How many Proxmox servers do you work with?

Visit our advertisers