Dynamically start console server on a given TTY

obmc-console-server currently uses /dev/ttyVUART0, which is a symlink
to ttyS0. This patch allows the TTY number to be populated based on some source
and then passes the TTY number on which the console server needs to be started.

This patch also makes sure that obmc-console-ssh@.service is instantiated only
if the console server is started on the TTY device mentioned above.

Fixes openbmc/openbmc#407

Change-Id: If7a6f0e5b899a32225af262e72a3292fb619920a
Signed-off-by: Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com>
diff --git a/common/recipes-phosphor/console/obmc-console.bb b/common/recipes-phosphor/console/obmc-console.bb
index f6c1db2..9d3315c 100644
--- a/common/recipes-phosphor/console/obmc-console.bb
+++ b/common/recipes-phosphor/console/obmc-console.bb
@@ -18,13 +18,15 @@
 SRCREV = "44580de4e2170c8ee06dbf401315d3acfcf52b22"
 
 REGISTERED_SERVICES_${PN} += "obmc_console:tcp:2200"
+OBMC_CONSOLE_HOST_TTY ?= "ttyVUART0"
+SYSTEMD_SUBSTITUTIONS += "OBMC_CONSOLE_HOST_TTY:${OBMC_CONSOLE_HOST_TTY}:${PN}-ssh@.service"
 
 SYSTEMD_SERVICE_${PN} = " \
-        ${PN}.service \
+        ${PN}@.service \
+        ${PN}@${OBMC_CONSOLE_HOST_TTY}.service \
         ${PN}-ssh.socket \
         ${PN}-ssh@.service \
         "
-
 do_install_append() {
         install -m 0755 -d ${D}${sysconfdir}
         install -m 0644 ${WORKDIR}/${PN}.conf ${D}${sysconfdir}/${PN}.conf
diff --git a/common/recipes-phosphor/console/obmc-console/obmc-console-ssh@.service b/common/recipes-phosphor/console/obmc-console/obmc-console-ssh@.service
index 198383c..f8fa7cc 100644
--- a/common/recipes-phosphor/console/obmc-console/obmc-console-ssh@.service
+++ b/common/recipes-phosphor/console/obmc-console/obmc-console-ssh@.service
@@ -1,6 +1,6 @@
 [Unit]
 Description=Phosphor Host Console SSH Per-Connection
-Wants=obmc-console.service
+Wants=obmc-console@{OBMC_CONSOLE_HOST_TTY}.service
 
 [Service]
 Environment="DROPBEAR_RSAKEY_DIR=/etc/dropbear"
diff --git a/common/recipes-phosphor/console/obmc-console/obmc-console.service b/common/recipes-phosphor/console/obmc-console/obmc-console.service
deleted file mode 100644
index b9a6c99..0000000
--- a/common/recipes-phosphor/console/obmc-console/obmc-console.service
+++ /dev/null
@@ -1,12 +0,0 @@
-[Unit]
-Description=Phosphor Console Muxer
-BindsTo=dev-ttyVUART0.device
-After=dev-ttyVUART0.device
-
-[Service]
-# TODO: openbmc/obmc-console#5 - Restore this to 'obmc-console-server ttyVUART0'
-ExecStart=/bin/sh -c 'realpath /dev/ttyVUART0 | xargs basename | xargs {sbindir}/obmc-console-server'
-Restart=always
-
-[Install]
-WantedBy={SYSTEMD_DEFAULT_TARGET}
diff --git a/common/recipes-phosphor/console/obmc-console/obmc-console@.service b/common/recipes-phosphor/console/obmc-console/obmc-console@.service
new file mode 100644
index 0000000..d84fca9
--- /dev/null
+++ b/common/recipes-phosphor/console/obmc-console/obmc-console@.service
@@ -0,0 +1,12 @@
+[Unit]
+Description=Phosphor Console Muxer listening on device /dev/%I
+BindsTo=dev-%i.device
+After=dev-%i.device
+
+[Service]
+# TODO: openbmc/obmc-console#5 - Restore this to 'obmc-console-server ttyVUART0'
+ExecStart=/bin/sh -c 'realpath /dev/%i | xargs basename | xargs {sbindir}/obmc-console-server'
+Restart=always
+
+[Install]
+WantedBy={SYSTEMD_DEFAULT_TARGET}