PM2 + IPFS

Theory

PM2 is a free/open source process manager that enables remote monitoring, automatic restarts, and other useful system adminstrative features.

IPFS is a distributed storage network that replaces convention hypertext linking via the fusion of files to a “one size fits all” string of characters called a hash.

Download IPFS

wget https://github.com/ipfs/go-ipfs/releases/download/v0.4.23/go-ipfs_v0.4.23_linux-amd64.tar.gz

Extract IPFS

tar xvfz go-ipfs_v0.4.23_linux-amd64.tar.gz

Change Directory Into the IPFS Folder

cd go-ipfs

Install IPFS

sudo ./install.sh

Initalize IPFS

ipfs init

Edit IPFS's Configuration

Changes directory into the folder

cd ~/.ipfs

Customize Your Configuration With Nano

sudo apt-get install nano

nano config

Using Nano to modify the configuration

ctrl + x + y

Change IPFS Repo Size

From

"StorageMax": "10GB", to

"StorageMax": "50GB",

Change IPFS Port

Find

"/ip4/0.0.0.0/tcp/4001",

"/ip6/::/tcp/4001"

Replace with

"/ip4/0.0.0.0/tcp/44444",

"/ip6/::/tcp/44444"

Or with the ports you desire.

Prioritize Stored Files Over Cache (with –enable-gc)

From

"Strategy": "all"

To

"Strategy": "pinned"

Select a Different Directory for Storing IPFS's Files

export IPFS_PATH=/edit/this/path/to/ipfsrepo

After Exporting, re-run the init command.

ipfs init

Install Node

curl -sL https://deb.nodesource.com/setup_13.x | sudo -E bash -

sudo apt-get install -y nodejs

For non Ubuntu based distriubtions of linux, seek refrence from Nodesource's readme.

Install PM2

sudo npm install [email protected] -g

Start IPFS Daemon

pm2 start "ipfs daemon --enable-gc"

Starts IPFS daemon with garbage collection enabled.

Start IPFS Daemon With Memory Restriction

pm2 start "ipfs daemon --enable-gc" --max-memory-restart 3G

Restarts IPFS daemon if memory usage surpasses 3GB.

Restart IPFS

pm2 status

Gets the process ID.

pm2 restart 0

Use the process ID found with pm2 status that is running IPFS Daemon. (normally 0 if you have no other processes)

Stop IPFS

pm2 stop 0

Use the process ID found with pm2 status that is running IPFS Daemon. (normally 0 if you have no other processes)

Make IPFS Run At First Boot

pm2 startup

Copy and input the command given.

pm2 save

Saves the current process list enabling each process to run when the computer starts.