dropbox / dropbox/nautilus-dropbox
Dropbox daemon writes incorrect PID to `~/.dropbox/dropbox.pid` when running as `systemd` user service
- Dominant language
- Python
- Stars
- 276
- Forks
- 68
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 2
Description
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:
```bash
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](https://github.com/dropbox/nautilus-dropbox/blob/2852e07cc1cd73bfd948790ac2ea07f4fa94fdad/dropbox.in#L136-L147) is working correctly:
```python
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:
```ini
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.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reading nautilus-dropbox/dropbox.in lines 136-147 and reproducing the issue with the Dropbox daemon as a systemd user service. Compare the PID in ~/.dropbox/dropbox.pid with the service's MainPID and trace when the daemon writes the file. Done means the file contains the daemon PID and dropbox status detects the running service.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- linux, python
- Domain
- cli, operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100