Zend certified PHP/Magento developer

Change IPFS repo location in daemon service

I’m working to create a service that maintains an IPFS daemon, as part of a private IPFS network.

To try & keep the IPFS into available to all users easily, I chose to initialize the IPFS repo in an /opt folder. I set IPFS_PATH in /etc/bash.bashrc such that the default location for all users is in this /opt folder:

18:53:02 [foo@server ~]
$ echo $IPFS_PATH
/opt/ipfsNode/.ipfs

Once this was completed, I successfully initialized my IPFS repo & was able to start the daemon as expected.

$ ipfs daemon
Initializing daemon...
go-ipfs version: 0.12.2
Repo version: 12
System version: amd64/linux
Golang version: go1.16.15
Swarm is limited to private network of peers with the swarm key
Swarm key fingerprint: [redacted]
Swarm listening on /ip4/<ip>/tcp/4001
Swarm listening on /ip4/127.0.0.1/tcp/4001
Swarm listening on /ip6/::1/tcp/4001
Swarm listening on /p2p-circuit
Swarm announcing /ip4/<ip>/tcp/4001
Swarm announcing /ip4/127.0.0.1/tcp/4001
Swarm announcing /ip6/::1/tcp/4001
API server listening on /ip4/<ip>/tcp/5001
WebUI: http://<ip>:5001/webui
Gateway (readonly) server listening on /ip4/<ip>/tcp/8080
Daemon is ready

To transition this into a service, I created this service definition at /etc/systemd/system/ipfs.service, using an example from an Eleks lab:

[Unit]
 Description=IPFS Daemon
 After=syslog.target network.target remote-fs.target nss-lookup.target
 [Service]
 Type=simple
 ExecStart=/usr/local/bin/ipfs daemon --enable-namesys-pubsub
 User=foo
 [Install]
 WantedBy=multi-user.target

However, it seems to try & use a repo initialized on top of my home directory ~/.ipfs instead of ${IPFS_PATH}/.ipfs when the service is started. How can I change this to find the repo I’ve already initialized?

● ipfs.service - IPFS Daemon
     Loaded: loaded (/etc/systemd/system/ipfs.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Wed 2022-06-01 18:43:03 UTC; 17min ago
    Process: 227966 ExecStart=/usr/local/bin/ipfs daemon --enable-namesys-pubsub (code=exited, status=1/FAILURE)
   Main PID: 227966 (code=exited, status=1/FAILURE)

Jun 01 18:43:03 <server> systemd[1]: Started IPFS Daemon.
Jun 01 18:43:03 <server> ipfs[227966]: Initializing daemon...
Jun 01 18:43:03 <server> ipfs[227966]: go-ipfs version: 0.12.2
Jun 01 18:43:03 <server> ipfs[227966]: Repo version: 12
Jun 01 18:43:03 <server> ipfs[227966]: System version: amd64/linux
Jun 01 18:43:03 <server> ipfs[227966]: Golang version: go1.16.15
Jun 01 18:43:03 <server> ipfs[227966]: Error: no IPFS repo found in /home/foo/.ipfs.
Jun 01 18:43:03 <server> ipfs[227966]: please run: 'ipfs init'
Jun 01 18:43:03 <server> systemd[1]: ipfs.service: Main process exited, code=exited, status=1/FAILURE
Jun 01 18:43:03 <server> systemd[1]: ipfs.service: Failed with result 'exit-code'.