From 477e22be863cc418bdc73f0bbe8b6dcffb75e6e2 Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Thu, 31 Jan 2019 08:15:51 +0100 Subject: [PATCH] serial-log: Do not fail when tty is unavailable I don't like the fact, that on most systems `systemctl status` shows the state as degraded and that we have irrelevant entries in the journal, just because we don't have a functioning ttyS1 available. Regard serial.log\@ as a "best effort" service, which continuously tries to work with the device and just waits a bit on failure. Use an external command for the loop instead of abusing the service restart feature of systemd for that. --- install.sh | 1 + serial-log/serial-log | 14 ++++++++++++++ serial-log/serial-log@.service | 7 ++----- 3 files changed, 17 insertions(+), 5 deletions(-) create mode 100755 serial-log/serial-log diff --git a/install.sh b/install.sh index 6daac67..95dc3ef 100755 --- a/install.sh +++ b/install.sh @@ -134,4 +134,5 @@ install_exec hostconfig/hostconfig "$DESTDIR$usr_sbindir/h install_exec fon/fon.sh "$DESTDIR$usr_bindir/fon" install_exec nfsdtop/nfsdtop "$DESTDIR$usr_sbindir/nfsdtop" install_data serial-log/serial-log\@.service "$DESTDIR$systemdunitdir/serial-log@.service" +install_exec serial-log/serial-log "$DESTDIR$usr_exec_prefix/libexec/serial-log" exit diff --git a/serial-log/serial-log b/serial-log/serial-log new file mode 100755 index 0000000..21e2b49 --- /dev/null +++ b/serial-log/serial-log @@ -0,0 +1,14 @@ +#! /bin/bash + +(($#==1)) || { echo "usage: $0 device-name" >&2; exit 1; } + +devnam="$1" + +while true; do + until /usr/bin/stty -F "/dev/$devnam" 115200 -echo 2>/dev/null; do + sleep 60 + done + until cat "/dev/$devnam" >> /var/log/$devnam.log 2>&1;do + sleep 1 + done +done diff --git a/serial-log/serial-log@.service b/serial-log/serial-log@.service index 5f0c878..917907c 100644 --- a/serial-log/serial-log@.service +++ b/serial-log/serial-log@.service @@ -2,11 +2,8 @@ Description=TTY logger [Service] -ExecStartPre=/usr/bin/stty -F /dev/%I 115200 -echo -ExecStart=-/usr/bin/sh -c "/usr/bin/cat /dev/%I >> /var/log/%I.log 2>&1" -Type=idle -Restart=always -RestartSec=0 +ExecStart=/usr/libexec/serial-log %I +Type=simple UtmpIdentifier=%I [Install]