Guide: Hosting Archives from a Server
This guide will show you how to use some simple command-line tools to host archives on a VPS. (This guide is designed for systemd-based systems, including debian/ubuntu.)
npm install -g dat-next 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
Add and remove
dat clone commands to ~/dats/services to change the archives your server hosts. You don't need to restart the dat-lil-pids service, because it watches the services file and automatically adds/removes processes to match it.
On your server, install the following tools from npm:
npm install -g dat-next lil-pids add-to-systemd
Create the Archives
Follow the Dat CLI Guide to create the archives. You can do this on your local machine, or on the server. Take note of the URLs of the archives you want to rehost.
For this guide, we'll use this site (datprotocol.com) as an example archive. It is located at
Upload the Archives
To make sure the archives get to the server, we'll manually upload the archives first. In this guide, we'll use the
mkdir ~/dats cd ~/dats dat clone dat://ff34725120b2f3c5bd5028e4f61d14a45a22af48a7b12126d5d588becde88a93/ ./datprotocol Cloning Dat Archive: /home/alice/dats/datprotocol Link: dat://ff34725120b2f3c5bd5028e4f61d14a45a22af48a7b12126d5d588becde88a93 Metadata: [==================================================>] 100% Content: [==================================================>] 100% Total size: 7 files (38.2 kB) 2 peers on the Dat Network
Once this is done, you can close the process.
Note: there's an open issue that can cause the Content progress to stop at under... or *over*... 100%, even though all content is synced. Don't worry about it.
Write the Services File
Now, we want to turn that 'clone' command into a long-running process. The lil-pids tool is a simple process-manager which watches a "services file" to determine which commands should be active. We'll use it to spawn a number of dat-clone processes. The file we'll write is ~/dats/services.
The command is the same as before, except that we'll add
--upload to rehost the archive to the network, and
--quiet to suppress output that we don't need cluttering our logs.
Use an editor to write to ~/dats/services:
dat dat://ff34725120b2f3c5bd5028e4f61d14a45a22af48a7b12126d5d588becde88a93/ \ ~/dats/datprotocol \ --quiet
To start the commands, we run:
lil-pids ~/dats/services ~/dats/pids
You can view the process ids of the commands (in another CLI session) with
Add to Systemd
Finally, we want to turn the
lil-pids process into a daemon. Run these commands to do so:
sudo add-to-systemd dat-lil-pids $(which lil-pids) ~/dats/services ~/dats/pids sudo systemctl start dat-lil-pids
If successful, you'll be able to run
sudo systemctl status dat-lil-pids and see the output.
If you want to add or remove dats, you don't need to restart the service. Just edit the
~/dats/services file to include the additional
dat clone commands. After saving, lil-pids will automatically open and close processes to match the file.