Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
donald committed Jan 31, 2019
1 parent 55e5388 commit 477e22b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions install.sh
Expand Up @@ -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
14 changes: 14 additions & 0 deletions 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
7 changes: 2 additions & 5 deletions serial-log/serial-log@.service
Expand Up @@ -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]
Expand Down

0 comments on commit 477e22b

Please sign in to comment.