Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

In my experience this won't do the right thing, at least if you only want Dropbox to run during user sessions (without enabling linger, which keeps your systemd user session running even before and after you log out).

If you do want dropbox to run only at login, and be terminated upon logout, better to use this unit file:

[Unit]
Description=Dropbox Network Storage Daemon
After=graphical-session.target

[Service]
Type=forking
PIDFile=%h/.dropbox/dropbox.pid
ExecStart=/usr/bin/dropbox start
ExecStop=/usr/bin/dropbox stop

[Install]
WantedBy=default.target

The important change is to give it the location of dropbox's PIDFile= within your home directory, so that systemd can monitor the true dropbox process (${HOME}/.dropbox-dist/dropbox-lnx.x86_64-49.3.66/dropbox_py3 on my system, currently) while it's running, as well as confirm that it's correctly responded to start/stop commands.

Also, After=graphical-session.target ensures that it will only be started after Gnome Shell is running.

With this unit file installed and enabled, and dropbox.service started, systemd properly monitors the process and can manage it correctly:

$ systemctl --user --full --no-pager status dropbox.service
● dropbox.service - Dropbox Network Storage Daemon
   Loaded: loaded (XXXXXXXX/dropbox.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2018-05-03 21:35:41 EDT; 9min ago
  Process: 14805 ExecStart=/usr/bin/dropbox start (code=exited, status=0/SUCCESS)
 Main PID: 14889 (dropbox_py3)
   CGroup: /user.slice/user-1000.slice/user@1000.service/dropbox.service
           └─14889 /home/XXXXXXX/.dropbox-dist/dropbox-lnx.x86_64-49.3.66/dropbox_py3 /py3 /newerversion

May 03 21:35:41 HOSTNAME dropbox[14805]: dropbox: setting program path '/home/XXXXXXX/.dropbox-dist/dropbox-lnx.x86_64-49.3.66/dropbox_py3'
May 03 21:35:41 HOSTNAME dropbox[14805]: dropbox: setting home path '/home/XXXXXXX/.dropbox-dist/dropbox-lnx.x86_64-49.3.66'
May 03 21:35:41 HOSTNAME dropbox[14805]: dropbox: setting python path '/home/XXXXXXX/.dropbox-dist/dropbox-lnx.x86_64-49.3.66:/home/XXXXXXX/.dropbox-dist/dropbox-lnx.x86_64-49.3.66/python-packages-35.zip'
May 03 21:35:41 HOSTNAME dropbox[14805]: dropbox: python initialized
May 03 21:35:41 HOSTNAME dropbox[14805]: dropbox: running dropbox
May 03 21:35:41 HOSTNAME dropbox[14805]: dropbox: setting args
May 03 21:35:41 HOSTNAME dropbox[14805]: dropbox: applying overrides
May 03 21:35:41 HOSTNAME dropbox[14805]: dropbox: running main script
May 03 21:35:41 HOSTNAME dropbox[14805]: Done!
May 03 21:35:41 HOSTNAME systemd[1690]: Started Dropbox Network Storage Daemon.