How to you make Kubo on Ubuntu 24.10 run as a daemon instead of having to launch it from command line as ipfs daemon?

To run Kubo as a background service on Ubuntu 24.10, you can set it up as a systemd service. This allows Kubo to start automatically at boot and run in the background without manual intervention. Here's how to do it:

**1. Create a Systemd Service File:**

Open a terminal and create a new service file for Kubo:

```bash sudo nano /etc/systemd/system/ipfs.service ```

In the editor, add the following content:

```ini [Unit] Description=IPFS Kubo Daemon After=network.target

[Service] User=your_username Group=your_username Environment=IPFS_PATH=/home/your_username/.ipfs ExecStart=/usr/local/bin/ipfs daemon –init –migrate Restart=on-failure KillSignal=SIGINT

[Install] WantedBy=multi-user.target ```

Replace `your_username` with your actual Ubuntu username. Ensure that the `ExecStart` path points to the correct location of the `ipfs` binary. The `Environment` variable `IPFS_PATH` should point to your IPFS repository path, typically `/home/your_username/.ipfs`.

**2. Reload Systemd and Enable the Service:**

After saving the file, reload systemd to recognize the new service:

```bash sudo systemctl daemon-reload ```

Enable the service to start at boot:

```bash sudo systemctl enable ipfs ```

sudo systemctl enable ipfs

Created symlink '/etc/systemd/system/multi-user.target.wants/ipfs.service' → '/etc/systemd/system/ipfs.service'.

**3. Start the IPFS Service:**

Start the IPFS service immediately:

```bash sudo systemctl start ipfs ```

**4. Verify the Service Status:**

Check the status of the IPFS service to ensure it's running correctly:

```bash sudo systemctl status ipfs ```

You should see output indicating that the service is active and running.

**Additional Considerations:**

- **Permissions:** Ensure that the user specified in the service file has the necessary permissions to access the IPFS repository and execute the `ipfs` binary.

- **IPFS_PATH:** If your IPFS repository is located in a different directory, adjust the `IPFS_PATH` environment variable accordingly.

- **Binary Location:** Verify that the `ExecStart` path points to the correct location of the `ipfs` binary. If you installed Kubo using a package manager, the path might differ.

By following these steps, Kubo will run as a systemd service, starting automatically at boot and running in the background. This setup ensures that your IPFS node is consistently available without manual intervention.

For more detailed information and advanced configurations, refer to the official IPFS Kubo documentation.


Failure

sudo systemctl status ipfs

× ipfs.service - IPFS Kubo Daemon

Loaded: loaded (/etc/systemd/system/ipfs.service; enabled; preset: enabled)

Active: failed (Result: exit-code) since Mon 2024-11-18 06:54:56 PST; 2min 2s ago

  Duration: 23ms
 
Invocation: 24269ca92d024f7eb7b0121abe011cf0

Process: 183936 ExecStart=/usr/local/bin/ipfs daemon –init –migrate (code=exited, status=203/EXEC)

Main PID: 183936 (code=exited, status=203/EXEC)

Nov 18 06:54:56 i9mini1 systemd[1]: ipfs.service: Scheduled restart job, restart counter is at 5. Nov 18 06:54:56 i9mini1 systemd[1]: ipfs.service: Start request repeated too quickly. Nov 18 06:54:56 i9mini1 systemd[1]: ipfs.service: Failed with result 'exit-code'. Nov 18 06:54:56 i9mini1 systemd[1]: Failed to start ipfs.service - IPFS Kubo Daemon.

The error indicates that the `ipfs.service` is failing to start because of an incorrect configuration in the systemd service file, specifically the `ExecStart` command.

Verify the Path to the IPFS Binary

Ensure that the path to the IPFS Kubo binary (`/usr/local/bin/ipfs`) in the service file is correct. Run the following command to confirm the binary location:

```bash which ipfs ```

This will display the correct path to the `ipfs` binary. If the path is different from `/usr/local/bin/ipfs`, let me know the output, and I’ll guide you on how to update the service file.

which ipfs

/usr/bin/ipfs

The issue is that the `ipfs.service` file references the incorrect binary path. Let’s update it to point to the correct location (`/usr/bin/ipfs`).

Update the Service File

Edit the service file to correct the `ExecStart` path:

```bash sudo nano /etc/systemd/system/ipfs.service ```

Find the line that starts with `ExecStart`

It was incorrect as ExecStart=/usr/bin/ipfs daemon –init –migrate

Update it to:

```bash ExecStart=/usr/bin/ipfs daemon –init –migrate ```

Save and exit the editor (`Ctrl+O`, `Enter`, `Ctrl+X`).

sudo systemctl start ipfs

Warning: The unit file, source configuration file or drop-ins of ipfs.service changed on disk. Run 'systemctl daemon-reload' to reload units.

  1. Step 7: Reload the Systemd Configuration

Reload the systemd configuration to apply the updated service file:

```bash sudo systemctl daemon-reload ```

sudo systemctl status ipfs

● ipfs.service - IPFS Kubo Daemon

Loaded: loaded (/etc/systemd/system/ipfs.service; enabled; preset: enabled)

Active: active (running) since Mon 2024-11-18 07:05:26 PST; 12s ago

