new env variables for data-accumulator

This commit is contained in:
Tassilo - 2022-06-11 01:19:12 +02:00
parent 3dc3a267ab
commit 756e8e8f7e
Signed by: revol-xut
GPG Key ID: 4F56FF7759627D07
9 changed files with 138 additions and 130 deletions

View File

@ -237,8 +237,8 @@
nixpkgs.overlays = [ radio-conf.overlay."aarch64-linux" decode-server.overlay."aarch64-linux" ];
}
];
};
};
};
hydraJobs = {
data-hoarder."x86_64-linux" = self.nixosConfigurations.data-hoarder.config.system.build.toplevel;

View File

@ -36,15 +36,15 @@ in
};
};
"pg-dvbdump-setup" = {
description = "prepare dvbdump postgres database";
wantedBy = [ "multi-user.target" ];
after = [ "networking.target" "postgresql.service" ];
serviceConfig.Type = "oneshot";
description = "prepare dvbdump postgres database";
wantedBy = [ "multi-user.target" ];
after = [ "networking.target" "postgresql.service" ];
serviceConfig.Type = "oneshot";
path = [ pkgs.sudo config.services.postgresql.package ];
script = ''
sudo -u ${config.services.postgresql.superUser} psql -c "ALTER ROLE dvbdump WITH PASSWORD '$(cat ${config.sops.secrets.postgres_password.path})'"
'';
path = [ pkgs.sudo config.services.postgresql.package ];
script = ''
sudo -u ${config.services.postgresql.superUser} psql -c "ALTER ROLE dvbdump WITH PASSWORD '$(cat ${config.sops.secrets.postgres_password.path})'"
'';
};
};
};

View File

