Merge pull request #22180 from mguentner/offline_ipfs

services: ipfs: separate system units, add offline mode
This commit is contained in:
Franz Pletz 2017-02-01 03:41:31 +01:00 committed by GitHub
commit f96c3f1844

View File

@ -104,30 +104,72 @@ in
};
};
systemd.services.ipfs = {
description = "IPFS Daemon";
systemd.services.ipfs-init = {
description = "IPFS Initializer";
after = [ "local-fs.target" ];
before = [ "ipfs.service" "ipfs-offline.service" ];
wantedBy = [ "multi-user.target" ];
after = [ "network.target" "local-fs.target" ];
path = [ pkgs.ipfs pkgs.su pkgs.bash ];
preStart = ''
install -m 0755 -o ${cfg.user} -g ${cfg.group} -d ${cfg.dataDir}
'';
script = ''
if [[ ! -d ${cfg.dataDir}/.ipfs ]]; then
cd ${cfg.dataDir}
${pkgs.su}/bin/su -s ${pkgs.bash}/bin/sh ${cfg.user} -c \
"${ipfs}/bin/ipfs init ${if cfg.emptyRepo then "-e" else ""}"
${ipfs}/bin/ipfs init ${optionalString cfg.emptyRepo "-e"}
fi
${pkgs.su}/bin/su -s ${pkgs.bash}/bin/sh ${cfg.user} -c \
"${ipfs}/bin/ipfs --local config Addresses.API ${cfg.apiAddress} && \
${ipfs}/bin/ipfs --local config Addresses.Gateway ${cfg.gatewayAddress}"
${ipfs}/bin/ipfs --local config Addresses.API ${cfg.apiAddress}
${ipfs}/bin/ipfs --local config Addresses.Gateway ${cfg.gatewayAddress}
'';
serviceConfig = {
User = cfg.user;
Group = cfg.group;
Type = "oneshot";
RemainAfterExit = true;
PermissionsStartOnly = true;
};
};
systemd.services.ipfs = {
description = "IPFS Daemon";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" "local-fs.target" "ipfs-init.service" ];
conflicts = [ "ipfs-offline.service" ];
wants = [ "ipfs-init.service" ];
path = [ pkgs.ipfs ];
serviceConfig = {
ExecStart = "${ipfs}/bin/ipfs daemon ${ipfsFlags}";
User = cfg.user;
Group = cfg.group;
PermissionsStartOnly = true;
Restart = "on-failure";
RestartSec = 1;
};
};
systemd.services.ipfs-offline = {
description = "IPFS Daemon (offline mode)";
after = [ "local-fs.target" "ipfs-init.service" ];
conflicts = [ "ipfs.service" ];
wants = [ "ipfs-init.service" ];
path = [ pkgs.ipfs ];
serviceConfig = {
ExecStart = "${ipfs}/bin/ipfs daemon ${ipfsFlags} --offline";
User = cfg.user;
Group = cfg.group;
Restart = "on-failure";
RestartSec = 1;
};
};
};