Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "refactor: consolidate all settings in defaultProcessSettings (#348)" #379

Merged
merged 3 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions nix/lib.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,6 @@
'';
default = {
namespace = lib.mkDefault config.namespace;
# https://github.com/F1bonacc1/process-compose#-auto-restart-if-not-healthy
availability = {
restart = lib.mkDefault "on_failure";
max_restarts = lib.mkDefault 5;
};
readiness_probe = {
initial_delay_seconds = lib.mkDefault 2;
period_seconds = lib.mkDefault 10;
timeout_seconds = lib.mkDefault 4;
success_threshold = lib.mkDefault 1;
failure_threshold = lib.mkDefault 5;
};
};
};
settings = lib.mkOption {
Expand Down
5 changes: 5 additions & 0 deletions nix/services/apache-kafka.nix
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ with lib;
readiness_probe = {
# TODO: need to find a better way to check if kafka is ready. Maybe use one of the scripts in bin?
exec.command = "${pkgs.netcat.nc}/bin/nc -z localhost ${builtins.toString config.port}";
initial_delay_seconds = 2;
period_seconds = 10;
timeout_seconds = 4;
success_threshold = 1;
failure_threshold = 5;
};

availability = {
Expand Down
10 changes: 10 additions & 0 deletions nix/services/cassandra.nix
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,18 @@ in
exec.command = ''
echo 'show version;' | CQLSH_HOST=${config.listenAddress} CQLSH_PORT=${toString config.nativeTransportPort} ${config.package}/bin/cqlsh
'';
initial_delay_seconds = 2;
period_seconds = 10;
timeout_seconds = 4;
success_threshold = 1;
failure_threshold = 5;
};

# https://github.com/F1bonacc1/process-compose#-auto-restart-if-not-healthy
availability = {
restart = "on_failure";
max_restarts = 5;
};
};
};
};
Expand Down
10 changes: 10 additions & 0 deletions nix/services/clickhouse/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,18 @@ in
host = "localhost";
port = if (lib.hasAttr "http_port" config.extraConfig) then config.extraConfig.http_port else 8123;
};
initial_delay_seconds = 2;
period_seconds = 10;
timeout_seconds = 4;
success_threshold = 1;
failure_threshold = 5;
};
depends_on."${name}-init".condition = "process_completed_successfully";
# https://github.com/F1bonacc1/process-compose#-auto-restart-if-not-healthy
availability = {
restart = "on_failure";
max_restarts = 5;
};
};
};
};
Expand Down
8 changes: 8 additions & 0 deletions nix/services/elasticsearch.nix
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,17 @@ in
readiness_probe = {
exec.command = "${pkgs.curl}/bin/curl -f -k http://${config.listenAddress}:${toString config.port}";
initial_delay_seconds = 15;
period_seconds = 10;
timeout_seconds = 2;
success_threshold = 1;
failure_threshold = 5;
};

# https://github.com/F1bonacc1/process-compose#-auto-restart-if-not-healthy
availability = {
restart = "on_failure";
max_restarts = 5;
};
};
};
};
Expand Down
8 changes: 8 additions & 0 deletions nix/services/grafana.nix
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,17 @@ in
path = "/api/health";
};
initial_delay_seconds = 15;
period_seconds = 10;
timeout_seconds = 2;
success_threshold = 1;
failure_threshold = 5;
};

# https://github.com/F1bonacc1/process-compose#-auto-restart-if-not-healthy
availability = {
restart = "on_failure";
max_restarts = 5;
};
};
};
};
Expand Down
5 changes: 5 additions & 0 deletions nix/services/memcached.nix
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ in
exec.command = ''
echo -e "stats\nquit" | ${pkgs.netcat}/bin/nc ${config.bind} ${toString config.port} > /dev/null 2>&1
'';
initial_delay_seconds = 2;
period_seconds = 10;
timeout_seconds = 4;
success_threshold = 1;
failure_threshold = 5;
};

# https://github.com/F1bonacc1/process-compose#-auto-restart-if-not-healthy
Expand Down
10 changes: 10 additions & 0 deletions nix/services/mysql/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,18 @@ in
# Turns out using `--defaults-file` alone doesn't make the readiness_probe work unless `MYSQL_UNIX_PORT` is set.
# Hence the use of `--socket`.
exec.command = "${config.package}/bin/mysqladmin --socket=${config.socketDir}/mysql.sock ping -h localhost";
initial_delay_seconds = 2;
period_seconds = 10;
timeout_seconds = 4;
success_threshold = 1;
failure_threshold = 5;
};

