<commit_before>#!/usr/bin/perl

use strict;
use warnings;
use 5.012;

use Getopt::Long;
use RedisFailover;
use File::Basename;

our $PROGNAME = basename($0);

my $sentinel = 'localhost:26379';
my $out      = '/etc/nutcracker/nutcracker.yml';
my $pid      = '/tmp/redis_failover';
my $pretend;
my $check;
my $help;

GetOptions(
    "sentinel|s=s" => \$sentinel,
    "out|o=s"      => \$out,
    "pretend|p"    => \$pretend,
    "check|c"      => \$check,
    "help|h"       => \$help,
);

if ($check) {
    {
        my $uid  = ( stat $out )[4];
        my $user = ( getpwuid $uid )[0];
        if ( $user ne 'redis' ) {
            say 'it seems like the nutcracker config is not writable by redis user';
        }
    }
    {
        my $uid  = ( stat dirname($out) )[4];
        my $user = ( getpwuid $uid )[0];
        if ( $user ne 'redis' ) {
            say 'it seems like the nutcracker config directory is not writable by redis user';
        }
    }

    exit(0);
}

if ($help) {
    say "usage:";
    say "$PROGNAME --out <nutcracker.yml> --help";
    say "\t--sentinel  | -s define sentinel server";
    say "\t--out       | -o output to specified file";
    say "\t--pretend   | -p write config, but don't issue restart";
    say "\t--check     | -c quick check if redis can rewrite nutcracker config";
    say "\t--help      | -h display this help";
    exit(0);
}

#TODO: this is ugly :X
while ( -f $pid ) { }

open my $fh, '>', $pid;
close($fh);
eval {
    RedisFailover->new(
        out      => $out,
        sentinel => $sentinel,
        pretend  => $pretend,
    )->run;
};
eval {
    RedisFailover->new(
        out      => "socket_$out",
        sentinel => $sentinel,
        pretend  => $pretend,
        listen   => '/run/redis/nutcracker.sock',
    )->run;
};

unlink $pid;<commit_msg>Append socket to choosen filename<commit_after>#!/usr/bin/perl

use strict;
use warnings;
use 5.012;

use Getopt::Long;
use RedisFailover;
use File::Basename;

our $PROGNAME = basename($0);

my $sentinel = 'localhost:26379';
my $out      = '/etc/nutcracker/nutcracker.yml';
my $pid      = '/tmp/redis_failover';
my $pretend;
my $check;
my $help;

GetOptions(
    "sentinel|s=s" => \$sentinel,
    "out|o=s"      => \$out,
    "pretend|p"    => \$pretend,
    "check|c"      => \$check,
    "help|h"       => \$help,
);

if ($check) {
    {
        my $uid  = ( stat $out )[4];
        my $user = ( getpwuid $uid )[0];
        if ( $user ne 'redis' ) {
            say 'it seems like the nutcracker config is not writable by redis user';
        }
    }
    {
        my $uid  = ( stat dirname($out) )[4];
        my $user = ( getpwuid $uid )[0];
        if ( $user ne 'redis' ) {
            say 'it seems like the nutcracker config directory is not writable by redis user';
        }
    }

    exit(0);
}

if ($help) {
    say "usage:";
    say "$PROGNAME --out <nutcracker.yml> --help";
    say "\t--sentinel  | -s define sentinel server";
    say "\t--out       | -o output to specified file";
    say "\t--pretend   | -p write config, but don't issue restart";
    say "\t--check     | -c quick check if redis can rewrite nutcracker config";
    say "\t--help      | -h display this help";
    exit(0);
}

#TODO: this is ugly :X
while ( -f $pid ) { }

open my $fh, '>', $pid;
close($fh);
eval {
    RedisFailover->new(
        out      => $out,
        sentinel => $sentinel,
        pretend  => $pretend,
    )->run;
};
eval {
    my $out =~ s/\.yml$/_socket.yml/;
    RedisFailover->new(
        out         => $out,
        sentinel    => $sentinel,
        pretend     => $pretend,
        listen_addr => '/run/redis/nutcracker.sock',
    )->run;
};

unlink $pid;
{'fraction_non_alphanumeric': 0.16915557969046974, 'fraction_numerical': 0.008688569101276133, 'mean_word_length': 2.0396039603960396, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3572831', 'n_tokens_mistral': 1401, 'n_tokens_neox': 1341, 'n_words': 374}