docs/cli/multi-instance.mdx
Spacedrive CLI now supports running multiple daemon instances simultaneously, enabling local testing of device pairing and other multi-device features.
Multiple daemon instances allow you to:
# Start default instance
spacedrive start
# Start named instances
spacedrive start --instance alice
spacedrive start --instance bob
# Start with networking enabled
spacedrive start --instance alice
spacedrive start --instance bob
Use the --instance flag to target commands to specific daemon instances:
# Default instance
spacedrive library list
# Named instances
spacedrive --instance alice library list
spacedrive --instance bob library create "Bob's Library"
# List all daemon instances
spacedrive instance list
# Stop specific instance
spacedrive instance stop alice
spacedrive --instance bob stop # Alternative syntax
# Check status of specific instance
spacedrive --instance alice daemon
On macOS, you can configure instances to start automatically on login:
# Install auto-start for default instance
spacedrive daemon install
# Install auto-start for named instance
spacedrive --instance alice daemon install
# Check auto-start status
spacedrive --instance alice daemon status
# Remove auto-start
spacedrive --instance alice daemon uninstall
Each instance gets its own LaunchAgent plist file. The daemon starts with the correct --data-dir and --instance flags automatically. Logs write to ~/Library/Application Support/spacedrive/logs/daemon.out.log and daemon.err.log.
Test device pairing locally using two instances:
# Terminal 1: Start Alice's daemon
spacedrive start --instance alice --foreground
# Terminal 2: Start Bob's daemon
spacedrive start --instance bob --foreground
# Terminal 3: Alice generates pairing code
spacedrive --instance alice network init --password "test123"
spacedrive --instance alice network pair generate --auto-accept
# Terminal 4: Bob joins using Alice's code
spacedrive --instance bob network init --password "test123"
spacedrive --instance bob network pair join "word1 word2 word3 ... word12"
Each instance has completely isolated:
spacedrive.sock, spacedrive-alice.sock, spacedrive-bob.sockspacedrive.pid, spacedrive-alice.pid, spacedrive-bob.piddata/sd-cli-data/, data/sd-cli-data/instance-alice/cli_state.json per instance$runtime_dir/ # /tmp or $XDG_RUNTIME_DIR
├── spacedrive.sock # Default instance socket
├── spacedrive.pid # Default instance PID
├── spacedrive-alice.sock # Alice instance socket
├── spacedrive-alice.pid # Alice instance PID
├── spacedrive-bob.sock # Bob instance socket
└── spacedrive-bob.pid # Bob instance PID
data/sd-cli-data/ # Default instance data
├── spacedrive.json
├── libraries/
└── cli_state.json
data/sd-cli-data/instance-alice/ # Alice instance data
├── spacedrive.json
├── libraries/
└── cli_state.json
data/sd-cli-data/instance-bob/ # Bob instance data
├── spacedrive.json
├── libraries/
└── cli_state.json
# Start two instances for pairing test
spacedrive start --instance initiator --foreground &
spacedrive start --instance joiner --foreground &
# Initialize networking
spacedrive --instance initiator network init --password "dev123"
spacedrive --instance joiner network init --password "dev123"
# Test pairing
CODE=$(spacedrive --instance initiator network pair generate --auto-accept | grep "Pairing code:" | cut -d' ' -f3-)
spacedrive --instance joiner network pair join "$CODE"
# Verify connection
spacedrive --instance initiator network devices
spacedrive --instance joiner network devices
# Stop all instances
spacedrive instance list
spacedrive instance stop alice
spacedrive instance stop bob
spacedrive stop # Default instance
# Clean up sockets (if needed)
rm /tmp/spacedrive*.sock /tmp/spacedrive*.pid
The implementation maintains full backwards compatibility: