Skip to content
Snippets Groups Projects
Commit e96619ce authored by Thomas Bellman's avatar Thomas Bellman Committed by Thomas Bellman
Browse files

Allow configuring options to serial console getty.


Add parameter 'options' to the console::serial::login definition,
allowing users to change which options get sent to the agetty process.

The default is intended to be the same as what the operating system
normally does; under systemd we thus pass --keep-baud by default, but
on RHEL-6 we default to no options.  (This is also the same behaviour
as we had before, so users that don't set the 'options' parameter will
not get any changes.)

Signed-off-by: default avatarThomas Bellman <bellman@lysator.liu.se>
parent 05a389b2
No related branches found
No related tags found
No related merge requests found
# Copyright © 2018-2020 Thomas Bellman, Linköping, Sweden # Copyright © 2018-2021 Thomas Bellman, Linköping, Sweden
# Licensed under the GNU LGPL v3+; see the README file for more information. # Licensed under the GNU LGPL v3+; see the README file for more information.
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
* *
* Parameters: * Parameters:
* - name Name of serial port device (without /dev/ prefix). * - name Name of serial port device (without /dev/ prefix).
* - getty_options Options to pass to the getty process.
* The defaults depend on the operating system.
* - ensure One of 'enabled' (the default) or 'disabled'. * - ensure One of 'enabled' (the default) or 'disabled'.
* - speeds (List of) speeds in bits/second. * - speeds (List of) speeds in bits/second.
* - termtype Default terminal type connected to the port. * - termtype Default terminal type connected to the port.
...@@ -15,6 +17,7 @@ ...@@ -15,6 +17,7 @@
*/ */
define console::serial::login( define console::serial::login(
$ensure='enabled', $ensure='enabled',
$getty_options=undef,
$speeds=[115200,38400,9600], $speeds=[115200,38400,9600],
$termtype='vt100', $termtype='vt100',
$rootlogin=undef, $rootlogin=undef,
...@@ -34,7 +37,9 @@ define console::serial::login( ...@@ -34,7 +37,9 @@ define console::serial::login(
console::serial::login::systemd { console::serial::login::systemd {
$name: $name:
ensure => $ensure, ensure => $ensure,
speeds => $speeds, termtype => $termtype; getty_options => $getty_options,
speeds => $speeds,
termtype => $termtype;
} }
} }
...@@ -42,7 +47,9 @@ define console::serial::login( ...@@ -42,7 +47,9 @@ define console::serial::login(
console::serial::login::rhel_6 { console::serial::login::rhel_6 {
$name: $name:
ensure => $ensure, ensure => $ensure,
speeds => $speeds, termtype => $termtype; getty_options => $getty_options,
speeds => $speeds,
termtype => $termtype;
} }
} }
...@@ -67,11 +74,26 @@ define console::serial::login( ...@@ -67,11 +74,26 @@ define console::serial::login(
# #
define console::serial::login::systemd( define console::serial::login::systemd(
$ensure, $ensure,
$getty_options=['--keep-baud'], # This is the systemd default
$speeds, $speeds,
$termtype, $termtype,
) )
{ {
$svcdir = "/etc/systemd/system/serial-getty@${name}.service.d" $svcdir = "/etc/systemd/system/serial-getty@${name}.service.d"
# Systemd cmdline quoting is not *exactly* like shell, but close enough.
$agetty_cmdline = shellquote(
# agetty(8) doc says tty name should be before speeds, but default
# systemd service definition puts %I after; do it like systemd does.
'/sbin/agetty',
$getty_options ? { undef => [], default => $getty_options, },
inline_template('<%= [@speeds].flatten.join(",") %>'),
'%I',
$termtype
)
$svc_params_cfg = (
"[Service]\nExecStart=\nExecStart=-${agetty_cmdline}\n"
)
file { file {
$svcdir: $svcdir:
ensure => $ensure ? { ensure => $ensure ? {
...@@ -83,11 +105,7 @@ define console::serial::login::systemd( ...@@ -83,11 +105,7 @@ define console::serial::login::systemd(
ensure => $ensure ? { ensure => $ensure ? {
'enabled' => file, 'disabled' => absent, 'enabled' => file, 'disabled' => absent,
}, },
content => inline_template( content => $svc_params_cfg,
"[Service]\n",
"ExecStart=\n",
"ExecStart=-/sbin/agetty --keep-baud <%= [@speeds].flatten.join(',') %> %I <%= @termtype %>\n"
),
owner => 'root', group => 'root', mode => '0444', owner => 'root', group => 'root', mode => '0444',
notify => Service["serial-getty@${name}"]; notify => Service["serial-getty@${name}"];
} }
...@@ -110,12 +128,20 @@ define console::serial::login::systemd( ...@@ -110,12 +128,20 @@ define console::serial::login::systemd(
# #
define console::serial::login::rhel_6( define console::serial::login::rhel_6(
$ensure, $ensure,
$getty_options=[],
$speeds, $speeds,
$termtype $termtype
) )
{ {
$svcname = "serial-${name}" $svcname = "serial-${name}"
$xspeeds = inline_template('<%= [@speeds].flatten.join(",") %>') # Upstart uses shell if special characters in command so use shellquote().
$agetty_cmdline = shellquote(
'/sbin/agetty',
$getty_options ? { undef => [], default => $getty_options, },
"/dev/${name}",
inline_template('<%= [@speeds].flatten.join(",") %>'),
$termtype
)
if ($ensure == 'enabled') if ($ensure == 'enabled')
{ {
...@@ -125,7 +151,7 @@ define console::serial::login::rhel_6( ...@@ -125,7 +151,7 @@ define console::serial::login::rhel_6(
'start on stopped rc RUNLEVEL=[2345]', 'start on stopped rc RUNLEVEL=[2345]',
'stop on starting runlevel [016]', 'stop on starting runlevel [016]',
'respawn', 'respawn',
"exec /sbin/agetty /dev/${name} ${xspeeds} ${termtype}", "exec ${agetty_cmdline}",
] ]
file { file {
"/etc/init/${svcname}.conf": "/etc/init/${svcname}.conf":
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment