Capture syndicate-server logs in synit-pid1

This commit is contained in:
Tony Garnock-Jones 2022-02-07 13:04:12 +01:00
parent 75e388fec8
commit f66a89813d
3 changed files with 37 additions and 16 deletions

View file

@ -1,13 +1,13 @@
# Contributor: Tony Garnock-Jones <tonyg@leastfixedpoint.com>
# Maintainer: Tony Garnock-Jones <tonyg@leastfixedpoint.com>
pkgname=synit-pid1
pkgver=0.0.1
pkgrel=4
pkgver=0.0.2
pkgrel=1
pkgdesc="synit pid 1 program"
url="https://synit.org/"
arch="all"
license="GPLv3"
depends="syndicate-server"
depends="syndicate-server s6"
makedepends=""
source="
synit-pid1.aarch64
@ -24,10 +24,11 @@ build() {
package() {
mkdir -p "$pkgdir/sbin"
cp -p synit-pid1.${CARCH} "$pkgdir/sbin/synit-pid1"
cp -p "$startdir/synit-log" "$pkgdir/sbin/synit-log"
}
sha512sums="
80ff805cc6d9c3c93aaa255541dc3324cf1325c82402ec9f20b3e293081595ae5a651fe1d1a4732e2fa2cb3b5e10f992d67455de6978c156b03bdea1a7eefbf2 synit-pid1.aarch64
823cd73c26be73a796a66021c5ed61edcfa1ecb003d7261727bffca2d42fc0bca8888baef97910cc391546a8a67697b4b8e45bf2236714be2cc0685db0a52c50 synit-pid1.armv7
b3c5f15b5c682f226ecfa6c0eddf2254f3e417acc865a10a099c129a4541daa1a3ea58dd2a3396de1fc9dd98e03a1266485e5c5f8ce6b6bea0f914e3ac5f7b4c synit-pid1.x86_64
03ee111c5b4d2da50219a7ba95e4afdcc90e485866472e483c8ecdd6bdc824ce3c0d6565622afb0af6372f34f93c9ca2f536c224f45868957610fd425cc8640b synit-pid1.aarch64
8c8b836e5aace4fb36c474495752ff661dd75548b6e0d779171b7508194608721982c726ceb30e30b8e21fe776de8c4150787191d482d4feeb2903765f6269b3 synit-pid1.armv7
aa993cd216e989162586c08d9656e3fd3c715430977f659c1b2fcc35311cc7936d4f39acec9c997e1be1cd6dc8563d6b8b46ce905fecd87711a9973043a2d063 synit-pid1.x86_64
"

View file

@ -0,0 +1,3 @@
#!/bin/sh
mkdir -p /var/log/synit
exec s6-log t s999999 n500 /var/log/synit

View file

@ -4,6 +4,7 @@ use nix::sys::signal::{killpg, Signal};
use nix::sys::wait;
use nix::unistd;
use std::convert::TryInto;
use std::sync::Arc;
use syndicate::actor::*;
@ -21,6 +22,9 @@ use tokio::signal::unix::{signal, SignalKind};
pub struct CommandLine {
#[clap(long, default_value="/usr/bin/syndicate-server")]
server_path: String,
#[clap(long, default_value="/sbin/synit-log")]
log: String,
}
pub struct Pid1Listener {
@ -98,20 +102,33 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = Arc::new(CommandLine::parse());
let server = process::Command::new(&config.server_path)
.arg("--inferior")
.arg("--config")
.arg("/etc/syndicate/boot")
.stdin(std::process::Stdio::piped())
.stdout(std::process::Stdio::piped())
// .stderr(std::process::Stdio::null())
.spawn()
.expect("Could not spawn main server");
Actor::top(None, move |t| {
let server = process::Command::new(&config.server_path)
.arg("--inferior")
.arg("--config")
.arg("/etc/syndicate/boot")
.stdin(std::process::Stdio::piped())
.stdout(std::process::Stdio::piped())
.stderr(std::process::Stdio::piped())
.spawn()
.expect("Could not spawn main server");
let server_stderr: std::process::Stdio = server.stderr
.expect("fetching server stderr")
.try_into()
.expect("converting server stderr to Stdio");
if config.log.len() > 0 {
process::Command::new(&config.log)
.stdin(server_stderr)
.spawn()
.expect("Could not spawn log program");
}
Actor::top(None, |t| {
let listener = t.create(Pid1Listener::new(config));
let from_server = server.stdout.expect("Missing dataspace server stdout");
let to_server = server.stdin.expect("Missing dataspace server stdin");
let ds = &relay::TunnelRelay::run(t,
relay::Input::Bytes(Box::pin(from_server)),
relay::Output::Bytes(Box::pin(to_server)),