From 576fa64abf3b8bd6f068b37905e9e35d92eef2e9 Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Wed, 19 Mar 2014 16:21:43 -0400 Subject: [PATCH] serial-console: Use udev rules to startup getty Update the systemd serial port element implementation so that it uses udev rules. Much nicer than hard coding ttyS0 and ttyS1. The udev rule only adds real serial device types (i.e. == 4). See: define TTY_DRIVER_TYPE_SERIAL 0x0003 from include/linux/tty_driver.h. Change-Id: I5d7de4815fd09c01693b7da4b8949f22fee20745 --- elements/serial-console/README.md | 4 ++-- elements/serial-console/install.d/20-stty | 8 +++----- .../serial-console/install.d/serial-console-udev.rules | 1 + 3 files changed, 6 insertions(+), 7 deletions(-) create mode 100644 elements/serial-console/install.d/serial-console-udev.rules diff --git a/elements/serial-console/README.md b/elements/serial-console/README.md index 73ce59c9..f753b160 100644 --- a/elements/serial-console/README.md +++ b/elements/serial-console/README.md @@ -1,4 +1,4 @@ -Start getty on ttyS0 and/or ttyS1 +Start getty on active serial consoles. With ILO and other remote admin environments, having a serial console can be useful for debugging and troubleshooting. @@ -7,4 +7,4 @@ For upstart: If ttyS1 exists, getty will run on that, otherwise on ttyS0. For systemd: - Try to start getty on both ttyS0 and ttyS1. + We dynamically start a getty on any active serial port via udev rules. diff --git a/elements/serial-console/install.d/20-stty b/elements/serial-console/install.d/20-stty index fe1e0b12..57e6312e 100755 --- a/elements/serial-console/install.d/20-stty +++ b/elements/serial-console/install.d/20-stty @@ -1,12 +1,10 @@ #!/bin/bash - -home=$(dirname $0) set -uex +SCRIPTDIR=$(dirname $0) DIB_INIT_SYSTEM=$(dib-init-system) if [ "$DIB_INIT_SYSTEM" == "upstart" ]; then - install -m 0644 -o root -g root $home/ttySx.conf /etc/init/ttySx.conf + install -m 0644 -o root -g root ${SCRIPTDIR}/ttySx.conf /etc/init/ttySx.conf elif [ "$DIB_INIT_SYSTEM" == "systemd" ]; then - ln -s /usr/lib/systemd/system/getty@.service /etc/systemd/system/getty.target.wants/getty@ttyS0.service - ln -s /usr/lib/systemd/system/getty@.service /etc/systemd/system/getty.target.wants/getty@ttyS1.service + install -D -g root -o root -m 0644 ${SCRIPTDIR}/serial-console-udev.rules /etc/udev/rules.d/99-serial-console.rules fi diff --git a/elements/serial-console/install.d/serial-console-udev.rules b/elements/serial-console/install.d/serial-console-udev.rules new file mode 100644 index 00000000..a0bd6c74 --- /dev/null +++ b/elements/serial-console/install.d/serial-console-udev.rules @@ -0,0 +1 @@ +SUBSYSTEM=="tty", ACTION=="add", TAG+="systemd", ENV{SYSTEMD_WANTS}+="getty@$name.service", ATTRS{type}=="4"