Preventing RAID spin-ups: Running dropboxd in scheduled windows using systemd

Introduction

I use Dropbox to back up my smartphone photos in full resolution to my home server, allowing me to avoid paying for high-capacity cloud services just to transfer files. Since my server curie has plenty of local storage, I only need a reliable cloud platform to serve as a middle layer. The basic 2GB free tier of Dropbox is perfect for this when paired with its “Camera Uploads” mobile feature. The photos sync immediately to the server, and a script sweeps them into permanent storage, keeping our Dropbox usage well under the 2GB limit.

However, running the headless Dropbox daemon 24/7 creates a secondary issue: it keeps the local storage array spinning all day, causing unnecessary disk wear, power draw, and noise. The solution is to stop the always-on services and run Dropbox in short windows a few times per day using systemd. This uses the official Linux daemon and command line interface, see Dropbox for Linux install and Dropbox Linux CLI.

Create a windowed Dropbox service

First, I created a template service, /etc/systemd/system/dropbox-window@.service. This runs the official daemon at /opt/dropbox/dropboxd for a limited time, 30 minutes, then stops it automatically via RuntimeMaxSec. The %i token acts as a placeholder for the username, making it incredibly easy to scale to a multi-user setup. See systemd.service.

[Unit]
Description=Run Dropbox for a limited window for %i
After=network-online.target
Wants=network-online.target
 
[Service]
Type=simple
User=%i
ExecStart=/opt/dropbox/dropboxd
# Stop the process automatically after 30 minutes
RuntimeMaxSec=1800
# SIGINT lets Dropbox shut down gracefully, similar to pressing Ctrl-C.
KillSignal=SIGINT
# Ensures that when systemd stops the service, it sends the stop signal to all processes in the same control group
KillMode=control-group
# Gives Dropbox up to 60 seconds to stop gracefully after receiving SIGINT before further action is taken.
TimeoutStopSec=60
# If the service still does not stop after TimeoutStopSec, systemd will send SIGKILL to forcibly terminate it.
SendSIGKILL=yes
# Commands that run after the main process stops. These are cleanup actions. Kills any leftover Dropbox processes
# matching /opt/dropbox/.../dropbox for that user
ExecStopPost=/usr/bin/pkill -u %i -f '/opt/dropbox/.*/dropbox'

Setting KillMode=control-group ensures the entire process tree receives the termination signal. As an extra failsafe for a multi-user environment, the ExecStopPost command uses a precise pkill target limited to that specific user account (-u %i). This ensures user instances do not interfere with each other or leave orphan processes behind.

Schedule the window every six hours

Then I created a timer unit, /etc/systemd/system/dropbox-window@.timer. Instead of a relative monotonic timer (like OnUnitActiveSec=6h, which can cause multi-user accounts to drift out of sync), this uses a fixed wall-clock calendar schedule (OnCalendar) to lock all user sync windows to the exact same times:

[Unit]
Description=Start Dropbox window for %i every 6 hours
 
[Timer]
OnBootSec=5min
OnCalendar=03,09,15,21:00:00
Persistent=true
 
[Install]
WantedBy=timers.target

Using OnCalendar=03,09,15,21:00:00 guarantees that all user instances fire simultaneously at 03:00, 09:00, 15:00, and 21:00. This ensures the hard drive array spins up only once per 6-hour block for all accounts. If you want a shorter window, you can adjust RuntimeMaxSec=900 (15 minutes) in the service unit.

Enable the timers

Now I could enable the service for the respective users on the server:

sudo systemctl enable --now dropbox-window@tjansson.timer 
sudo systemctl enable --now dropbox-window@user2.timer

Systemd handles the execution windows independently for each account, ensuring everything stays isolated and highly maintainable.

Looking at my system thread monitoring metrics below, you can see how this optimization helped. Instead of a continuous high thread count baseline, the server now shows distinct, sharp spikes only when the Dropbox windows open every 6 hours, leaving the system (and the disks) completely at peace in between. Part of the problem was also that dropboxd was failing as it was not up to date, but see how that is resolved below.

Munin thread monitoring showing windowed dropbox service activity spikes

Moving files into permanent storage

With the sync windows running on a predictable cycle, we need to regularly pull files out of the incoming Dropbox/Camera Uploads directory. Relocating these files locally forces Dropbox to delete them from the cloud during the next sync window, keeping your 2GB quota permanently open.

Here is the bash script I run to move the images to my permanent media directory (/home/tjansson/bin/move-dropbox-images-tjansson.sh):

#!/bin/bash
 
shopt -s nullglob  # don't return literal glob if matching fails
 
DIR_FROM="/home/tjansson/Dropbox/Camera Uploads"
DIR_DEST="/home/tjansson/Media/Pictures/Thomas-phone-pictures/"
 
# Only try to move the files if there are any files present
FROM_FILES=("$DIR_FROM"/*.*)
if [[ ${#FROM_FILES[@]} > 1 ]]; then
    mv "$DIR_FROM"/*.* "$DIR_DEST"
fi

Note the shopt -s nullglob line—this is important so that if the folder is empty, bash doesn’t try to literally move a file named *.*, which would result in an error.

Set this script to run 2 minutes past the hour during each sync window (at 03:02, 09:02, 15:02, and 21:02) via your user’s crontab:

02 3,9,15,21 * * * /home/tjansson/bin/move-dropbox-images-tjansson.sh

Running the script right after the window opens ensures incoming media is moved into permanent storage while the drives are already spun up and Dropbox is connected. You can set up a matching cron entry for secondary user accounts as well.

Automating Dropbox Updates

The headless Dropbox binaries must be kept up to date; otherwise, the client eventually refuses to authenticate and stops syncing entirely. Since our systemd timers handle stopping the daemons automatically at 03:30 AM, we can run a silent update script shortly after on the NVMe system drive while the RAID array is asleep.

I keep this script at /opt/update-dropbox.sh and run it once a day at 04:30 AM through root’s crontab (30 4 * * * /opt/update-dropbox.sh):

#!/usr/bin/env sh
 
# 1. Download the latest Dropbox Linux package.
sudo curl -sSL "https://www.dropbox.com/download?plat=lnx.x86_64" -o dropbox-linux.tar.gz
 
# 2. Extract the downloaded package directly to /opt/dropbox.
sudo tar xzf dropbox-linux.tar.gz --strip 1 -C /opt/dropbox
 
# 3. Clean up the tarball.
sudo rm -f dropbox-linux.tar.gz

By omitting systemctl start commands in the update script, the download and extraction happen entirely on the NVMe OS drive without waking the sleeping RAID array. The newly updated binaries are then naturally picked up when the next scheduled window opens at 09:00 AM.

Conclusion

By shifting from an always-on configuration to a windowed sync architecture, we address two operational challenges at once. We retain a completely seamless, multi-user mobile backup workflow that avoids expensive cloud storage tiers, while also ensuring that our server’s hard drives aren’t being forced to stay awake 24/7 by a restless background daemon. The disks get to spin down quietly, our hardware lifespan is extended, and our backups remain perfectly up to date.

Notes and references

If you are setting up from scratch on a server, follow the headless flow described on the official install page, then keep the daemon in /opt/dropbox.

Leave a Reply