diff options
-rw-r--r-- | docs/cookbook/server.md | 84 |
1 files changed, 74 insertions, 10 deletions
diff --git a/docs/cookbook/server.md b/docs/cookbook/server.md index 056d8d8..015ce4b 100644 --- a/docs/cookbook/server.md +++ b/docs/cookbook/server.md @@ -1,16 +1,80 @@ # Dats on a Server -After you create your dat and close your laptop, other people won't be able to access your data. You might want a server that is always running, that archives and mirrors your dats, so that your dats are accessible at all times of the day. +Since Dat is a distributed (peer-to-peer) data sharing tool, a computer must be actively sharing a dat for it to be available. If you're sharing files over Dat, you might want to set up a dedicated server that re-hosts your dat. This means that it'll still be available even after you turn off your personal computer. -## TLDR -To host a dat on your server: +Running Dat on a server can also be used for live backups. As long as you are connected to your server and syncing changes, your server can backup all of your content history - allowing you to view old content later. +## Short Instructions + +We have built a simple tool to host multiple dats using the commandline. The tool is called `hypercored`. Hypercored reads a file that contains all of the dats that you want to share. + +Install it on your server, create a `feeds` file with dats separated by newlines, and run `hypercored`. + +``` +npm install -g hypercored +echo 'dat://64375abb733a62fa301b1f124427e825d292a6d3ba25a26c9d4303a7987bec65' >> feeds +echo 'dat://another-dat-link-here' >> feeds +hypercored +``` + +That's it. Now it will download and host the data for the each dat in the `feeds` file. Hypercored uses [hypercore-archiver](https://github.com/mafintosh/hypercore-archiver) for efficient sharing of many dats and full content history backup. + +See below for more detailed instructions. + +## Detailed Instructions + +### Node Version + +Check your node version, you should have version 4.0 or higher, but 6.10.3 or higher is preferred. + +``` +$ node -v ``` - npm install -g dat lil-pids add-to-systemd - mkdir ~/dats - echo "dat dat://ff34725120b2f3c5bd5028e4f61d14a45a22af48a7b12126d5d588becde88a93/ \ - ~/dats/datprotocol \ - --quiet" > ~/dats/services - sudo add-to-systemd dat-lil-pids $(which lil-pids) ~/dats/services ~/dats/pids - sudo systemctl start dat-lil-pids + +Then, go to your server (using `ssh username@hostname.com`) and install `hypercored`: + ``` +npm install -g hypercored +``` + +If you have installation trouble due to a permissions error, please see [this tutorial for fixing permissions in node.js](https://docs.npmjs.com/getting-started/fixing-npm-permissions). + +Now, create a file called 'feeds' with the list of dats you want to share. + +feeds +``` +dat://one-hash +two-hash +website.com/three-hash +``` + +So then if you `ls` you should see `feeds` in the list of files. + +``` +$ ls +feeds +``` + +Now, to share these dats simply type `hypercored` in the same directory. + +``` +~/dat $ hypercored +Watching ~/dat/feeds for a list of active feeds +Archiver key is 42471e32d36be3cb617ec1df382372532aac1d1ce683982962fb3594c5f9532a +Swarm listening on port 58184 +``` + +That's great! Now all of the dats in `feeds` will be downloaded and re-hosted. However, it's running in the foreground -- you probably want to use a process manager to run and watch the process so that it never goes down. + +## Run it Forever + +We recommend using `lil-pids` and `add-to-systemd` for long-term dat hosting from a linux server. + +``` +npm install -g add-to-systemd lil-pids +mkdir ~/dat +echo "hypercored --cwd ~/dat" > ~/dat/services +sudo add-to-systemd dat-lil-pids $(which lil-pids) ~/dat/services ~/dat/pids +``` + +Replace `~` with the path where you want to store your dats. |