# https://github.com/F1bonacc1/process-compose#-auto-restart-if-not-healthy
availability = {
restart = "on_failure";
max_restarts = 5;
};
};
"${name}-configure" = {
command = configureScript;
Expand Down
10 changes: 10 additions & 0 deletions nix/services/nginx/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ in
readiness_probe = {
# FIXME need a better health check
exec.command = "[ -e ${config.dataDir}/nginx/nginx.pid ]";
initial_delay_seconds = 2;
period_seconds = 10;
timeout_seconds = 4;
success_threshold = 1;
failure_threshold = 5;
};
# https://github.com/F1bonacc1/process-compose#-auto-restart-if-not-healthy
availability = {
restart = "on_failure";
max_restarts = 5;
};
};
};
Expand Down
5 changes: 5 additions & 0 deletions nix/services/ollama.nix
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ in
host = config.host;
port = config.port;
};
initial_delay_seconds = 2;
period_seconds = 10;
timeout_seconds = 4;
success_threshold = 1;
failure_threshold = 5;
};
availability = {
restart = "on_failure";
Expand Down
5 changes: 5 additions & 0 deletions nix/services/open-webui.nix
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ in
host = config.host;
port = config.port;
};
initial_delay_seconds = 2;
period_seconds = 10;
timeout_seconds = 4;
success_threshold = 1;
failure_threshold = 5;
};
availability = {
restart = "on_failure";
Expand Down
10 changes: 10 additions & 0 deletions nix/services/pgadmin.nix
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,18 @@ in
port = config.port;
path = "/misc/ping";
};
initial_delay_seconds = 2;
period_seconds = 10;
timeout_seconds = 4;
success_threshold = 1;
failure_threshold = 5;
};
depends_on."${name}-init".condition = "process_completed_successfully";
# https://github.com/F1bonacc1/process-compose#-auto-restart-if-not-healthy
availability = {
restart = "on_failure";
max_restarts = 5;
};
};
};
};
Expand Down
3 changes: 3 additions & 0 deletions nix/services/postgres/bad_test.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- Tests if the postgres process gets skipped when there is an error while setting up inital databases
CREATE STABLE users (id INT PRIMARY KEY, user_name VARCHAR(25));

10 changes: 10 additions & 0 deletions nix/services/postgres/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,18 @@ in
shutdown.signal = 2;
readiness_probe = {
exec.command = "${config.package}/bin/pg_isready ${lib.concatStringsSep " " pg_isreadyArgs}";
initial_delay_seconds = 2;
period_seconds = 10;
timeout_seconds = 4;
success_threshold = 1;
failure_threshold = 5;
};
depends_on."${name}-init".condition = "process_completed_successfully";
# https://github.com/F1bonacc1/process-compose#-auto-restart-if-not-healthy
availability = {
restart = "on_failure";
max_restarts = 5;
};
};
};
};
Expand Down
29 changes: 26 additions & 3 deletions nix/services/postgres/postgres_test.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs, config, ... }: {
{ pkgs, config, name, ... }: {
services.postgres."pg1" = {
enable = true;
initialScript.before = "CREATE USER bar;";
Expand Down Expand Up @@ -26,16 +26,31 @@
}
];
};

# Tests if `pg4-init` fails due to `./bad_test.sql`
services.postgres."pg4" = {
enable = true;
socketDir = "./test/new/socket/path3";
listen_addresses = "";
initialDatabases = [
{
name = "test-db";
schemas = [ ./bad_test.sql ];
}
];
};
# avoid both the processes trying to create `data` directory at the same time
settings.processes."pg2-init".depends_on."pg1-init".condition = "process_completed_successfully";
settings.processes."pg3-init".depends_on."pg2-init".condition = "process_completed_successfully";
settings.processes."pg4-init".depends_on."pg3-init".condition = "process_completed_successfully";

