37

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?

  • 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 3 '12 at 16:58
  • Perhaps nohup? unix.stackexchange.com/questions/56495/… – njsg Feb 7 '13 at 14:43

15 Answers 15

49

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 0: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 pixeldust.wikidot.com/linode-setup%3adropbox seems to work well. – Zac Jan 9 '14 at 20:31
13

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.

11

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
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...

3

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.

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.

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.

2

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.

1

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.

1

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

  • @roaima thanks for your judgment. Which other solution? I just posted the solution which worked for me. – Aryo Z Dec 8 '16 at 5:35
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
  • Assuming you really do mean [ $rv -eq 0] (and not [ $rv -ne 0 ]) you could simplify all that with dropbox running && dropbox start – roaima Dec 8 '16 at 12:07
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

-1

The solution is as other python programs :

shell$ nohup ~/.dropbox-dist/dropboxd & 
-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

  • 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 0:36

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.