owncast: add archiver
This commit is contained in:
parent
233498c9ae
commit
0906569551
|
@ -1,13 +1,17 @@
|
||||||
{ config, pkgs, ... }:
|
{ config, pkgs, ... }:
|
||||||
|
|
||||||
{
|
{
|
||||||
|
imports = [
|
||||||
|
./owncast-archiver.nix
|
||||||
|
];
|
||||||
|
|
||||||
deployment = {
|
deployment = {
|
||||||
vcpu = 8;
|
vcpu = 8;
|
||||||
mem = 2048;
|
mem = 2048;
|
||||||
persistedShares = [ "/etc" "/home" "/var" ];
|
persistedShares = [ "/etc" "/home" "/var" ];
|
||||||
extraShares = [ {
|
extraShares = [ {
|
||||||
source = "/glusterfs/big/microvms/c3d2/config/owncast/archive";
|
source = "/glusterfs/big/microvms/c3d2/config/owncast/archive";
|
||||||
mountPoint = "/mnt/archive";
|
mountPoint = config.services.owncast-archiver.targetDir;
|
||||||
} ];
|
} ];
|
||||||
};
|
};
|
||||||
c3d2.hq.statistics.enable = true;
|
c3d2.hq.statistics.enable = true;
|
||||||
|
@ -38,7 +42,7 @@
|
||||||
proxyWebsockets = true;
|
proxyWebsockets = true;
|
||||||
};
|
};
|
||||||
locations."/archive/" = {
|
locations."/archive/" = {
|
||||||
alias = "/mnt/archive/";
|
alias = "${config.services.owncast-archiver.targetDir}/";
|
||||||
extraConfig = ''
|
extraConfig = ''
|
||||||
fancyindex on;
|
fancyindex on;
|
||||||
fancyindex_exact_size off;
|
fancyindex_exact_size off;
|
||||||
|
@ -46,5 +50,9 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
systemd.services.nginx.serviceConfig.ReadWritePaths = [ "/mnt/archive" ];
|
systemd.services.nginx.serviceConfig.ReadWritePaths = [
|
||||||
|
config.services.owncast-archiver.targetDir
|
||||||
|
];
|
||||||
|
|
||||||
|
services.owncast-archiver.enable = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
|
let
|
||||||
|
|
||||||
|
owncastArchiver = with pkgs; writeScript "owncast-archiver.sh" ''
|
||||||
|
#! ${runtimeShell} -e
|
||||||
|
|
||||||
|
PATH=${lib.makeBinPath [ coreutils curl jq ffmpeg ]}
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
|
||||||
|
STATUS="$(curl -s https://owncast.c3d2.de/api/status)"
|
||||||
|
ONLINE="$(echo "$STATUS" | jq -r .online)"
|
||||||
|
if [ "$ONLINE" = true ]; then
|
||||||
|
TITLE="$(echo "$STATUS" | jq -r .streamTitle)"
|
||||||
|
ffmpeg -i https://owncast.c3d2.de/hls/0/stream.m3u8 -c copy "$(echo "$(date -Iseconds)_$TITLE.mkv"|tr " +<>:/" "____\\-\\-")"
|
||||||
|
fi
|
||||||
|
|
||||||
|
sleep ${toString cfg.pollInterval}
|
||||||
|
done
|
||||||
|
'';
|
||||||
|
|
||||||
|
cfg = config.services.owncast-archiver;
|
||||||
|
|
||||||
|
in
|
||||||
|
|
||||||
|
{
|
||||||
|
options.services.owncast-archiver = with lib; {
|
||||||
|
enable = mkEnableOption "owncast archiver";
|
||||||
|
|
||||||
|
targetDir = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "/mnt/archive";
|
||||||
|
};
|
||||||
|
|
||||||
|
pollInterval = mkOption {
|
||||||
|
type = types.int;
|
||||||
|
default = 10;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = lib.mkIf cfg.enable {
|
||||||
|
users.users.archiver = {
|
||||||
|
isSystemUser = true;
|
||||||
|
group = "nginx";
|
||||||
|
};
|
||||||
|
|
||||||
|
systemd.services.owncast-archiver = {
|
||||||
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
after = [ "owncast.service" ];
|
||||||
|
serviceConfig = {
|
||||||
|
ReadWritePaths = cfg.targetDir;
|
||||||
|
WorkingDirectory = cfg.targetDir;
|
||||||
|
User = "archiver";
|
||||||
|
ExecStart = owncastArchiver;
|
||||||
|
Restart = "always";
|
||||||
|
RestartSec = 60;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in New Issue