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