at 25.11-pre 3.7 kB view raw
1{ 2 config, 3 lib, 4 pkgs, 5 ... 6}: 7let 8 9 cfg = config.services.aerospike; 10 11 aerospikeConf = pkgs.writeText "aerospike.conf" '' 12 # This stanza must come first. 13 service { 14 user aerospike 15 group aerospike 16 paxos-single-replica-limit 1 # Number of nodes where the replica count is automatically reduced to 1. 17 proto-fd-max 15000 18 work-directory ${cfg.workDir} 19 } 20 logging { 21 console { 22 context any info 23 } 24 } 25 mod-lua { 26 system-path ${cfg.package}/share/udf/lua 27 user-path ${cfg.workDir}/udf/lua 28 } 29 network { 30 ${cfg.networkConfig} 31 } 32 ${cfg.extraConfig} 33 ''; 34 35in 36 37{ 38 39 ###### interface 40 41 options = { 42 43 services.aerospike = { 44 enable = lib.mkEnableOption "Aerospike server"; 45 46 package = lib.mkPackageOption pkgs "aerospike" { }; 47 48 workDir = lib.mkOption { 49 type = lib.types.str; 50 default = "/var/lib/aerospike"; 51 description = "Location where Aerospike stores its files"; 52 }; 53 54 networkConfig = lib.mkOption { 55 type = lib.types.lines; 56 default = '' 57 service { 58 address any 59 port 3000 60 } 61 62 heartbeat { 63 address any 64 mode mesh 65 port 3002 66 interval 150 67 timeout 10 68 } 69 70 fabric { 71 address any 72 port 3001 73 } 74 75 info { 76 address any 77 port 3003 78 } 79 ''; 80 description = "network section of configuration file"; 81 }; 82 83 extraConfig = lib.mkOption { 84 type = lib.types.lines; 85 default = ""; 86 example = '' 87 namespace test { 88 replication-factor 2 89 memory-size 4G 90 default-ttl 30d 91 storage-engine memory 92 } 93 ''; 94 description = "Extra configuration"; 95 }; 96 }; 97 98 }; 99 100 ###### implementation 101 102 config = lib.mkIf config.services.aerospike.enable { 103 104 users.users.aerospike = { 105 name = "aerospike"; 106 group = "aerospike"; 107 uid = config.ids.uids.aerospike; 108 description = "Aerospike server user"; 109 }; 110 users.groups.aerospike.gid = config.ids.gids.aerospike; 111 112 boot.kernel.sysctl = { 113 "net.core.rmem_max" = lib.mkDefault 15728640; 114 "net.core.wmem_max" = lib.mkDefault 5242880; 115 }; 116 117 systemd.services.aerospike = rec { 118 description = "Aerospike server"; 119 120 wantedBy = [ "multi-user.target" ]; 121 after = [ "network.target" ]; 122 123 serviceConfig = { 124 ExecStart = "${cfg.package}/bin/asd --fgdaemon --config-file ${aerospikeConf}"; 125 User = "aerospike"; 126 Group = "aerospike"; 127 LimitNOFILE = 100000; 128 PermissionsStartOnly = true; 129 }; 130 131 preStart = '' 132 if [ $(echo "$(${pkgs.procps}/bin/sysctl -n kernel.shmall) < 4294967296" | ${pkgs.bc}/bin/bc) == "1" ]; then 133 echo "kernel.shmall too low, setting to 4G pages" 134 ${pkgs.procps}/bin/sysctl -w kernel.shmall=4294967296 135 fi 136 if [ $(echo "$(${pkgs.procps}/bin/sysctl -n kernel.shmmax) < 1073741824" | ${pkgs.bc}/bin/bc) == "1" ]; then 137 echo "kernel.shmmax too low, setting to 1GB" 138 ${pkgs.procps}/bin/sysctl -w kernel.shmmax=1073741824 139 fi 140 install -d -m0700 -o ${serviceConfig.User} -g ${serviceConfig.Group} "${cfg.workDir}" 141 install -d -m0700 -o ${serviceConfig.User} -g ${serviceConfig.Group} "${cfg.workDir}/smd" 142 install -d -m0700 -o ${serviceConfig.User} -g ${serviceConfig.Group} "${cfg.workDir}/udf" 143 install -d -m0700 -o ${serviceConfig.User} -g ${serviceConfig.Group} "${cfg.workDir}/udf/lua" 144 ''; 145 }; 146 147 }; 148 149}