UNPKG

17.6 kBMarkdownView Raw
1# hyperdrive-daemon
2[![Build Status](https://travis-ci.com/andrewosh/hyperdrive-daemon.svg?branch=master)](https://travis-ci.com/andrewosh/hyperdrive-daemon)
3
4The Hyperdrive daemon helps you create, share, and manage Hyperdrives through a persistent process running on your computer, without having to deal with storage management or networking configuration.
5
6It provides both a gRPC API (see [`hyperdrive-daemon-client`](https://github.com/andrewosh/hyperdrive-daemon-client)) for interacting with remote drives, and an optional FUSE interface for mounting drives as directories in your local filesystem.
7
8#### Features
9* __Hyperswarm Networking__: Hyperdrives are announced and discovered using the [Hyperswarm DHT](https://github.com/hyperswarm/hyperswarm).
10* __Easy Storage__: All your Hyperdrives are stored in a single spot, the `~/.hyperdrive/storage` directory.
11* __gRPC API__: The daemon exposes an API for managing remote Hyperdrives over gRPC. We currently have a [NodeJS client](https://github.com/andrewosh/hyperdrive-daemon-client).
12* __FUSE support__: If you're using Linux or Mac, you can mount Hyperdrives as directories and work with them using standard filesystem syscalls.
13* __CLI Tools__: The `hyperdrive` CLI supports a handful of commands for managing the daemon, creating/sharing drives, getting statistics, and augmenting the FUSE interface to support Hyperdrive-specific functions (like mounts).
14* __Persistence__: Networking configuration info is stored in a [Level](https://github.com/level/level) instance, so your drives will reconnect to the network automatically when the daemon's restarted.
15* __PM2 Process Management__: We use [PM2](https://github.com/Unitech/pm2) to manage the daemon process. Separately installing the PM2 CLI gives you access to extra monitoring, and support for installing the Hyperdrive daemon as a system daemon
16
17## Installation
18*Note: The daemon CLI currently requires Node 12 or greater*
19
20__Temporary Note: We're working out a [segfault issue](https://github.com/hypercore-protocol/hyperdrive-daemon/issues/47) that's causing the daemon to fail with Node 14. If you're on 14, check that issue for updates, but for now try using 12 or 13__.
21
22```
23npm i hyperdrive-daemon -g
24```
25
26### Starting the daemon
27
28After installing/configuring, you'll need to start the daemon before running any other commands. To do this, first pick a storage directory for your mounted Hyperdrives. By default, the daemon will use `~/.hyperdrive/storage`.
29
30```
31❯ hyperdrive start
32Daemon started at http://localhost:3101
33```
34
35If you want to stop the daemon, you can run:
36```
37❯ hyperdrive stop
38The Hyperdrive daemon has been stopped.
39```
40
41### Checking the status
42
43After it's been started, you can check if the daemon's running (and get lots of useful information) with the `status` command:
44```
45❯ hyperdrive status
46The Hyperdrive daemon is running:
47
48 API Version: 0
49 Daemon Version: 1.7.15
50 Client Version: 1.7.6
51 Schema Version: 1.6.5
52 Hyperdrive Version: 10.8.15
53 Fuse Native Version: 2.2.1
54 Hyperdrive Fuse Version: 1.2.14
55
56 Holepunchable: true
57 Remote Address: 194.62.216.174:35883
58
59 Uptime: 0 Days 1 Hours 6 Minutes 2 Seconds
60```
61
62## API
63The daemon exposes a gRPC API for interacting with remote Hyperdrives. [`hyperdrive-daemon-client`](https://github.com/andrewosh/hyperdrive-daemon-client) is a Node client that you can use to interact with the API. If you'd like to write a client in another language, check out the schema definitions in [`hyperdrive-schemas`](https://github.com/andrewosh/hyperdrive-schemas)
64
65## CLI
66
67Hypermount provides an gRPC interface for mounting, unmounting, and providing status information about all current mounts. There's also a bundled CLI tool which wraps the gRPC API and provides the following commands:
68
69### Basic Commands
70#### `hyperdrive fuse-setup`
71Performs a one-time configuration step that installs FUSE. This command will prompt you for `sudo`.
72
73#### `hyperdrive start`
74Start the Hyperdrive daemon.
75
76Options include:
77```
78 --bootstrap ['host:port', 'host:port', ...] // Optional, alternative bootstrap servers
79 --storage /my/storage/dir // The storage directory. Defaults to ~/.hyperdrive/storage
80 --log-level info // Logging level
81 --port 3101 // The port gRPC will bind to
82 --memory-only // Run in in-memory mode
83 --foreground // Do not launch a separate, PM2-managed process
84```
85
86#### `hyperdrive status`
87Gives the current status of the daemon, as well as version/networking info, and FUSE availability info.
88
89#### `hyperdrive stop`
90Stop the daemon.
91
92### Importing/Exporting
93If you're on a system that doesn't support FUSE, or you just don't want to bother with it, the CLI provides the `import` and `export` commands for moving files in and out of Hyperdrives.
94
95#### Importing
96To import a directory into a new Hyperdrive, you can run `import` without specifying a key:
97```
98❯ hyperdrive import ./path/to/directory
99Importing path/to/directory into aae4f36bd0b1a7a8bf68aa0bdd0b93997fd8ff053f4a3e816cb629210aa17737 (Ctrl+c to exit)...
100
101Importing | ======================================== | 100% | 3/3 Files
102```
103
104The command will remain running, watching the directory for any new changes, but you can always stop it with `Ctrl+c`
105
106`import` will save a special file called `.hyperdrive-import-key` inside the directory you uploaded. This makes it easier to resume a previous import later, without any additional arguments.
107
108Using the command above as an example, `hyperdrive import path/to/directory` subsequent times will always import into drive `aae4f36bd0b1a7a8bf68aa0bdd0b93997fd8ff053f4a3e816cb629210aa17737`.
109
110#### Exporting
111`hyperdrive export` is just the inverse of `import`: Given a key it will export the drive's contents into a directory:
112```
113❯ hyperdrive export aae4f36bd0b1a7a8bf68aa0bdd0b93997fd8ff053f4a3e816cb629210aa17737
114Exporting aae4f36bd0b1a7a8bf68aa0bdd0b93997fd8ff053f4a3e816cb629210aa17737 into (my working directory)/aae4f36bd0b1a7a8bf68aa0bdd0b93997fd8ff053f4a3e816cb629210aa17737 (Ctrl+c to exit)...
115
116Exporting | ======================================== | 100% | 5/5 Metadata Blocks | 0 Peers
117```
118Unless an output directory is specified, `export` will store files in a subdirectory with the drive's key as its name.
119
120As with `import`, `export` will store a special file which lets you resume exports easily (just `cd` into your previous output directory and run `hyperdrive export`), and it will remain running, watching the remote drive for changes.
121
122### Debugging Commands
123If you're testing bug fixes or features, some of these commands might be useful for you.
124
125#### `hyperdrive cleanup:remove-readonly-drives`
126Delete all read-only drives from disk. This will clear up storage, and makes it easier to test networking issues during development (as running this command will force you to re-sync test drives when the daemon is restarted).
127
128This command *must not* be run while the daemon is running. Since it deletes data, it's intentionally verbose!
129
130## FUSE
131Using FUSE, the Hyperdrive daemon lets your mount Hyperdrives as normal filesystem directories on both OSX and Linux. To use FUSE, you need to run the `setup` command before you start the daemon the first time:
132
133### Setup
134The setup command installs native, prebuilt FUSE bindings. We currently only provide bindings for OSX and Linux. The setup step is the only part of installation that requires `sudo` access:
135```
136❯ hyperdrive fuse-setup
137Configuring FUSE...
138[sudo] password for andrewosh:
139Successfully configured FUSE!
140```
141
142You should only need to perform this step once (it will persist across restarts). In order to make sure that the setup step completed successfully, run the `status` command. It should contain the following two FUSE-related lines:
143```
144❯ hyperdrive status
145...
146 Fuse Available: true
147 Fuse Configured: true
148```
149
150If FUSE is both available and configured, then you're ready to continue with mounting your top-level, private drive!
151
152### Usage
153The daemon requires all users to have a private "root" drive, mounted at `~/Hyperdrive`, into which additional subdrives can be mounted and shared with others.
154
155Think of this root drive as the `home` directory on your computer, where you might have Documents, Photos, or Videos directories. You'll likely never want to share your complete Documents folder with someone, but you can create a shareable mounted drive `Documents/coding-project-feb-2020` to share with collaborators on that project.
156
157#### Basic Mounting
158After starting the daemon with FUSE configured, you'll find a fresh root drive automatically mounted for you at `~/Hyperdrive`. This root drive will persist across daemon restarts, so it should always be available (just like your usual Home directory!).
159
160As with a home directory, you can might want to create directories like `~/Hyperdrive/Documents`, `~/Hyperdrive/Videos`, and `~/Hyperdrive/Projects`. Be careful though -- any directory you create with `mkdir` or through the OSX Finder will not be drive mounts, so they will not be shareable with others.
161
162There are two ways to create a shareable drive inside your root drive:
1631. `hyperdrive create [path]` - This will create a new shareable drive at `path` (where `path` must be a subdirectory of `~/Hyperdrive`. This drive will look like a normal directory, but if you run `hyperdrive info [path]` it will tell you that it's shareable.
1642. `hyperdrive mount [path] [key]` - This will mount an existing drive at `path`. It's useful if someone is sharing one of their drives with you, and you want to save it into your root drive.
165
166Here are a few examples of what this flow might look like:
167
168To mount a new drive, you can either provide a complete path to the desired mountpoint, or you can use a relative path if your current working directory is within `~/Hyperdrive`. As an example, here's how you would create a shareable drive called `Videos`, mounted inside your root drive:
169```
170❯ hyperdrive create ~/Hyperdrive/videos
171Mounted a drive with the following info:
172
173 Path : /home/foo/Hyperdrive/videos
174 Key: b432f90b2f817164c32fe5056a06f50c60dc8db946e81331f92e3192f6d4b847
175 Seeding: true
176```
177
178*__Note:__ Unless you use the `no-seed` flag, all new drives will be automatically "seeded," meaning they'll be announced on the Hyperswarm DHT. In the above example, this could be done with `hyperdrive create ~/Hyperdrive/videos --no-seed`. To announce it later, you can run `hyperdrive seed ~/Hyperdrive/videos`.*
179
180Equivalently:
181```
182❯ cd ~/Hyperdrive
183❯ hyperdrive create Videos
184```
185
186For most purposes, you can just treat this mounted drive like you would any other directory. The `hyperdrive` CLI gives you a few mount-specific commands for sharing drive keys and getting statistics for mounted drives.
187
188Mounted subdrives are seeded (announced on the DHT) by default, but if you've chosen to not seed (via the `--no-seed` flag), you can make them available with the `seed` command:
189```
190❯ hyperdrive seed ~/Hyperdrive/Videos
191Seeding the drive mounted at ~/Hyperdrive/Videos
192```
193
194Seeding will start announcing the drive's discovery key on the hyperswarm DHT, and this setting is persistent -- the drive will be reannounced when the daemon is restarted.
195
196After seeding, another user can either:
1971. Mount the same subdrive by key within their own root drive
1982. Inspect the drive inside the `~/Hyperdrive/Network` directory (can be a symlink target outside the FUSE mount!):
199```
200❯ hyperdrive info ~/Hyperdrive/Videos
201Drive Info:
202
203 Key: b432f90b2f817164c32fe5056a06f50c60dc8db946e81331f92e3192f6d4b847
204 Is Mount: true
205 Writable: true
206
207❯ ls ~/Hyperdrive/Network/b432f90b2f817164c32fe5056a06f50c60dc8db946e81331f92e3192f6d4b847
208vid.mkv
209```
210Or:
211```
212❯ hyperdrive mount ~/Hyperdrive/a_friends_videos b432f90b2f817164c32fe5056a06f50c60dc8db946e81331f92e3192f6d4b847
213...
214❯ ls ~/Hyperdrive/home/a_friends_videos
215vid.mkv
216```
217
218If you ever want to remove a drive, you can use the `hyperdrive unmount [path]` command.
219
220### The `Network` "Magic Folder"
221
222Within your root drive, you'll see a special directory called `~/Hyperdrive/Network`. This is a virtual directory (it does not actually exist inside the drive), but it provides read-only access to useful information, such as storage/networking stats for any drive in the daemon. Here's what you can do with the `Network` directory:
223
224#### Global Drive Paths
225For any drive that's being announced on the DHT, `~/Hyperdrive/Network/<drive-key>` will contain that drive's contents. This is super useful because these paths will be consistent across all daemon users! If you have an interesting file you want to share over IRC, you can just copy+paste `cat ~/Hyperdrive/Network/<drive-key>/my-interesting-file.txt` into IRC and that command will work for everyone.
226
227#### Storage/Networking Statistics
228Inside `~/Hyperdrive/Network/Stats/<drive-key>` you'll find two files: `storage.json` and `networking.json` containing an assortment of statistics relating to that drive, such as per-file storage usage, current peers, and uploaded/downloaded bytes of the drive's metadata and content feeds.
229
230*__Note__: `storage.json` is dynamically computed every time the file is read -- if you have a drive containing millions of files, this can be an expensive operation, so be careful.*
231
232Since looking at `networking.json` is a common operation, we provide a shorthand command `hyperdrive stats` that prints this file for you. It uses your current working directory to determine the key of the mounted drive you're in.
233
234#### Active Drives
235The `~/Hyperdrive/Network/Active` directory contains symlinks to the `networking.json` stats files for every drive that your daemon is currently announcing. `ls`ing this directory gives you a quick overview of exactly what you're announcing.
236
237### FUSE Commands
238*Note: Always be sure to run `hyperdrive setup` and check the FUSE status before doing any additional FUSE-related commands!*
239
240#### `hyperdrive create <path>`
241Create a new drive mounted at `path`.
242
243Newly-created drives are seeded by default. This behavior can be disabled with the `no-seed` flag, or toggled later through `hyperdrive seed <path>` or `hyperdrive unseed <path>`
244
245Options include:
246```
247 --no-seed // Do not announce the drive on the DHT.
248```
249
250#### `hyperdrive mount <path> <key>`
251Mount an existing Hyperdrive into your root drive at path `path`.
252
253If you don't specify a `key`, the `mount` command will behave identically to `hyperdrive create`.
254
255- `path` must be a subdirectory of `~/Hyperdrive/home`.
256- `key` is an optional drive key.
257
258CLI options include:
259```
260 --checkout (version) // Mount a static version of a drive.
261 --no-seed // Do not announce the drive on the DHT.
262```
263
264#### `hyperdrive info <path>`
265Display information about the drive mounted at `path`. The information will include the drive's key, and whether `path` is the top-level directory in a mountpoint (meaning it's directly shareable).
266
267- `path` must be a subdirectory of `~/Hyperdrive/`. If `path` is not specified, the command will use the enclosing mount of your current working directory.
268
269By default, this command will refuse to display the key of your root drive (to dissuade accidentally sharing it). To forcibly display your root drive key, run this command with `--root`.
270
271CLI options include:
272```
273 --root // Forcibly display your root drive key.
274```
275
276#### `hyperdrive seed <path>`
277Start announcing a drive on the DHT so that it can be shared with other peers.
278
279- `path` must be a subdirectory of `~/Hyperdrive/`. If `path` is not specified, the command will use the enclosing mount of your current working directory.
280
281By default, this command will refuse to publish your root drive (to dissuade accidentally sharing it). To forcibly publish your root drive, run this command with `--root`.
282
283CLI options include:
284```
285 --lookup (true|false) // Look up the drive key on the DHT. Defaults to true
286 --announce (true|false) // Announce the drive key on the DHT. Defaults to true
287 --remember (true|false) // Persist these network settings in the database.
288 --root // Forcibly display your root drive key.
289 ```
290
291#### `hyperdrive unseed <path>`
292Stop advertising a previously-published subdrive on the network.
293
294- `path` must be a subdirectory of `~/Hyperdrive/`. If `path` is not specified, the command will use the enclosing mount of your current working directory.
295
296*Note: This command will currently not delete the Hyperdrive from disk. Support for this will be added soon.*
297
298#### `hyperdrive stats <path>`
299Display networking statistics for a drive. This is a shorthand for getting a drive's key with `hyperdrive info` and `cat`ing `~/Hyperdrive/Network/Stats/<drive-key>/networking.json`.
300
301- `path` must be a subdirectory of `~/Hyperdrive/` and must have been previously mounted with the mount subcommand described above. If `path` is not specified, the command will use the enclosing mount of your current working directory.
302
303#### `hyperdrive force-unmount`
304If the daemon fails or is not stopped cleanly, then the `~/Hyperdrive` mountpoint might be left in an unusable state. Running this command before restarting the daemon will forcibly disconnect the mountpoint.
305
306This command should never be necessary! If your FUSE mountpoint isn't cleaned up on shutdown, and you're unable to restart your daemon (due to "Mountpoint in use") errors, please file an issue.
307
308## License
309MIT
310
\No newline at end of file