Can't start IPFS daemon - ipfs.service: Failed with result 'exit-code'

I’m a noob in sysadmin. I restarted my Ubuntu server on AWS. But now, when I run systemctl start ipfs.service I get the error below.

● ipfs.service - InterPlanetary File System (IPFS) daemon
     Loaded: loaded (/etc/systemd/system/ipfs.service; disabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Sun 2023-08-13 01:40:02 UTC; 4s ago
       Docs: https://docs.ipfs.io/
    Process: 1852 ExecStart=/usr/local/bin/ipfs daemon --init --migrate (code=exited, status=1/FAILURE)
   Main PID: 1852 (code=exited, status=1/FAILURE)

Aug 13 01:40:02 ip-172-31-11-119 ipfs[1852]: Repo version: 12
Aug 13 01:40:02 ip-172-31-11-119 ipfs[1852]: System version: 386/linux
Aug 13 01:40:02 ip-172-31-11-119 ipfs[1852]: Golang version: go1.16.15
Aug 13 01:40:02 ip-172-31-11-119 ipfs[1852]: generating ED25519 keypair...done
Aug 13 01:40:02 ip-172-31-11-119 ipfs[1852]: peer identity: 12D3KooWQV1MBeUvUrtnDQzePRyfbPae12jTs3p6dc8zSJRnvR8B
Aug 13 01:40:02 ip-172-31-11-119 ipfs[1852]: initializing IPFS node at ${HOME}
Aug 13 01:40:02 ip-172-31-11-119 ipfs[1852]: Error: mkdir ${HOME}: permission denied
Aug 13 01:40:02 ip-172-31-11-119 systemd[1]: ipfs.service: Main process exited, code=exited, status=1/FAILURE
Aug 13 01:40:02 ip-172-31-11-119 systemd[1]: ipfs.service: Failed with result 'exit-code'.
Aug 13 01:40:02 ip-172-31-11-119 systemd[1]: Failed to start InterPlanetary File System (IPFS) daemon.

I decided to launch a new AWS Ubuntu instance for my IPFS node and still I’m encountering errors. Been launching 8 instances with setting up 8 times to no avail. It’s been very frustrating. Experiencing Murphy’s Law in every step.

I followed this tutorial - Tutorial: Setting up an IPFS peer, part I | by Carson Farmer | Textile | Medium and I have the below ipfs.service.

[Unit]
Description=ipfs daemon
[Service]
ExecStart=/usr/local/bin/ipfs daemon --enable-gc
Restart=on-failure
RestartSec=5
User=ubuntu
Group=ubuntu
Environment="IPFS_PATH=/data/ipfs"
[Install]
WantedBy=multi-user.target

But I keep getting this…

ubuntu@ip-172-31-35-57:~$ sudo systemctl status ipfs
● ipfs.service - ipfs daemon
     Loaded: loaded (/etc/systemd/system/ipfs.service; enabled; vendor preset: enabled)
     Active: activating (auto-restart) (Result: exit-code) since Mon 2023-08-14 01:25:54 UTC; 3s ago
    Process: 78949 ExecStart=/usr/local/bin/ipfs daemon --enable-gc (code=exited, status=1/FAILURE)
   Main PID: 78949 (code=exited, status=1/FAILURE)
        CPU: 67ms

The funny thing is I managed to set up an Ubuntu AWS IPFS node last year but I forgot all of it cos I’m not a sysadmin.

When I run the command /usr/local/bin/ipfs daemon --enable-gc independently, it seems to work fine. But I’m not sure why the service refused to work.

The syslog says this…

Aug 14 13:49:10 ip-172-31-35-57 systemd[1]: Started ipfs daemon.
Aug 14 13:49:10 ip-172-31-35-57 ipfs[218510]: Initializing daemon...
Aug 14 13:49:10 ip-172-31-35-57 ipfs[218510]: Kubo version: 0.22.0
Aug 14 13:49:10 ip-172-31-35-57 ipfs[218510]: Repo version: 14
Aug 14 13:49:10 ip-172-31-35-57 ipfs[218510]: System version: amd64/linux
Aug 14 13:49:10 ip-172-31-35-57 ipfs[218510]: Golang version: go1.19.12
Aug 14 13:49:10 ip-172-31-35-57 ipfs[218510]: Error: no IPFS repo found in /data/ipfs.
Aug 14 13:49:10 ip-172-31-35-57 ipfs[218510]: please run: 'ipfs init'
Aug 14 13:49:10 ip-172-31-35-57 systemd[1]: ipfs.service: Main process exited, code=exited, status=1/FAILURE
Aug 14 13:49:10 ip-172-31-35-57 systemd[1]: ipfs.service: Failed with result 'exit-code'.

But when I ran ipfs init, I get this.

ubuntu@ip-172-31-35-57:~$ ipfs init
generating ED25519 keypair...done
peer identity: 12D3KooWQt2nmHF...
initializing IPFS node at /home/ubuntu/.ipfs
Error: ipfs configuration file already exists!
Reinitializing would overwrite your keys

If you read the error messages closely you will notice you are running ipfs init with IPFS_PATH unset (so it uses default path), while systemd is trying to use /data/ipfs, which is still uninitialized.

Thank you. I finally got it to work by hardcoding this…

Environment="IPFS_PATH=/home/ubuntu"