Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: NixOS/nixpkgs
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0834e98ece64
Choose a base ref
...
head repository: NixOS/nixpkgs
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 2a2255409265
Choose a head ref
  • 1 commit
  • 1 file changed
  • 1 contributor

Commits on Dec 5, 2018

  1. nixos/cockroachdb: simplify dataDir management, tweaks

    This cleans up the CockroachDB expression, with a few suggestions from
    @aszlig.
    
    However, it brought up the note of using systemd's StateDirectory=
    directive, which is a nice feature for managing long-term data files,
    especially for UID/GID assigned services. However, it can only manage
    directories under /var/lib (for global services), so it has to introduce
    a special path to make use of it at all in the case someone wants a path
    at a different root.
    
    While the dataDir directive at the NixOS level is _occasionally_ useful,
    I've gone ahead and removed it for now, as this expression is so new,
    and it makes the expression cleaner, while other kinks can be worked out
    and people can test drive it.
    
    CockroachDB's dataDir directive, instead, has been replaced with
    systemd's StateDirectory management to place the data under
    /var/lib/cockroachdb for all uses.
    
    There's an included RequiresMountsFor= clause like usual though, so if
    people want dependencies for any kind of mounted device at boot
    time/before database startup, it's easy to specify using their own
    mount/filesystems clause.
    
    This can also be reverted if necessary, but, we can see if anyone ever
    actually wants that later on before doing it -- it's a backwards
    compatible change, anyway.
    
    Signed-off-by: Austin Seipp <aseipp@pobox.com>
    thoughtpolice committed Dec 5, 2018

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    marsam Mario Rodas
    Copy the full SHA
    2a22554 View commit details
Showing with 23 additions and 28 deletions.
  1. +23 −28 nixos/modules/services/databases/cockroachdb.nix
51 changes: 23 additions & 28 deletions nixos/modules/services/databases/cockroachdb.nix
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ let
[ # Basic startup
"${crdb}/bin/cockroach start"
"--logtostderr"
"--store=${cfg.dataDir}"
"--store=/var/lib/cockroachdb"
(ifNotNull cfg.locality "--locality='${cfg.locality}'")

# WebUI settings
@@ -41,7 +41,7 @@ let
};

port = mkOption {
type = types.int;
type = types.port;
default = defaultPort;
description = "Port to bind to for ${descr}";
};
@@ -70,10 +70,12 @@ in
like datacenter. The tiers and order must be the same on all nodes.
Including more tiers is better than including fewer. For example:
<literal>
country=us,region=us-west,datacenter=us-west-1b,rack=12
country=ca,region=ca-east,datacenter=ca-east-2,rack=4
planet=earth,province=manitoba,colo=secondary,power=3
</literal>
'';
};

@@ -83,12 +85,6 @@ in
description = "The addresses for connecting the node to a cluster.";
};

dataDir = mkOption {
type = types.path;
default = "/var/lib/cockroachdb";
description = "Location where CockroachDB stores its table files";
};

insecure = mkOption {
type = types.bool;
default = false;
@@ -126,9 +122,12 @@ in
The total size for caches.
This can be a percentage, expressed with a fraction sign or as a
decimal-point number, or any bytes-based unit. For example, "25%",
"0.25" both represent 25% of the available system memory. The values
"1000000000" and "1GB" both represent 1 gigabyte of memory.
decimal-point number, or any bytes-based unit. For example,
<literal>"25%"</literal>, <literal>"0.25"</literal> both represent
25% of the available system memory. The values
<literal>"1000000000"</literal> and <literal>"1GB"</literal> both
represent 1 gigabyte of memory.
'';
};

@@ -140,9 +139,11 @@ in
data for SQL queries.
This can be a percentage, expressed with a fraction sign or as a
decimal-point number, or any bytes-based unit. For example, "25%",
"0.25" both represent 25% of the available system memory. The values
"1000000000" and "1GB" both represent 1 gigabyte of memory.
decimal-point number, or any bytes-based unit. For example,
<literal>"25%"</literal>, <literal>"0.25"</literal> both represent
25% of the available system memory. The values
<literal>"1000000000"</literal> and <literal>"1GB"</literal> both
represent 1 gigabyte of memory.
'';
};

@@ -193,27 +194,21 @@ in
requires = [ "time-sync.target" ];
wantedBy = [ "multi-user.target" ];

unitConfig.RequiresMountsFor = "${cfg.dataDir}";

preStart = ''
if ! test -e ${cfg.dataDir}; then
mkdir -m 0700 -p ${cfg.dataDir}
chown -R ${cfg.user} ${cfg.dataDir}
fi
'';
unitConfig.RequiresMountsFor = "/var/lib/cockroachdb";

serviceConfig =
{ ExecStart = startupCommand;
Type = "notify";
User = cfg.user;
PermissionsStartOnly = true;
StateDirectory = "cockroachdb";
StateDirectoryMode = "0700";

Restart = "always";
TimeoutStopSec="60";
RestartSec="10";
StandardOutput="syslog";
StandardError="syslog";
SyslogIdentifier="cockroach";

# A conservative-ish timeout is alright here, because for Type=notify
# cockroach will send systemd pings during startup to keep it alive
TimeoutStopSec = 60;
RestartSec = 10;
};
};
};