-
-
Notifications
You must be signed in to change notification settings - Fork 14.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nixosModules.seaweedfs: Add Seaweedfs Module
- Loading branch information
1 parent
4aa3656
commit ebed001
Showing
1 changed file
with
278 additions
and
0 deletions.
There are no files selected for viewing
278 changes: 278 additions & 0 deletions
278
nixos/modules/services/network-filesystems/seaweedfs.nix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,278 @@ | ||
{ | ||
config, | ||
lib, | ||
pkgs, | ||
... | ||
}: | ||
|
||
let | ||
cfg = config.services.seaweedfs; | ||
baseDir = "/var/lib/seaweedfs"; | ||
in | ||
{ | ||
options.services.seaweedfs = { | ||
package = lib.mkOption { | ||
type = lib.types.package; | ||
default = pkgs.seaweedfs; | ||
defaultText = lib.literalExpression "pkgs.seaweedfs"; | ||
description = "The SeaweedFS package to use."; | ||
}; | ||
|
||
master = { | ||
enable = lib.mkEnableOption "SeaweedFS master server"; | ||
|
||
port = lib.mkOption { | ||
type = lib.types.port; | ||
default = 9333; | ||
description = "Port for master server."; | ||
}; | ||
|
||
ip = lib.mkOption { | ||
type = lib.types.str; | ||
description = "IP address to bind to."; | ||
}; | ||
|
||
ipBind = lib.mkOption { | ||
type = lib.types.str; | ||
default = ""; | ||
description = "IP address to bind to. If empty, defaults to same as ip."; | ||
}; | ||
|
||
dataDir = lib.mkOption { | ||
type = lib.types.str; | ||
default = "${baseDir}/master"; | ||
description = "Data directory for master."; | ||
}; | ||
|
||
peers = lib.mkOption { | ||
type = lib.types.listOf lib.types.str; | ||
default = [ ]; | ||
example = [ | ||
"192.168.1.10:9333" | ||
"192.168.1.11:9333" | ||
]; | ||
description = "List of master peers for clustering."; | ||
}; | ||
|
||
volumeSizeLimitMB = lib.mkOption { | ||
type = lib.types.int; | ||
default = 1024; | ||
description = "Volume size limit in MB."; | ||
}; | ||
}; | ||
|
||
volume = { | ||
enable = lib.mkEnableOption "SeaweedFS volume server"; | ||
|
||
port = lib.mkOption { | ||
type = lib.types.port; | ||
default = 8080; | ||
description = "Port for volume server."; | ||
}; | ||
|
||
ip = lib.mkOption { | ||
type = lib.types.str; | ||
description = "IP address to bind to."; | ||
}; | ||
|
||
ipBind = lib.mkOption { | ||
type = lib.types.str; | ||
default = ""; | ||
description = "IP address to bind to. If empty, defaults to same as ip."; | ||
}; | ||
|
||
dataDir = lib.mkOption { | ||
type = lib.types.str; | ||
default = "${baseDir}/volume"; | ||
description = "Data directory for volume."; | ||
}; | ||
|
||
master = lib.mkOption { | ||
type = lib.types.str; | ||
description = "Master server address (e.g., localhost:9333)."; | ||
}; | ||
|
||
maxVolumes = lib.mkOption { | ||
type = lib.types.int; | ||
default = 7; | ||
description = "Maximum number of volumes."; | ||
}; | ||
}; | ||
|
||
filer = { | ||
enable = lib.mkEnableOption "SeaweedFS filer server"; | ||
|
||
port = lib.mkOption { | ||
type = lib.types.port; | ||
default = 8888; | ||
description = "Port for filer server."; | ||
}; | ||
|
||
ip = lib.mkOption { | ||
type = lib.types.str; | ||
description = "IP address to bind to."; | ||
}; | ||
|
||
ipBind = lib.mkOption { | ||
type = lib.types.str; | ||
default = ""; | ||
description = "IP address to bind to. If empty, defaults to same as ip."; | ||
}; | ||
|
||
dataDir = lib.mkOption { | ||
type = lib.types.str; | ||
default = "${baseDir}/filer"; | ||
description = "Data directory for filer."; | ||
}; | ||
|
||
master = lib.mkOption { | ||
type = lib.types.str; | ||
description = "Master server address (e.g., localhost:9333)."; | ||
}; | ||
|
||
maxMB = lib.mkOption { | ||
type = lib.types.int; | ||
default = 4; | ||
description = "Split files larger than the limit."; | ||
}; | ||
}; | ||
}; | ||
|
||
config = lib.mkMerge [ | ||
(lib.mkIf (cfg.master.enable || cfg.volume.enable || cfg.filer.enable) { | ||
users.users.seaweedfs = { | ||
isSystemUser = true; | ||
group = "seaweedfs"; | ||
home = baseDir; | ||
createHome = true; | ||
}; | ||
|
||
users.groups.seaweedfs = { }; | ||
|
||
systemd.tmpfiles.rules = [ | ||
"d ${baseDir} 0755 seaweedfs seaweedfs -" | ||
"d ${cfg.master.dataDir} 0755 seaweedfs seaweedfs -" | ||
"d ${cfg.volume.dataDir} 0755 seaweedfs seaweedfs -" | ||
"d ${cfg.filer.dataDir} 0755 seaweedfs seaweedfs -" | ||
]; | ||
}) | ||
|
||
(lib.mkIf cfg.master.enable { | ||
systemd.services.seaweedfs-master = { | ||
description = "SeaweedFS Master Server"; | ||
after = [ "network-online.target" ]; | ||
wants = [ "network-online.target" ]; | ||
wantedBy = [ "multi-user.target" ]; | ||
|
||
preStart = '' | ||
mkdir -p ${cfg.master.dataDir} | ||
chown -R seaweedfs:seaweedfs ${cfg.master.dataDir} | ||
chmod -R 755 ${cfg.master.dataDir} | ||
''; | ||
|
||
serviceConfig = { | ||
ExecStart = '' | ||
${cfg.package}/bin/weed master \ | ||
-port=${toString cfg.master.port} \ | ||
-ip=${cfg.master.ip} \ | ||
${lib.optionalString (cfg.master.ipBind != "") "-ip.bind=${cfg.master.ipBind}"} \ | ||
-mdir=${cfg.master.dataDir} \ | ||
-volumeSizeLimitMB=${toString cfg.master.volumeSizeLimitMB} \ | ||
${ | ||
lib.optionalString (cfg.master.peers != [ ]) "-peers=${lib.concatStringsSep "," cfg.master.peers}" | ||
} | ||
''; | ||
User = "seaweedfs"; | ||
Group = "seaweedfs"; | ||
StateDirectory = "seaweedfs"; | ||
RuntimeDirectory = "seaweedfs"; | ||
Restart = "always"; | ||
RestartSec = "10s"; | ||
WorkingDirectory = "${cfg.master.dataDir}"; | ||
LimitNOFILE = 65535; | ||
AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ]; | ||
}; | ||
}; | ||
}) | ||
|
||
(lib.mkIf cfg.volume.enable { | ||
systemd.services.seaweedfs-volume = { | ||
description = "SeaweedFS Volume Server"; | ||
after = [ | ||
"network-online.target" | ||
"seaweedfs-master.service" | ||
]; | ||
wants = [ "network-online.target" ]; | ||
requires = [ "seaweedfs-master.service" ]; | ||
wantedBy = [ "multi-user.target" ]; | ||
|
||
preStart = '' | ||
mkdir -p ${cfg.volume.dataDir} | ||
chown -R seaweedfs:seaweedfs ${cfg.volume.dataDir} | ||
chmod -R 755 ${cfg.volume.dataDir} | ||
''; | ||
|
||
serviceConfig = { | ||
ExecStart = '' | ||
${cfg.package}/bin/weed volume \ | ||
-port=${toString cfg.volume.port} \ | ||
-ip=${cfg.volume.ip} \ | ||
${lib.optionalString (cfg.volume.ipBind != "") "-ip.bind=${cfg.volume.ipBind}"} \ | ||
-dir=${cfg.volume.dataDir} \ | ||
-mserver=${cfg.volume.master} \ | ||
-max=${toString cfg.volume.maxVolumes} | ||
''; | ||
User = "seaweedfs"; | ||
Group = "seaweedfs"; | ||
StateDirectory = "seaweedfs"; | ||
RuntimeDirectory = "seaweedfs"; | ||
Restart = "always"; | ||
RestartSec = "10s"; | ||
WorkingDirectory = "${cfg.volume.dataDir}"; | ||
LimitNOFILE = 65535; | ||
AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ]; | ||
}; | ||
}; | ||
}) | ||
|
||
(lib.mkIf cfg.filer.enable { | ||
systemd.services.seaweedfs-filer = { | ||
description = "SeaweedFS Filer Server"; | ||
after = [ | ||
"network-online.target" | ||
"seaweedfs-master.service" | ||
]; | ||
wants = [ "network-online.target" ]; | ||
requires = [ "seaweedfs-master.service" ]; | ||
wantedBy = [ "multi-user.target" ]; | ||
|
||
preStart = '' | ||
mkdir -p ${cfg.filer.dataDir} | ||
chown -R seaweedfs:seaweedfs ${cfg.filer.dataDir} | ||
chmod -R 755 ${cfg.filer.dataDir} | ||
''; | ||
|
||
serviceConfig = { | ||
ExecStart = '' | ||
${cfg.package}/bin/weed filer \ | ||
-port=${toString cfg.filer.port} \ | ||
-ip=${cfg.filer.ip} \ | ||
${lib.optionalString (cfg.filer.ipBind != "") "-ip.bind=${cfg.filer.ipBind}"} \ | ||
-master=${cfg.filer.master} \ | ||
-defaultStoreDir=${cfg.filer.dataDir} \ | ||
-maxMB=${toString cfg.filer.maxMB} | ||
''; | ||
User = "seaweedfs"; | ||
Group = "seaweedfs"; | ||
StateDirectory = "seaweedfs"; | ||
RuntimeDirectory = "seaweedfs"; | ||
Restart = "always"; | ||
RestartSec = "10s"; | ||
WorkingDirectory = "${cfg.filer.dataDir}"; | ||
LimitNOFILE = 65535; | ||
AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ]; | ||
}; | ||
}; | ||
}) | ||
]; | ||
} |