settings.processes.test =
let
cfg = config.services.postgres."pg1";
in
{
command = pkgs.writeShellApplication {
runtimeInputs = [ cfg.package pkgs.gnugrep ];
runtimeInputs = [ cfg.package pkgs.gnugrep pkgs.curl pkgs.jq ];
text = ''
echo 'SELECT version();' | psql -h 127.0.0.1
echo 'SHOW hba_file;' | psql -h 127.0.0.1 | ${pkgs.gawk}/bin/awk 'NR==3' | grep '^ /nix/store'
Expand All @@ -48,9 +63,17 @@

# schemas test
echo "SELECT * from users where user_name = 'test_user';" | psql -h 127.0.0.1 -p 5433 -d sample-db | grep -q test_user

# listen_addresses test
echo "SELECT 1 FROM pg_database where datname = 'test-db';" | psql -h "$(readlink -f ${config.services.postgres.pg3.socketDir})" -d postgres | grep -q 1

# Test if `pg4-init` fails due to `bad_test.sql`
#
# The curl to process-compose server is documented in the swagger URL, http://localhost:8080, but since we are listening on unix socket here, you can use `socat` to temporarily pipe the port `8080` to the `pc-${name}.sock` (`socat TCP-LISTEN:8080,fork UNIX-CONNECT:/path/to/your/socket.sock

# OpenAPI documentation from the swagger URL:
# /process/logs/{name}/{endOffset}/{limit}
curl --unix-socket pc-${name}.sock http://localhost/process/logs/pg4-init/30/0 | jq '.logs | contains(["ERROR: syntax error at or near \"STABLE\""])' | grep "true"
'';
name = "postgres-test";
};
Expand Down
5 changes: 3 additions & 2 deletions nix/services/postgres/setup-script.nix
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,13 @@ in
}
trap 'remove_tmp_pg_init_sock_dir "$PGHOST"' EXIT

trap 'pg_ctl -D "$PGDATA" -m fast -w stop' EXIT

pg_ctl -D "$PGDATA" -w start -o "-c unix_socket_directories=$PGHOST -c listen_addresses= -p ${toString config.port}"

${runInitialScript.before}
${setupInitialDatabases}
${runInitialScript.after}
pg_ctl -D "$PGDATA" -m fast -w stop
remove_tmp_pg_init_sock_dir "$PGHOST"
else
echo
echo "PostgreSQL database directory appears to contain a database; Skipping initialization"
Expand Down
10 changes: 10 additions & 0 deletions nix/services/prometheus.nix
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,18 @@ in
port = config.port;
path = "/-/ready";
};
initial_delay_seconds = 2;
period_seconds = 10;
timeout_seconds = 4;
success_threshold = 1;
failure_threshold = 5;
};

# https://github.com/F1bonacc1/process-compose#-auto-restart-if-not-healthy
availability = {
restart = "on_failure";
max_restarts = 5;
};
};
};
};
Expand Down
10 changes: 10 additions & 0 deletions nix/services/redis-cluster.nix
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,18 @@ in

readiness_probe = {
exec.command = "${config.package}/bin/redis-cli -p ${port} ping";
initial_delay_seconds = 2;
period_seconds = 10;
timeout_seconds = 4;
success_threshold = 1;
failure_threshold = 5;
};

# https://github.com/F1bonacc1/process-compose#-auto-restart-if-not-healthy
availability = {
restart = "on_failure";
max_restarts = 5;
};
};
hosts = lib.mapAttrsToList (_: cfg: "${config.bind}:${builtins.toString cfg.port}") config.nodes;
clusterCreateScript = pkgs.writeShellApplication {
Expand Down
10 changes: 10 additions & 0 deletions nix/services/redis.nix
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,17 @@ in
"${config.package}/bin/redis-cli -s ${transformedSocketPath} ${toString config.port} ping"
else
"${config.package}/bin/redis-cli -p ${toString config.port} ping";
initial_delay_seconds = 2;
period_seconds = 10;
timeout_seconds = 4;
success_threshold = 1;
failure_threshold = 5;
};
# https://github.com/F1bonacc1/process-compose#-auto-restart-if-not-healthy
availability = {
restart = "on_failure";
max_restarts = 5;
};
};
};
};
Expand Down
5 changes: 5 additions & 0 deletions nix/services/searxng.nix
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ in
host = config.host;
port = config.port;
};
initial_delay_seconds = 2;
period_seconds = 10;
timeout_seconds = 4;
success_threshold = 1;
failure_threshold = 5;
};
};
};
Expand Down
3 changes: 3 additions & 0 deletions nix/services/tempo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ in
path = "/ready";
};
initial_delay_seconds = 15;
period_seconds = 10;
timeout_seconds = 2;
success_threshold = 1;
failure_threshold = 5;
};
availability = {
restart = "on_failure";
Expand Down
5 changes: 5 additions & 0 deletions nix/services/tika.nix
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ in
host = config.host;
port = config.port;
};
initial_delay_seconds = 2;
period_seconds = 10;
timeout_seconds = 4;
success_threshold = 1;
failure_threshold = 5;
};
};
};
Expand Down
Loading