47

I'm using Debian 6 and Dropbox. I followed these commands to install it.

When I run ~/.dropbox-dist/dropboxd — Dropbox works and stuff. Problem is that when I close terminal or, even worse — reboot, Dropbox stops working and I need to run that daemon again.

How can I have the computer automatically start that daemon in the background?

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
daGrevis
  • 853
  • Have you tried the python script linked below on that same website? It seems to be targeted to controlling the daemon. (I don't have access to a debian-based machine ATM to try it myself though). – WhyNotHugo Apr 03 '12 at 16:58
  • Perhaps nohup? http://unix.stackexchange.com/questions/56495/whats-the-difference-between-running-a-program-as-a-daemon-and-forking-it-into – njsg Feb 07 '13 at 14:43

16 Answers16

63

If you're running the daemon from your own account, start it at boot time with Cron. Run crontab -e to edit your crontab file and add the line

@reboot ~/.dropbox-dist/dropboxd
  • While this would work, ideally it would be best to create the service script within /etc/init.d/ utilizing the skeleton script that is contained within. You can then add the service dropbox start to the cron on reboot and still have the ability to stop the service and restart it. – sparticvs Aug 14 '13 at 00:38
  • @sparticvs - Will dropbox not run as root if you put it in init.d? dropbox can be configured to run per user basis. Can the dropboxd be shared between users using different dropbox accounts? – Lord Loh. Aug 16 '13 at 17:02
  • @LordLoh. good point. However you could change to who you want to run as. I did find this resource. Looks new. – sparticvs Aug 16 '13 at 17:30
  • 1
    @LordLoh. @sparticvs I think there is a solution to the init.d running as root problem. I posted an answer of my own, but the solution at http://pixeldust.wikidot.com/linode-setup%3adropbox seems to work well. – Zac Jan 09 '14 at 20:31
15

run the command in this way:

($HOME/.dropbox-dist/dropboxd &)&

this will detach the process from tha actual terminal and put it in real background.

You will still have to start it back up manually after a reboot, though.

mutek
  • 151
14

Here is my solution. This is on Debian 8.

Install Dropbox as per standard instructions. So far, I've only got one user connected, I don't know if this will work with multiple users as dropbox seems to register the machine and not the linux user account. If you know how to get multiple user accounts on one server working let us know.

https://www.dropbox.com/en_GB/install?os=lnx

Then install the python control script instructions but put it in /usr/bin and not your home directory bin.

Create file /lib/systemd/system/dropbox@.service:

[Unit]
Description=Dropbox as a system service user %i

[Service]
Type=forking
ExecStart=/usr/bin/dropbox start
ExecStop=/usr/bin/dropbox stop
User=%i
Group=%i
# 'LANG' might be unnecessary, since systemd already sets the
# locale for all services according to "/etc/locale.conf".
# Run `systemctl show-environment` to make sure.
Environment=LANG=en_US.utf-8

[Install]
WantedBy=multi-user.target

Enable the service for user fred:

$ sudo systemctl enable dropbox@fred.service

Then start the service:

$ sudo systemctl start dropbox@fred.service
  • 1
    I like your answer, just a couple things I change. I'd add After=network.target under [Unit] and put the python file in /usr/local/bin per http://unix.stackexchange.com/questions/8656/usr-bin-vs-usr-local-bin-on-linux – Northstrider Mar 05 '17 at 01:50
  • This answer ammended by Northstrider's comment should be part of the official documentation provided by Dropbox. – Dennis Williamson Aug 12 '22 at 15:27
  • What's the difference between dropbox and dropboxd as provided in the distribution? – NeilG Aug 20 '23 at 10:56
5

You can also run as a daemon by doing daemon $HOME/.dropbox-dist/dropboxd.

This has the advantage that if you additionally pass the -n/--name flag, you can use daemon --[running|restart|stop] -n <name> to control the process.

Perhaps someone else can chip in on how best to get daemons started using daemon to run at startup...

4

You can find Debian and Ubuntu init.d scripts, just copy to /etc/init.d/dropbox and customize with user name.

Enable in debian with chkconfig --add dropbox. Then run as any other service.

csanchez
  • 141
3

Have a look here:

https://community.spiceworks.com/topic/131973-dropbox-headless-workstation?page=1#entry-6076539

A user mentioned:

Just thought I'd mention:

(a) the latest distributions seem to make this fairly straightfoward, just run dropbox start from the command line, BUT (b) watch out for logging in and out with X11 forwarded.

I've set up a lot of Bash aliases for connecting to various machines, and they all include the -X option to forward X11 packets. Because of this, Dropbox kept dying on my on logout, even running it under screen and with nohup. Apparently, having X11 forwarded was causing Dropbox to connect the dbus process on my local machine rather than on the remote machine; so, when I broke the connection, Dropbox was seeing dbus as having terminated and thus was terminating itself.

Just FYI, as this stumped me for a bit. The key was that I was having to press Ctrl-C even after logging out / running exit on the remote machine. Apparently, SSH was keeping the session open, even though I had exited Bash, because of the remaining open connection.

The solution is simple even if one (for some reason) wants to keep ssh-ing with the -X: before launching Dropbox you should "break" the forwarding for example doing:

$ unset DISPLAY

If this is done in a Bash script the forwarding is "broken" just inside the script but once this is executed the 'terminal' is still forwarding.

slm
  • 369,824
3

Here is my solution for Linux distributions using Upstart 1.4 and higher.

Save the contents below into a configuration file under /etc/init, for example: /etc/init/db_user.conf:

# Dropbox upstart script for user db_user, db_user can be replaced by anything you like.

description "Dropbox db_user"
author "myth384"

start on runlevel [2345]
stop on runlevel [!2345]

respawn

setuid db_user
# The next two lines are optional. I use these to be able to share the 
#   Dropbox using Samba. Within group shareusers are all Samba users.
# setgid shareusers
# umask 0002

# The next line is necessary to be able to synchronise files with non-ASCII characters.

env LANG="en_US.UTF-8"     
exec /home/db_user/.dropbox-dist/dropbox

To start up the daemon without rebooting:

sudo start db_user

NOTE: By uncommenting the setgid line it is not necessary to set the setgid flag on the .dropbox.cache folder as indicated by other sources on the internet.

slm
  • 369,824
Alain
  • 171
  • 1
  • 1
  • 5
2

There is a fairly nice way to add this to init.d described here. You have to add which users you want Dropbox to start for to the init script (easy enough), and when the system boots, it will start the Dropbox daemon for each of those users.

The only thing to note is that they specify DAEMON=.dropbox-dist/dropbox which I believe is incorrect. The author forgot the d at the end of that — it should be DAEMON=.dropbox-dist/dropboxd.

Zac
  • 121
2

It might not be useful for all Linux distros, but in CentOS 7, from Applications/System Tools/ menu, open 'Startup Applications'. Then click Add, and enter this command:

/home/username/.dropbox-dist/dropboxd

or

/home/.dropbox-dist/dropboxd

enter image description here

Aryo Z
  • 21
  • @roaima thanks for your judgment. Which other solution? I just posted the solution which worked for me. – Aryo Z Dec 08 '16 at 05:35
  • Cool, this is what worked for me. Simple and straightforward. Cron and some of the other solutions described did not. – kghbln Mar 25 '24 at 20:43
2

You could use screen:

screen -dmS ~/.dropbox-dist/dropboxd

This will start it as a daemon and in detached mode.

You would then have to write your own init.d script to have it run as service this way and add a line after #!/bin/bash for chkconfig and add the necessary run levels, such as 2, 3, 4, 5. Different distributions have different run levels so you'd have to check this.

0

This site seems to have complete information on how to install and configure dropbox on Linux, including downloading and installing the CLI, creating soft links outside of dropbox, and running dropbox as a daemon. The latter provides an init.d script that will enable dropboxd to be controlled with service and chkconfig.

http://www.dropboxwiki.com/tips-and-tricks/install-dropbox-centos-gui-required

0

download the script provided by dropbox https://www.dropbox.com/download?dl=packages/dropbox.py and run

python dropbox.py start

If you don't have python you will need pyhon to run this

oo mo
  • 1
0

1- install Dropbox (reference: https://www.dropbox.com/install-linux):

32 bits:

cd ~ && wget -O - "https://www.dropbox.com/download?plat=lnx.x86" | tar xzf -

64-bit:

cd ~ && wget -O - "https://www.dropbox.com/download?plat=lnx.x86_64" | tar xzf -

2- Execute (you have to execute at least one time, to log in Dropbox)

~/.dropbox-dist/dropboxd

3- Download this script:

cd ~/Downloads
wget https://www.dropbox.com/download?dl=packages/dropbox.py
mv download?dl=packages%2Fdropbox.py dropbox.py
mv dropbox.py ~/bin/dropbox.py
chmod 755 ~/bin/dropbox.py

You can use this command to get help about the script:

~/bin/dropbox.py help

4- Set autostart

~/bin/dropbox.py autostart y
~/bin/dropbox.py start
~/bin/dropbox.py status

As mentioned by @Zac there are a good explanation about each step here: http://pixeldust.wikidot.com/linode-setup%3adropbox

0

I added the following lines to the end of my .profile file. I prefer to have the computer boot at terminal. However, if I start X11 after this, the dropbox applet is not displayed on the system tray.

dropbox running
rv=$?
if [ $rv -eq 0 ]; then
    dropbox start;
fi
Lord Loh.
  • 1,976
  • Assuming you really do mean [ $rv -eq 0] (and not [ $rv -ne 0 ]) you could simplify all that with dropbox running && dropbox start – Chris Davies Dec 08 '16 at 12:07
-1

The solution is as other python programs :

shell$ nohup ~/.dropbox-dist/dropboxd & 
Anthon
  • 79,293
-2

I think the best way is to create a new file in /usr/bin with this code:

#!/bin/bash

~/.dropbox-dist/dropboxd

save and name it "dropbox". Now you can run from console in background or create a shortcut in your menu/desktop

Azihak
  • 1
  • 2
    This is incorrect as it would just run in the foreground. You would have to still do dropbox & to send it to the background. Additionally if the terminal connection is ended, then the Hangup signal will kill the process. – sparticvs Aug 14 '13 at 00:36