1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 inherit (pkgs) glusterfs rsync; 7 8 cfg = config.services.glusterfs; 9 10in 11 12{ 13 14 ###### interface 15 16 options = { 17 18 services.glusterfs = { 19 20 enable = mkEnableOption "GlusterFS Daemon"; 21 22 logLevel = mkOption { 23 type = types.enum ["DEBUG" "INFO" "WARNING" "ERROR" "CRITICAL" "TRACE" "NONE"]; 24 description = "Log level used by the GlusterFS daemon"; 25 default = "INFO"; 26 }; 27 28 extraFlags = mkOption { 29 type = types.listOf types.str; 30 description = "Extra flags passed to the GlusterFS daemon"; 31 default = []; 32 }; 33 }; 34 }; 35 36 ###### implementation 37 38 config = mkIf cfg.enable { 39 environment.systemPackages = [ pkgs.glusterfs ]; 40 41 services.rpcbind.enable = true; 42 43 systemd.services.glusterd = { 44 45 description = "GlusterFS, a clustered file-system server"; 46 47 wantedBy = [ "multi-user.target" ]; 48 49 requires = [ "rpcbind.service" ]; 50 after = [ "rpcbind.service" "network.target" "local-fs.target" ]; 51 before = [ "network-online.target" ]; 52 53 # The copying of hooks is due to upstream bug https://bugzilla.redhat.com/show_bug.cgi?id=1452761 54 preStart = '' 55 install -m 0755 -d /var/log/glusterfs 56 mkdir -p /var/lib/glusterd/hooks/ 57 ${rsync}/bin/rsync -a ${glusterfs}/var/lib/glusterd/hooks/ /var/lib/glusterd/hooks/ 58 ''; 59 60 serviceConfig = { 61 Type="forking"; 62 PIDFile="/run/glusterd.pid"; 63 LimitNOFILE=65536; 64 ExecStart="${glusterfs}/sbin/glusterd -p /run/glusterd.pid --log-level=${cfg.logLevel} ${toString cfg.extraFlags}"; 65 KillMode="process"; 66 }; 67 }; 68 69 systemd.services.glustereventsd = { 70 71 description = "Gluster Events Notifier"; 72 73 wantedBy = [ "multi-user.target" ]; 74 75 after = [ "syslog.target" "network.target" ]; 76 77 serviceConfig = { 78 Type="simple"; 79 Environment="PYTHONPATH=${glusterfs}/usr/lib/python2.7/site-packages"; 80 PIDFile="/run/glustereventsd.pid"; 81 ExecStart="${glusterfs}/sbin/glustereventsd --pid-file /run/glustereventsd.pid"; 82 ExecReload="/bin/kill -SIGUSR2 $MAINPID"; 83 KillMode="control-group"; 84 }; 85 }; 86 }; 87}