@cryptotaxi247 / infra-1 / commits / 1e4152d5

Netcat syslog

Graham Christensen committed Apr 16, 2019 at 21:13 UTC 1e4152d50cfb8f01592bda03841b66bfddaff2df
4 files changed +54 -5
macs/guest/apply.sh
+10
@@ -1,5 +1,15 @@
1 #!/usr/bin/env bash
2
3 +echo "apply started at $(date)" | nc -w0 -u 10.172.170.1 1514
4 +
5 +printf '\n*.*\t@10.172.170.1:1514\n' | tee -a /etc/syslog.conf
6 +pkill syslog
7 +pkill asl
8 +
9 +exec 3>&1
10 +exec 2> >(nc -u 10.172.170.1 1514)
11 +exec 1>&2
12 +
13 PS4='${BASH_SOURCE}::${FUNCNAME[0]}::$LINENO '
14 set -o pipefail
15 set -ex
macs/guest/darwin-configuration.nix
+10
@@ -80,4 +80,14 @@ in
80 chown root:wheel ~root ~root/.ssh ~root/.ssh/authorized_keys
81 echo "ok"
82 '';
83 +
84 + launchd.daemons.prometheus-node-exporter = {
85 + script = ''
86 + exec ${pkgs.prometheus-node-exporter}/bin/node_exporter
87 + '';
88 +
89 + serviceConfig.KeepAlive = true;
90 + serviceConfig.StandardErrorPath = "/var/log/prometheus-node-exporter.log";
91 + serviceConfig.StandardOutPath = "/var/log/prometheus-node-exporter.log";
92 + };
93 }
macs/host/networking.nix
+30 -2
@@ -1,4 +1,4 @@
1 -{ lib, config, ... }:
1 +{ lib, pkgs, config, ... }:
2 let
3 inherit (lib) mkIf;
4
@@ -16,7 +16,12 @@ in {
16 '';
17
18 networking.firewall.allowedTCPPorts = [
19 - 2200 # forwarded port to the guest
19 + 2200 # forwarded to :22 on the guest for external SSH
20 + 9101 # forwarded to :9100 on the guest
21 + config.services.prometheus.exporters.node.port
22 + ];
23 + networking.firewall.allowedUDPPorts = [
24 + 1514 # guest sends logs here
25 ];
26
27 networking.nat = {
@@ -34,6 +39,11 @@ in {
39 proto = "tcp";
40 sourcePort = 2200;
41 }
42 + {
43 + destination = "${guestIP}:9100";
44 + proto = "tcp";
45 + sourcePort = 9101;
46 + }
47 ];
48 };
49
@@ -80,5 +90,23 @@ in {
90 cache.size = 10 * MB
91 '';
92 };
93 +
94 + services.prometheus.exporters.node = {
95 + enable = true;
96 + };
97 +
98 + systemd.services.netcatsyslog = {
99 + wantedBy = [ "multi-user.target" ];
100 + script = let
101 + ncl = pkgs.writeScript "ncl" ''
102 + #!/bin/sh
103 + set -euxo pipefail
104 + ${pkgs.netcat}/bin/nc -dklun 1514 | ${pkgs.coreutils}/bin/tr '<' $'\n'
105 + '';
106 + in ''
107 + set -euxo pipefail
108 + ${pkgs.expect}/bin/unbuffer ${ncl}
109 + '';
110 + };
111 };
112 }
macs/host/qemu.nix
+4 -3
@@ -26,10 +26,11 @@ in {
26 '';
27 };
28
29 - systemd.services."run-macos-vm" = {
30 - after = [ "create-macos-secrets.service" ];
31 - requires = [ "create-macos-secrets.service" ];
29 + systemd.services."run-macos-vm" = rec {
30 + requires = [ "create-macos-secrets.service" "dhcpd4.service" "kresd.service" "network-online.target" ];
31 + after = requires;
32 wantedBy = [ "multi-user.target" ];
33 + wants = [ "netcatsyslog.service" ];
34 path = with pkgs; [ zfs qemu cdrkit rsync findutils ];
35
36 serviceConfig.PrivateTmp = true;