Merge pull request #33372 from Mic92/memcache
nixos/memcached: make unix sockets usuable
This commit is contained in:
commit
f29ecd56c1
3 changed files with 38 additions and 25 deletions
|
@ -131,6 +131,14 @@ following incompatible changes:</para>
|
|||
Other types dependencies should be unaffected.
|
||||
</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>
|
||||
The <literal>memcached</literal> service no longer accept dynamic socket
|
||||
paths via <option>services.memcached.socket</option>. Unix sockets can be
|
||||
still enabled by <option>services.memcached.enableUnixSocket</option> and
|
||||
will be accessible at <literal>/run/memcached/memcached.sock</literal>.
|
||||
</para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
|
||||
</section>
|
||||
|
|
|
@ -197,7 +197,7 @@
|
|||
#input = 174; # unused
|
||||
sddm = 175;
|
||||
tss = 176;
|
||||
memcached = 177;
|
||||
#memcached = 177; removed 2018-01-03
|
||||
ntp = 179;
|
||||
zabbix = 180;
|
||||
#redis = 181; removed 2018-01-03
|
||||
|
@ -475,7 +475,7 @@
|
|||
input = 174;
|
||||
sddm = 175;
|
||||
tss = 176;
|
||||
#memcached = 177; # unused
|
||||
#memcached = 177; # unused, removed 2018-01-03
|
||||
#ntp = 179; # unused
|
||||
#zabbix = 180; # unused
|
||||
#redis = 181; # unused, removed 2018-01-03
|
||||
|
|
|
@ -40,11 +40,7 @@ in
|
|||
description = "The port to bind to";
|
||||
};
|
||||
|
||||
socket = mkOption {
|
||||
default = "";
|
||||
description = "Unix socket path to listen on. Setting this will disable network support";
|
||||
example = "/var/run/memcached";
|
||||
};
|
||||
enableUnixSocket = mkEnableOption "unix socket at /run/memcached/memcached.sock";
|
||||
|
||||
maxMemory = mkOption {
|
||||
default = 64;
|
||||
|
@ -68,31 +64,40 @@ in
|
|||
|
||||
config = mkIf config.services.memcached.enable {
|
||||
|
||||
users.extraUsers.memcached =
|
||||
{ name = cfg.user;
|
||||
uid = config.ids.uids.memcached;
|
||||
description = "Memcached server user";
|
||||
};
|
||||
users.extraUsers = optional (cfg.user == "memcached") {
|
||||
name = "memcached";
|
||||
description = "Memcached server user";
|
||||
};
|
||||
|
||||
environment.systemPackages = [ memcached ];
|
||||
|
||||
systemd.services.memcached =
|
||||
{ description = "Memcached server";
|
||||
systemd.services.memcached = {
|
||||
description = "Memcached server";
|
||||
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
after = [ "network.target" ];
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
after = [ "network.target" ];
|
||||
|
||||
serviceConfig = {
|
||||
ExecStart =
|
||||
let
|
||||
networking = if cfg.socket != ""
|
||||
then "-s ${cfg.socket}"
|
||||
else "-l ${cfg.listen} -p ${toString cfg.port}";
|
||||
in "${memcached}/bin/memcached ${networking} -m ${toString cfg.maxMemory} -c ${toString cfg.maxConnections} ${concatStringsSep " " cfg.extraOptions}";
|
||||
serviceConfig = {
|
||||
PermissionsStartOnly = true;
|
||||
ExecStartPre = optionals cfg.enableUnixSocket [
|
||||
"${pkgs.coreutils}/bin/install -d -o ${cfg.user} /run/memcached/"
|
||||
"${pkgs.coreutils}/bin/chown -R ${cfg.user} /run/memcached/"
|
||||
];
|
||||
ExecStart =
|
||||
let
|
||||
networking = if cfg.enableUnixSocket
|
||||
then "-s /run/memcached/memcached.sock"
|
||||
else "-l ${cfg.listen} -p ${toString cfg.port}";
|
||||
in "${memcached}/bin/memcached ${networking} -m ${toString cfg.maxMemory} -c ${toString cfg.maxConnections} ${concatStringsSep " " cfg.extraOptions}";
|
||||
|
||||
User = cfg.user;
|
||||
};
|
||||
User = cfg.user;
|
||||
};
|
||||
};
|
||||
};
|
||||
imports = [
|
||||
(mkRemovedOptionModule ["services" "memcached" "socket"] ''
|
||||
This option was replaced by a fixed unix socket path at /run/memcached/memcached.sock enabled using services.memached.enableUnixSocket.
|
||||
'')
|
||||
];
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue