conf: Ship default configuration and systemd units
Two configurations are supported:
1. A socket-activated, single-port client service arrangement, and
2. A port-templated client service
systemd's template-unit constraints prevent us from mapping ports to a
daemon configuration for the socket-activated case. To support multiple
concurrent console servers we have to revert to a standard daemon
arrangement where dropbear binds, listens and accepts its own
connections. This brings with it immediate memory overhead of running
dropbear before connections are received. As such configuration 2 is
opt-in as there are very few systems that require it.
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: Ifbcac1b1ca75ab3ff08c73855d7ed2ebabc27c0a
diff --git a/Makefile.am b/Makefile.am
index ce84c4c..f1a3a18 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,7 +1,21 @@
sbin_PROGRAMS = obmc-console-server
bin_PROGRAMS = obmc-console-client
-EXTRA_DIST = obmc-console.conf.sample
+obmcconsoledir = $(sysconfdir)/obmc-console
+obmcconsole_DATA = conf/server.ttyVUART0.conf
+
+if WITH_SYSTEMD
+systemdsystemunit_DATA = conf/obmc-console@.service \
+ conf/obmc-console-ssh@.service
+
+if ENABLE_CONCURRENT_SERVERS
+obmcconsole_DATA += conf/client.2200.conf
+else
+systemdsystemunit_DATA += conf/obmc-console-ssh.socket
+sshservicedir = $(systemdsystemunitdir)/obmc-console-ssh@.service.d
+sshservice_DATA = conf/obmc-console-ssh@.service.d/use-socket.conf
+endif
+endif
obmc_console_server_CPPFLAGS = \
-DLOCALSTATEDIR=\"$(localstatedir)\" \
diff --git a/conf/client.2200.conf.in b/conf/client.2200.conf.in
new file mode 100644
index 0000000..538cb55
--- /dev/null
+++ b/conf/client.2200.conf.in
@@ -0,0 +1 @@
+socket-id = host
diff --git a/conf/obmc-console-ssh.socket.in b/conf/obmc-console-ssh.socket.in
new file mode 100644
index 0000000..0eaa2b0
--- /dev/null
+++ b/conf/obmc-console-ssh.socket.in
@@ -0,0 +1,9 @@
+[Unit]
+Description=Phosphor Host Console SSH Per-Connection socket
+
+[Socket]
+ListenStream=2200
+Accept=yes
+
+[Install]
+WantedBy=sockets.target
diff --git a/conf/obmc-console-ssh@.service.d/use-socket.conf.in b/conf/obmc-console-ssh@.service.d/use-socket.conf.in
new file mode 100644
index 0000000..bd27077
--- /dev/null
+++ b/conf/obmc-console-ssh@.service.d/use-socket.conf.in
@@ -0,0 +1,4 @@
+[Service]
+ExecStart=
+ExecStart=-/usr/sbin/dropbear -r ${DROPBEAR_RSAKEY_DIR}/dropbear_rsa_host_key -c "/usr/bin/obmc-console-client" -i $DROPBEAR_EXTRA_ARGS
+StandardInput=socket
diff --git a/conf/obmc-console-ssh@.service.in b/conf/obmc-console-ssh@.service.in
new file mode 100644
index 0000000..10e106b
--- /dev/null
+++ b/conf/obmc-console-ssh@.service.in
@@ -0,0 +1,17 @@
+[Unit]
+Description=Console Client on %i
+Wants=dropbearkey.service
+After=dropbearkey.service
+
+[Service]
+# Unit defaults to a templated service
+Environment="DROPBEAR_RSAKEY_DIR=/etc/dropbear"
+EnvironmentFile=/etc/default/dropbear
+EnvironmentFile=-/etc/default/obmc-console-client
+ExecStart=/usr/sbin/dropbear -r ${DROPBEAR_RSAKEY_DIR}/dropbear_rsa_host_key -c "/usr/bin/obmc-console-client -c /etc/obmc-console/client.%i.conf" -p %i -F $DROPBEAR_EXTRA_ARGS
+SyslogIdentifier=console-client-%i
+ExecReload=/bin/kill -HUP $MAINPID
+KillMode=process
+
+[Install]
+WantedBy=default.target
diff --git a/conf/obmc-console@.service.in b/conf/obmc-console@.service.in
new file mode 100644
index 0000000..c6cd1b4
--- /dev/null
+++ b/conf/obmc-console@.service.in
@@ -0,0 +1,9 @@
+[Unit]
+Description=%i Console Server
+ConditionPathExists=/etc/obmc-console/server.%i.conf
+
+[Service]
+# Instance ID is the VUART basename
+ExecStart=/usr/sbin/obmc-console-server --config /etc/obmc-console/server.%i.conf %i
+SyslogIdentifier=%i-console-server
+Restart=always
diff --git a/conf/server.ttyVUART0.conf.in b/conf/server.ttyVUART0.conf.in
new file mode 100644
index 0000000..7d3f758
--- /dev/null
+++ b/conf/server.ttyVUART0.conf.in
@@ -0,0 +1,6 @@
+lpc-address = 0x3f8
+sirq = 4
+upstream-tty = ttyVUART0
+local-tty = ttyS0
+local-tty-baud = 115200
+socket-id = host
diff --git a/configure.ac b/configure.ac
index f720c7c..8f37250 100644
--- a/configure.ac
+++ b/configure.ac
@@ -12,6 +12,8 @@
AC_PROG_MAKE_SET
# Checks for libraries.
+PKG_PROG_PKG_CONFIG
+
PKG_CHECK_MODULES([SYSTEMD], [libsystemd > 221])
# Checks for header files.
@@ -22,6 +24,21 @@
# Checks for library functions.
LT_INIT # Removes 'unrecognized options: --with-libtool-sysroot'
+AC_ARG_WITH([systemdsystemunitdir],
+ AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd service files]),
+ [], [with_systemdsystemunitdir=${prefix}$($PKG_CONFIG --variable=systemdsystemunitdir systemd)])
+if test "x$with_systemdsystemunitdir" != xno; then
+ AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])
+fi
+AM_CONDITIONAL(WITH_SYSTEMD, [test -n "$with_systemdsystemunitdir" -a "x$with_systemdsystemunitdir" != xno ])
+
+AC_ARG_ENABLE([concurrent-servers],
+ [AS_HELP_STRING([--enable-concurrent-servers],
+ [Configure applications and systemd units for concurrent server instances])],
+ [],
+ [enable_concurrent_servers="no"])
+AM_CONDITIONAL([ENABLE_CONCURRENT_SERVERS], [test "x$enable_concurrent_servers" = "xyes"])
+
# Check/set gtest specific functions.
AX_PTHREAD([GTEST_CPPFLAGS="-DGTEST_HAS_PTHREAD=1"],[GTEST_CPP_FLAGS="-DGTEST_HAS_PTHREAD=0"])
AC_SUBST(GTEST_CPPFLAGS)
@@ -45,5 +62,14 @@
)
# Create configured output
-AC_CONFIG_FILES([Makefile test/Makefile])
+AC_CONFIG_FILES([
+ conf/client.2200.conf
+ conf/obmc-console@.service
+ conf/obmc-console-ssh@.service
+ conf/obmc-console-ssh@.service.d/use-socket.conf
+ conf/obmc-console-ssh.socket
+ conf/server.ttyVUART0.conf
+ Makefile
+ test/Makefile
+ ])
AC_OUTPUT
diff --git a/obmc-console.conf.sample b/obmc-console.conf.sample
deleted file mode 100644
index a4ff6ad..0000000
--- a/obmc-console.conf.sample
+++ /dev/null
@@ -1,15 +0,0 @@
-# For VUART devices, we can specify the LPC address and SIRQ parameters
-lpc-address = 0x3f8
-sirq = 4
-
-# For real UART devices, we can specify the baud rate
-# baud = 115200
-
-# To mirror to a local tty device (typically a hardware UART), set local-tty
-# local-tty = ttyS0
-
-# Specify log size. Default is 16kB if unset. Takes the following suffixes:
-# No suffix: byte
-# "k": kilobyte = 1024B
-# "M": megabytes = 1024kB
-# logsize = 128k