2017-01-26 21:49:22 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
2017-05-13 02:07:04 +01:00
|
|
|
inherit (pkgs) glusterfs rsync;
|
2017-01-26 21:49:22 +00:00
|
|
|
|
2017-09-10 08:39:26 +01:00
|
|
|
tlsCmd = if (cfg.tlsSettings != null) then
|
|
|
|
''
|
|
|
|
mkdir -p /var/lib/glusterd
|
|
|
|
touch /var/lib/glusterd/secure-access
|
|
|
|
''
|
|
|
|
else
|
|
|
|
''
|
|
|
|
rm -f /var/lib/glusterd/secure-access
|
|
|
|
'';
|
|
|
|
|
|
|
|
restartTriggers = if (cfg.tlsSettings != null) then [
|
|
|
|
config.environment.etc."ssl/glusterfs.pem".source
|
|
|
|
config.environment.etc."ssl/glusterfs.key".source
|
|
|
|
config.environment.etc."ssl/glusterfs.ca".source
|
|
|
|
] else [];
|
|
|
|
|
2017-01-26 21:49:22 +00:00
|
|
|
cfg = config.services.glusterfs;
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.glusterfs = {
|
|
|
|
|
|
|
|
enable = mkEnableOption "GlusterFS Daemon";
|
|
|
|
|
|
|
|
logLevel = mkOption {
|
|
|
|
type = types.enum ["DEBUG" "INFO" "WARNING" "ERROR" "CRITICAL" "TRACE" "NONE"];
|
|
|
|
description = "Log level used by the GlusterFS daemon";
|
|
|
|
default = "INFO";
|
|
|
|
};
|
|
|
|
|
|
|
|
extraFlags = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
description = "Extra flags passed to the GlusterFS daemon";
|
|
|
|
default = [];
|
|
|
|
};
|
2017-09-10 08:39:26 +01:00
|
|
|
|
|
|
|
tlsSettings = mkOption {
|
|
|
|
description = ''
|
|
|
|
Make the server communicate via TLS.
|
|
|
|
This means it will only connect to other gluster
|
|
|
|
servers having certificates signed by the same CA.
|
|
|
|
|
|
|
|
Enabling this will create a file <filename>/var/lib/glusterd/secure-access</filename>.
|
|
|
|
Disabling will delete this file again.
|
|
|
|
|
|
|
|
See also: https://gluster.readthedocs.io/en/latest/Administrator%20Guide/SSL/
|
|
|
|
'';
|
|
|
|
default = null;
|
|
|
|
type = types.nullOr (types.submodule {
|
|
|
|
options = {
|
|
|
|
tlsKey = mkOption {
|
|
|
|
default = null;
|
|
|
|
type = types.path;
|
|
|
|
description = "Path to the private key used for TLS.";
|
|
|
|
};
|
|
|
|
|
|
|
|
tlsPem = mkOption {
|
|
|
|
default = null;
|
|
|
|
type = types.path;
|
|
|
|
description = "Path to the certificate used for TLS.";
|
|
|
|
};
|
|
|
|
|
|
|
|
caCert = mkOption {
|
|
|
|
default = null;
|
|
|
|
type = types.path;
|
|
|
|
description = "Path certificate authority used to sign the cluster certificates.";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
};
|
2017-01-26 21:49:22 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
environment.systemPackages = [ pkgs.glusterfs ];
|
|
|
|
|
|
|
|
services.rpcbind.enable = true;
|
|
|
|
|
2017-09-10 08:39:26 +01:00
|
|
|
environment.etc = mkIf (cfg.tlsSettings != null) {
|
|
|
|
"ssl/glusterfs.pem".source = cfg.tlsSettings.tlsPem;
|
|
|
|
"ssl/glusterfs.key".source = cfg.tlsSettings.tlsKey;
|
|
|
|
"ssl/glusterfs.ca".source = cfg.tlsSettings.caCert;
|
|
|
|
};
|
|
|
|
|
2017-01-26 21:49:22 +00:00
|
|
|
systemd.services.glusterd = {
|
2017-09-10 08:39:26 +01:00
|
|
|
inherit restartTriggers;
|
2017-01-26 21:49:22 +00:00
|
|
|
|
|
|
|
description = "GlusterFS, a clustered file-system server";
|
|
|
|
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
requires = [ "rpcbind.service" ];
|
|
|
|
after = [ "rpcbind.service" "network.target" "local-fs.target" ];
|
|
|
|
before = [ "network-online.target" ];
|
|
|
|
|
|
|
|
preStart = ''
|
|
|
|
install -m 0755 -d /var/log/glusterfs
|
2017-09-07 09:35:00 +01:00
|
|
|
''
|
|
|
|
# The copying of hooks is due to upstream bug https://bugzilla.redhat.com/show_bug.cgi?id=1452761
|
|
|
|
+ ''
|
2017-05-13 02:07:04 +01:00
|
|
|
mkdir -p /var/lib/glusterd/hooks/
|
|
|
|
${rsync}/bin/rsync -a ${glusterfs}/var/lib/glusterd/hooks/ /var/lib/glusterd/hooks/
|
2017-09-10 08:39:26 +01:00
|
|
|
|
|
|
|
${tlsCmd}
|
2017-09-07 09:35:00 +01:00
|
|
|
''
|
|
|
|
# `glusterfind` needs dirs that upstream installs at `make install` phase
|
|
|
|
# https://github.com/gluster/glusterfs/blob/v3.10.2/tools/glusterfind/Makefile.am#L16-L17
|
|
|
|
+ ''
|
|
|
|
mkdir -p /var/lib/glusterd/glusterfind/.keys
|
|
|
|
mkdir -p /var/lib/glusterd/hooks/1/delete/post/
|
2017-01-26 21:49:22 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
Type="forking";
|
|
|
|
PIDFile="/run/glusterd.pid";
|
|
|
|
LimitNOFILE=65536;
|
|
|
|
ExecStart="${glusterfs}/sbin/glusterd -p /run/glusterd.pid --log-level=${cfg.logLevel} ${toString cfg.extraFlags}";
|
|
|
|
KillMode="process";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.glustereventsd = {
|
2017-09-10 08:39:26 +01:00
|
|
|
inherit restartTriggers;
|
2017-01-26 21:49:22 +00:00
|
|
|
|
|
|
|
description = "Gluster Events Notifier";
|
|
|
|
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
after = [ "syslog.target" "network.target" ];
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
Type="simple";
|
|
|
|
Environment="PYTHONPATH=${glusterfs}/usr/lib/python2.7/site-packages";
|
|
|
|
PIDFile="/run/glustereventsd.pid";
|
|
|
|
ExecStart="${glusterfs}/sbin/glustereventsd --pid-file /run/glustereventsd.pid";
|
|
|
|
ExecReload="/bin/kill -SIGUSR2 $MAINPID";
|
|
|
|
KillMode="control-group";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|