Skip to content

Commit

Permalink
Start stop ipfs package when repo is changed
Browse files Browse the repository at this point in the history
  • Loading branch information
3alpha committed Aug 13, 2024
1 parent bafd376 commit 47e89c8
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/dappmanager/src/calls/ipfsClientTargetSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { IpfsRepository, IpfsClientTarget } from "@dappnode/types";
import { params } from "@dappnode/params";
import * as db from "@dappnode/db";
import { dappnodeInstaller } from "../index.js";
import { dockerContainerStart, dockerContainerStop, listPackageNoThrow } from "@dappnode/dockerapi";
import { packageInstall } from "./packageInstall.js";

/**
* Changes the IPFS client
Expand Down Expand Up @@ -37,16 +39,34 @@ async function changeIpfsClient(
const currentGateway = db.ipfsGateway.get();
if (currentTarget === nextTarget && currentGateway === nextGateway) return;

const ipfsPackage = await listPackageNoThrow({
dnpName: "ipfs.dnp.dappnode.eth"
});

if (nextTarget === IpfsClientTarget.local) {
db.ipfsClientTarget.set(IpfsClientTarget.local);
dappnodeInstaller.changeIpfsProvider(params.IPFS_LOCAL);
if(!ipfsPackage) { // Should never run as IPFS is core
packageInstall({name: "ipfs.dnp.dappnode.eth"})
}
else {
for (const container of ipfsPackage.containers)
if (!container.running)
await dockerContainerStart(container.containerName);
}
} else {
// Set new values in db
db.ipfsGateway.set(nextGateway || params.IPFS_GATEWAY);
db.ipfsClientTarget.set(IpfsClientTarget.remote);

// Change IPFS host
dappnodeInstaller.changeIpfsProvider(db.ipfsGateway.get());

if(ipfsPackage) {
for (const container of ipfsPackage.containers)
if (container.running)
await dockerContainerStop(container.containerName);
}
}
} catch (e) {
throw Error(`Error changing ipfs client to ${nextTarget}, ${e}`);
Expand Down

0 comments on commit 47e89c8

Please sign in to comment.