Skip to content

Instantly share code, notes, and snippets.

@olisolomons
Created February 19, 2022 16:52
Show Gist options
  • Select an option

  • Save olisolomons/5de5c8325a66c6e5b1e7e711afeabb68 to your computer and use it in GitHub Desktop.

Select an option

Save olisolomons/5de5c8325a66c6e5b1e7e711afeabb68 to your computer and use it in GitHub Desktop.
Make dropbox start properly
import os
import subprocess
import shutil
import time
import sys
# copied from dropbox source code
PARENT_DIR = os.path.expanduser("~")
DROPBOX_DIST_PATH = "%s/.dropbox-dist" % PARENT_DIR
DROPBOXD_PATH = os.path.join(DROPBOX_DIST_PATH, "dropboxd")
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 Exception:
cmdline = ""
return "dropbox" in cmdline
def start_dropbox():
if os.access(DROPBOXD_PATH, os.X_OK):
f = open("/dev/null", "w")
# Fix indicator icon and menu on Unity environments. (LP: #1559249)
# Fix indicator icon and menu in Budgie environment. (LP: #1683051)
new_env = os.environ.copy()
current_env = os.environ.get("XDG_CURRENT_DESKTOP", '').split(":")
to_check = ['Unity', 'Budgie']
if any(word in to_check for word in current_env):
new_env['XDG_CURRENT_DESKTOP'] = 'Unity'
# we don't reap the child because we're gonna die anyway, let init do it
dropboxd_proc = subprocess.Popen([DROPBOXD_PATH], preexec_fn=os.setsid, cwd=os.path.expanduser("~"),
stderr=sys.stderr, stdout=f, close_fds=True, env=new_env)
while dropboxd_proc.poll() is None:
if is_dropbox_running():
return True
time.sleep(5)
print(f'dropbox proprietary daemon exited with code {dropboxd_proc.returncode}')
return False
else:
return False
def start():
subprocess.Popen([shutil.which('dropbox'), 'start'])
def main():
if is_dropbox_running() or start_dropbox():
print('dropbox daemon is running')
start()
else:
print('unable to start daemon')
sys.exit(1)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment