Running a DAT share as a service with systemctl (Ubuntu, etc.)


#1

We just released the Better Blocker HTTP Archive collection under a Creative Commons ShareAlike license over DAT (you can read the original announcement on my Mastodon and get further info at archive.better.fyi.

Here, I want to document how we’re hosting it.

DATs are forever

Sharing a DAT archive is as easy as a dat share command in the CLI but, of course, that’s only valid for as long as the command is running. To ensure it’s available longer term, you have to run it as a daemon. Since archive.better.fyi is hosted on an OpenStack VPS running Ubuntu 18.04 at CloudScale, I thought I’d run it as a systemctl service unit.

It couldn’t be easier (well, OK, it could, but it’s quite easy anyway):

  1. Create the service unit file:

    sudo touch /etc/systemd/system/dat-share.service
    
  2. Then configure the service unit. For the Better HAR archive, I used:

    [Unit]
    Description=DAT Share: Better Blocker HTTP Archive collection
    After=network.target
    
    [Service]
    User=ubuntu
    Type=simple
    WorkingDirectory=/home/ubuntu/archive
    Environment=PATH=/home/ubuntu/.nvm/versions/node/v8.11.3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
    ExecStart=/home/ubuntu/.nvm/versions/node/v8.11.3/bin/node /home/ubuntu/.nvm/versions/node/v8.11.3/lib/node_modules/dat/bin/cli.js share
    Restart=always
    
    [Install]
    WantedBy=multi-user.target
    

    Note: I got into all sorts of trouble with systemctl timing out when trying to run the dat CLI binary directly – even with the service type set to forking, so that’s why I’m running the script explicitly via Node.

    Also, at one point I had to symlink node as I’m using NVM but I think that might have had to do with the service running as root before I’d put in the User field. Anyway, in case you run into the same issue:

    sudo ln -s "$(which node)" /usr/local/bin/node
    
  3. Enable the service:

    sudo systemctl enable dat-share
    
  4. Start the service:

    sudo systemctl start dat-share
    
  5. Check the logs and confirm that everything is fine:

    journalctl -fu dat-share.service
    

So, with this, the Better Blocker HTTP Archive is permanently being served from the archive.better.fyi server. Of course, as more people download and share the archive, it will also be available on the wider peer-to-peer DAT Web.