Skip to content

Dropbox daemon writes incorrect PID to ~/.dropbox/dropbox.pid when running as systemd user service #154

@Montana

Description

@Montana

Hi all,

The Dropbox daemon writes incorrect PID to ~/.dropbox/dropbox.pid when running as systemd user service, here are some more details.

Environment

  • OS: Linux
  • Dropbox daemon version: 178.3.4678
  • Dropbox command-line interface version: 2020.03.04
  • Setup: Dropbox daemon running as systemd user service, interacting via nautilus-dropbox

The Dropbox daemon is writing an incorrect PID (2, which corresponds to the kthreadd kernel process) to ~/.dropbox/dropbox.pid when running as a systemd user service. This causes the dropbox status command to report "Dropbox isn't running!" even though the daemon is actually running properly.

Steps to Reproduce

  1. Run Dropbox daemon as a systemd user service
  2. Execute dropbox status
  3. Observe "Dropbox isn't running!" error message
  4. Check cat ~/.dropbox/dropbox.pid - shows 2 instead of the actual daemon PID

The dropbox.pid file should contain the actual PID of the Dropbox daemon process, allowing dropbox status to correctly detect that the daemon is running.

Current Workaround

Manually updating the PID file with the correct value works:

systemctl show -p MainPID --value dropbox.service > ~/.dropbox/dropbox.pid

After this manual fix, dropbox status works correctly.

The issue appears to be in how the daemon writes its PID when launched via systemd. The status check logic in nautilus-dropbox/dropbox.in lines 136-147 is working correctly:

def is_dropbox_running():
    pidfile = os.path.expanduser("~/.dropbox/dropbox.pid")
    try:
        with open(pidfile, "r") as f:
            pid = int(f.read())
        with open("/proc/%d/cmdline" % pid, "r") as f:
            cmdline = f.read().lower()
    except:
        cmdline = ""
    return "dropbox" in cmdline

The problem is that the daemon is writing 2 (kthreadd PID) to the file instead of its own PID.

Attempted Solutions

I tried using a systemd ExecStartPost directive to automatically correct the PID file:

ExecStartPost = "/bin/bash -c 'systemctl show -p MainPID --value dropbox.service > $HOME/.dropbox/dropbox.pid'"

However, this doesn't work - the PID file still contains 2 after service startup, suggesting the daemon overwrites the file after the ExecStartPost runs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions