r/serterm: Deploy serial terminal multiplexer
Using `tmux`, we can spawn a bunch of `picocom` processes for the serial ports connected to other server's console ports. The _serial-terminal-server_ service manages the `tmux` server process, while the individual _serial-terminal-server-window@.service_ units create a window in the `tmux` session. The serial terminal server runs as a dedicated user. The SSH server is configured to force this user to connect to the `tmux` session. This should help ensure the serial consoles are accessible, even if the Active Directory server is unavailable.
This commit is contained in:
6
roles/serterm/files/add-window.sh
Normal file
6
roles/serterm/files/add-window.sh
Normal file
@@ -0,0 +1,6 @@
|
||||
#!/bin/sh
|
||||
# vim: set sw=4 ts=4 sts=4 et :
|
||||
|
||||
port="$1"
|
||||
|
||||
exec tmux new-window -a -t 'serial:{end}' -n "${port##*/}" /usr/local/libexec/serterm/connect-serial /dev/"${port}"
|
||||
8
roles/serterm/files/connect-serial.sh
Normal file
8
roles/serterm/files/connect-serial.sh
Normal file
@@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
# vim: set sw=4 ts=4 sts=4 et :
|
||||
|
||||
: "${LOG_DIR:=/var/log/serial}"
|
||||
|
||||
port="$1"
|
||||
|
||||
exec picocom -b 115200 -g "${LOG_DIR%/}"/"${port##*/}".log "${port}"
|
||||
6
roles/serterm/files/remove-window.sh
Normal file
6
roles/serterm/files/remove-window.sh
Normal file
@@ -0,0 +1,6 @@
|
||||
#!/bin/sh
|
||||
# vim: set sw=4 ts=4 sts=4 et :
|
||||
|
||||
port="$1"
|
||||
|
||||
exec tmux kill-window -t "${port##*/}"
|
||||
16
roles/serterm/files/serial-terminal-server-window@.service
Normal file
16
roles/serterm/files/serial-terminal-server-window@.service
Normal file
@@ -0,0 +1,16 @@
|
||||
# vim: set ft=systemd :
|
||||
[Unit]
|
||||
Description=Add serial terminal window for %I
|
||||
Requires=serial-terminal-server.service
|
||||
After=serial-terminal-server.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/local/libexec/serterm/add-window %I
|
||||
ExecStop=/usr/local/libexec/serterm/remove-window %I
|
||||
RemainAfterExit=yes
|
||||
User=serterm
|
||||
Group=serterm
|
||||
|
||||
[Install]
|
||||
WantedBy=serial-terminal-server.service
|
||||
14
roles/serterm/files/serial-terminal-server.service
Normal file
14
roles/serterm/files/serial-terminal-server.service
Normal file
@@ -0,0 +1,14 @@
|
||||
# vim: set ft=systemd :
|
||||
[Unit]
|
||||
Description=Serial Terminal
|
||||
|
||||
[Service]
|
||||
Type=forking
|
||||
ExecStart=/usr/local/libexec/serterm/start-server
|
||||
User=serterm
|
||||
Group=serterm
|
||||
Restart=always
|
||||
RestartSec=1s
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
16
roles/serterm/files/start-server.sh
Normal file
16
roles/serterm/files/start-server.sh
Normal file
@@ -0,0 +1,16 @@
|
||||
#!/bin/sh
|
||||
# vim: set sw=4 ts=4 sts=4 et :
|
||||
|
||||
if [ -z "${TMUX}" ]; then
|
||||
exec tmux new-session -s serial -d "$0"
|
||||
fi
|
||||
|
||||
tmux \
|
||||
set-option -t serial:0 -w remain-on-exit on \; \
|
||||
rename-window -t serial:0 info
|
||||
|
||||
cat <<'EOF'
|
||||
This window must remain open to keep the tmux server/session running.
|
||||
If all windows are closed, tmux will exit and will not be able to
|
||||
receive commands to add new windows for hotplugged devices.
|
||||
EOF
|
||||
18
roles/serterm/files/start-session.sh
Normal file
18
roles/serterm/files/start-session.sh
Normal file
@@ -0,0 +1,18 @@
|
||||
#!/bin/sh
|
||||
# vim: set sw=4 ts=4 sts=4 et :
|
||||
|
||||
if [ -z "${TMUX}" ]; then
|
||||
exec tmux new-session -s serial -d "$0"
|
||||
fi
|
||||
|
||||
tmux \
|
||||
set-option -t serial:0 -w remain-on-exit on \; \
|
||||
rename-window -t serial:0 info
|
||||
|
||||
cat <<'EOF'
|
||||
This window must remain open to keep the tmux server/session running.
|
||||
If all windows are closed, tmux will exit and will not be able to
|
||||
receive commands to add new windows for hotplugged devices.
|
||||
|
||||
Use `respawn-window` to restart all serial terminal windows.
|
||||
EOF
|
||||
18
roles/serterm/files/start-terminal-server.sh
Normal file
18
roles/serterm/files/start-terminal-server.sh
Normal file
@@ -0,0 +1,18 @@
|
||||
#!/bin/sh
|
||||
# vim: set sw=4 ts=4 sts=4 et :
|
||||
|
||||
if [ -z "${TMUX}" ]; then
|
||||
exec tmux new-session -s serial -d "$0"
|
||||
fi
|
||||
|
||||
tmux \
|
||||
set-option -t serial:0 -w remain-on-exit on \; \
|
||||
rename-window -t serial:0 info
|
||||
|
||||
cat <<'EOF'
|
||||
This window must remain open to keep the tmux server/session running.
|
||||
If all windows are closed, tmux will exit and will not be able to
|
||||
receive commands to add new windows for hotplugged devices.
|
||||
|
||||
Use `respawn-window` to restart all serial terminal windows.
|
||||
EOF
|
||||
Reference in New Issue
Block a user