Invocation: 1e2a929d3f98482b90248ef13f5a690d

Main PID: 184790 (ipfs)

Tasks: 25 (limit: 76593)

Memory: 46.7M (peak: 48M)

CPU: 2.394s

CGroup: /system.slice/ipfs.service

└─184790 /usr/bin/ipfs daemon –init –migrate

Nov 18 07:05:26 i9mini1 ipfs[184790]: 2024/11/18 07:05:26 failed to sufficiently increase receive buffer size>

Nov 18 07:05:26 i9mini1 ipfs[184790]: Swarm listening on 127.0.0.1:4001 (TCP+UDP)

Nov 18 07:05:26 i9mini1 ipfs[184790]: Swarm listening on 192.168.0.111:4001 (TCP+UDP)

Nov 18 07:05:26 i9mini1 ipfs[184790]: Swarm listening on 192.168.122.1:4001 (TCP+UDP)

Nov 18 07:05:26 i9mini1 ipfs[184790]: Swarm listening on [::1]:4001 (TCP+UDP)

Nov 18 07:05:26 i9mini1 ipfs[184790]: Run 'ipfs id' to inspect announced and discovered multiaddrs of this no>

Nov 18 07:05:26 i9mini1 ipfs[184790]: RPC API server listening on /ip4/127.0.0.1/tcp/5001

Nov 18 07:05:26 i9mini1 ipfs[184790]: WebUI: http://127.0.0.1:5001/webui

Nov 18 07:05:26 i9mini1 ipfs[184790]: Gateway server listening on /ip4/127.0.0.1/tcp/8080

Nov 18 07:05:26 i9mini1 ipfs[184790]: Daemon is ready

The IPFS Kubo daemon is now running successfully as a systemd service. Here’s what you can do next:

  1. Step 9: Verify Auto-Start on Reboot

To ensure the service starts automatically after a system reboot, reboot your machine:

```bash sudo reboot ```

Once the system is back up, check the status of the IPFS service:

```bash sudo systemctl status ipfs ```

Now let's solve this: Nov 18 07:05:26 i9mini1 ipfs[184790]: 2024/11/18 07:05:26 IPFS Kubo failed to sufficiently increase receive buffer size>

The error `failed to sufficiently increase receive buffer size` is related to IPFS Kubo attempting to increase the UDP buffer size for better UDP performance but being restricted by the system's configuration. Let’s resolve this step by step.

  1. Step 1: Verify Current Buffer Size

Run the following command to check your system's current UDP receive buffer limits:

```bash sysctl net.core.rmem_max

```

This will display the maximum size for the receive buffer.

The current value of `net.core.rmem_max` (212992 bytes, approximately 208 KB) is too low for IPFS Kubo, which recommends at least 7 MB (7168 KB). Let’s increase this limit.

Temporarily Increase the Buffer Size

To test the change temporarily, run the following command to set a higher buffer size:

```bash sudo sysctl -w net.core.rmem_max=8388608 ```

This command increases the buffer size to 8 MB (8388608 bytes). The change will last until the next reboot.

Restart the IPFS Service

Restart the IPFS service to see if the warning disappears:

```bash sudo systemctl restart ipfs sudo systemctl status ipfs ```

The warning about increasing the **send buffer size** still persists, which means the `net.core.wmem_max` value (for send buffer) also needs to be increased.

Temporarily Increase Send Buffer Size

Run the following command to temporarily increase the maximum send buffer size:

```bash sudo sysctl -w net.core.wmem_max=8388608 ```

This sets the maximum send buffer size to 8 MB, matching the receive buffer size we adjusted earlier.

Step 5: Restart the IPFS Service Again

After adjusting the send buffer size, restart the IPFS service to apply the changes:

```bash sudo systemctl restart ipfs sudo systemctl status ipfs ```

The IPFS service is now running without the buffer size warnings. This confirms the issue is resolved with the temporary adjustments.

Make Buffer Size Changes Permanent

To ensure the changes persist after a reboot, follow these steps:

1. Edit the `sysctl.conf` File:

Open the system configuration file:

```bash sudo nano /etc/sysctl.conf

  ```

2. **Add the Following Lines**:

Append these lines to the file to set the buffer sizes permanently:

```bash net.core.rmem_max=8388608 net.core.wmem_max=8388608 ```

3. Apply the Changes:

Reload the `sysctl` configuration to apply the new settings: ```bash sudo sysctl -p ```

Once you’ve completed these steps, the buffer size warnings should no longer appear, even after a reboot. Let me know if you’d like to verify the changes!

Now that the buffer size warnings are resolved and the changes are permanent, your IPFS Kubo setup is fully operational.

Final Verification

Let’s perform a quick verification to ensure everything is running smoothly:

1. Check the IPFS Service Status:

Confirm the service is active and running: ```bash sudo systemctl status ipfs

  ```

2. IPFS Verify Node Connectivity:

Check your node's connectivity to the IPFS network:

```bash ipfs swarm peers ``` This command should list IPFS connected peers, confirming your node is properly participating in the IPFS network.

3. Test File Access:

You can test file sharing again by adding a new file to `~/all/ipfs_shared`, adding it to IPFS, and verifying it via a public gateway.

If everything looks good, your node is fully configured and optimized for sharing files on IPFS.