@ -12,12 +12,15 @@
wantedBy = [ "multi-user.target" ];
script = ''
export POSTGRES_PASSWORD=$(cat ${config.sops.secrets.postgres_password.path})
exec ${pkgs.data-accumulator}/bin/data-accumulator --host 0.0.0.0 --port 8080&
'';
environment = {
"INFLUX_HOST" = "http://localhost:8086";
"GRPC_HOST" = "http://127.0.0.1:50051";
"POSTGRES_HOST" = "127.0.0.1";
"POSTGRES_PORT" = "5432";
};
serviceConfig = {
Type = "forking";

View File

@ -26,13 +26,13 @@
systemd.services.dump-csv = {
path = with pkgs; [ influxdb gzip ];
script = ''
cd /tmp
TMPFILE=$(mktemp telegrams.XXXXX.csv.gz)
TIMESTAMP=$(date +"%Y%m%d-%H%M")
influx -precision rfc3339 -database dvbdump -execute "SELECT * FROM telegram_r_09 WHERE time > now()-1h" -format csv | gzip -c > $TMPFILE
chmod a+r $TMPFILE
cd /tmp
TMPFILE=$(mktemp telegrams.XXXXX.csv.gz)
TIMESTAMP=$(date +"%Y%m%d-%H%M")
influx -precision rfc3339 -database dvbdump -execute "SELECT * FROM telegram_r_09 WHERE time > now()-1h" -format csv | gzip -c > $TMPFILE
chmod a+r $TMPFILE
mv $TMPFILE /var/lib/data-accumulator/data/telegrams-''${TIMESTAMP}.csv.gz
mv $TMPFILE /var/lib/data-accumulator/data/telegrams-''${TIMESTAMP}.csv.gz
'';
};
systemd.timers.dump-csv = {

View File

@ -1,32 +1,32 @@
{ pkgs, config, lib, ... }:
let
receiver = pkgs.gnuradio-decoder;
cfg = config.services.dump-dvb.gnuradio;
receiver = pkgs.gnuradio-decoder;
cfg = config.services.dump-dvb.gnuradio;
in
{
options.services.dump-dvb.gnuradio = {
enable = lib.mkOption {
type = lib.types.bool;
default = false;
description = ''Wether to enable dump-dvb gnuradio reciever'';
};
device = lib.mkOption {
type = lib.types.str;
default = "";
example = "hackrf=0";
description = ''Device string to pass to gnuradio'';
};
frequency = lib.mkOption {
type = lib.types.int;
default = 170795000;
description = ''Frequency to tune radio to'';
};
offset = lib.mkOption {
type = lib.types.int;
default = 19550;
description = ''Offset of the signal from center frequency'';
};
{
options.services.dump-dvb.gnuradio = {
enable = lib.mkOption {
type = lib.types.bool;
default = false;
description = ''Wether to enable dump-dvb gnuradio reciever'';
};
device = lib.mkOption {
type = lib.types.str;
default = "";
example = "hackrf=0";
description = ''Device string to pass to gnuradio'';
};
frequency = lib.mkOption {
type = lib.types.int;
default = 170795000;
description = ''Frequency to tune radio to'';
};
offset = lib.mkOption {
type = lib.types.int;
default = 19550;
description = ''Offset of the signal from center frequency'';
};
};
config = lib.mkIf config.services.dump-dvb.gnuradio.enable {
@ -45,20 +45,20 @@ in
};
};
users.groups.gnuradio = {};
users.users.gnuradio = {
name = "gnuradio";
description = "gnu radio service user";
isSystemUser = true;
group = "gnuradio";
extraGroups = [ "plugdev" ];
};
users.groups.gnuradio = { };
users.users.gnuradio = {
name = "gnuradio";
description = "gnu radio service user";
isSystemUser = true;
group = "gnuradio";
extraGroups = [ "plugdev" ];
};
security.wrappers.gnuradio-decode = {
owner = "gnuradio";
group = "users";
capabilities = "cap_sys_nice+eip";
source = "${receiver}/bin/gnuradio-decoder-cpp";
security.wrappers.gnuradio-decode = {
owner = "gnuradio";
group = "users";
capabilities = "cap_sys_nice+eip";
source = "${receiver}/bin/gnuradio-decoder-cpp";
};
};

View File

@ -2,62 +2,62 @@
let
cfg = config.services.dump-dvb.telegram-decoder;
in
{
options.services.dump-dvb.telegram-decoder = {
enable = lib.mkOption {
type = lib.types.bool;
default = false;
description = ''Wether to enable dump-dvb telegram-decoder'';
};
server = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ "https://dump.dvb.solutions/" ];
description = ''URL of the dump-dvb websocket'';
};
configFile = lib.mkOption {
type = lib.types.str;
default = "/etc/telegram-decoder/settings.json";
description = ''Path to telegram-decoder config'';
};
authTokenFile = lib.mkOption {
type = lib.types.str;
default = "/etc/telegram-decoder/token";
description = ''Path to telegram-decoder auth token'';
};
{
options.services.dump-dvb.telegram-decoder = {
enable = lib.mkOption {
type = lib.types.bool;
default = false;
description = ''Wether to enable dump-dvb telegram-decoder'';
};
server = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ "https://dump.dvb.solutions/" ];
description = ''URL of the dump-dvb websocket'';
};
configFile = lib.mkOption {
type = lib.types.str;
default = "/etc/telegram-decoder/settings.json";
description = ''Path to telegram-decoder config'';
};
authTokenFile = lib.mkOption {
type = lib.types.str;
default = "/etc/telegram-decoder/token";
description = ''Path to telegram-decoder auth token'';
};
};
config = lib.mkIf config.services.dump-dvb.telegram-decoder.enable {
environment.systemPackages = [ pkgs.telegram-decoder ];
users.groups.telegram-decoder = { };
users.users.telegram-decoder = {
name = "telegram-decoder";
description = "gnu radio service user";
group = "telegram-decoder";
isSystemUser = true;
};
systemd.services."telegram-decoder" = {
enable = true;
wantedBy = [ "multi-user.target" ];
config = lib.mkIf config.services.dump-dvb.telegram-decoder.enable {
script = "exec ${pkgs.telegram-decoder}/bin/telegram-decode --config ${cfg.configFile} --server ${builtins.concatStringsSep " " cfg.server} &";
environment.systemPackages = [ pkgs.telegram-decoder ];
users.groups.telegram-decoder = {};
users.users.telegram-decoder = {
name = "telegram-decoder";
description = "gnu radio service user";
group = "telegram-decoder";
isSystemUser = true;
environment = {
AUTHENTICATION_TOKEN_PATH = cfg.authTokenFile;
};
systemd.services."telegram-decoder" = {
enable = true;
wantedBy = [ "multi-user.target" ];
script = "exec ${pkgs.telegram-decoder}/bin/telegram-decode --config ${cfg.configFile} --server ${builtins.concatStringsSep " " cfg.server} &";
environment = {
AUTHENTICATION_TOKEN_PATH=cfg.authTokenFile;
};
serviceConfig = {
Type = "forking";
User = "telegram-decoder";
Restart = "on-failure";
StartLimitBurst = "2";
StartLimitIntervalSec = "150s";
};
serviceConfig = {
Type = "forking";
User = "telegram-decoder";
Restart = "on-failure";
StartLimitBurst = "2";
StartLimitIntervalSec = "150s";
};
};
};
}
}

View File

@ -1,16 +1,16 @@
{ config, lib, ... }:
let
file = "/etc/nixos/configs" + "/config_${toString config.dump-dvb.systemNumber}.json"; # make sure that the box has our nix-config checkout, lol
receiver_configs = [
{ frequency = 170795000; offset = 19550; device = "hackrf=0"; } # dresden - barkhausen
{ frequency = 170795000; offset = 19500; device = "hackrf=0"; } # dresden - zentralwerk
{ frequency = 153850000; offset = 20000; device = ""; } # chemnitz
{ frequency = 170795000; offset = 19550; device = "hackrf=0"; } # dresden unused
{ frequency = 170795000; offset = 19550; device = "hackrf=0"; } # dresden unused
];
file = "/etc/nixos/configs" + "/config_${toString config.dump-dvb.systemNumber}.json"; # make sure that the box has our nix-config checkout, lol
receiver_configs = [
{ frequency = 170795000; offset = 19550; device = "hackrf=0"; } # dresden - barkhausen
{ frequency = 170795000; offset = 19500; device = "hackrf=0"; } # dresden - zentralwerk
{ frequency = 153850000; offset = 20000; device = ""; } # chemnitz
{ frequency = 170795000; offset = 19550; device = "hackrf=0"; } # dresden unused
{ frequency = 170795000; offset = 19550; device = "hackrf=0"; } # dresden unused
];
receiver_config = lib.elemAt receiver_configs config.dump-dvb.systemNumber;
receiver_config = lib.elemAt receiver_configs config.dump-dvb.systemNumber;
in
{
services.dump-dvb.gnuradio = {

View File

@ -3,7 +3,8 @@ let
installScript = (system:
let ip = "10.13.37.${toString (system.config.dump-dvb.systemNumber + 100)}";
in (pkgs.writeScriptBin "deploy" ''
in
(pkgs.writeScriptBin "deploy" ''
#!${pkgs.runtimeShell}
ssh root@${ip} "ps cax | grep \"nixos-rebuild\" > /dev/null"
if [ $? -eq 0 ]
@ -16,21 +17,25 @@ let
fi
''));
installScripts = pkgs.lib.mapAttrs' (name: system:
pkgs.lib.attrsets.nameValuePair ("deploy-" + name) (installScript system))
installScripts = pkgs.lib.mapAttrs'
(name: system:
pkgs.lib.attrsets.nameValuePair ("deploy-" + name) (installScript system))
systems;
deployAllExecutablePathsConcatted =
pkgs.lib.strings.concatMapStringsSep " " (path: "${path}/bin/deploy")
(builtins.attrValues installScripts);
(builtins.attrValues installScripts);
deployAllScript = (name:
pkgs.writeScriptBin name (''
#!${pkgs.runtimeShell} -ex
${pkgs.parallel}/bin/parallel --will-cite -j10 ::: ${deployAllExecutablePathsConcatted} || echo "Some deployment failed"
''));
pkgs.writeScriptBin name (
''
#!${pkgs.runtimeShell} -ex
${pkgs.parallel}/bin/parallel --will-cite -j10 ::: ${deployAllExecutablePathsConcatted} || echo "Some deployment failed"
''
));
in {
in
{
deploy-all = deployAllScript "deploy-all";
nuke-all = deployAllScript "nuke-all";
} // installScripts

View File

@ -1,12 +1,12 @@
{
services.dump-dvb.gnuradio = {
enable = true;
# frequency = 105200000;
# offset = 1100;
# device = "";
};
services.dump-dvb.telegram-decoder = {
enable = true;
};
services.dump-dvb.gnuradio = {
enable = true;
# frequency = 105200000;
# offset = 1100;
# device = "";
};
services.dump-dvb.telegram-decoder = {
enable = true;
};
}