Skip to content

Commit 059fa34

Browse files
authored
DLPX-71998 Chatty systemd events for getty, serial-getty services take up a large percentage of syslog (#266)
DLPX-72681 delphix-startup-screen fails with static IP address DLPX-73286 systemd is restarting locale service every 30 seconds DLPX-73423 delphix-startup-screen crashes if there's no default route
1 parent 3871eed commit 059fa34

File tree

4 files changed

+50
-26
lines changed

4 files changed

+50
-26
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ jobs:
2525
with:
2626
python-version: '3.6'
2727
- run: python3 -m pip install pylint
28-
- run: pylint -d invalid-name files/common/usr/bin/delphix-startup-screen
28+
- run: python3 -m pip install netifaces
29+
- run: pylint -d invalid-name,E0611 files/common/usr/bin/delphix-startup-screen
2930
check-yapf:
3031
runs-on: ubuntu-18.04
3132
steps:
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[Service]
22
ExecStart=
3-
ExecStart=-/sbin/agetty -t 120 -o '-p -- \\u' --noclear %I $TERM
4-
ExecStartPre=-/usr/bin/delphix-startup-screen
3+
ExecStart=-/sbin/agetty -n -l /usr/bin/delphix-startup-screen --noclear %I $TERM
54
StandardInput=tty
65
StandardOutput=tty
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[Service]
22
ExecStart=
3-
ExecStart=-/sbin/agetty -t 120 -o '-p -- \\u' --keep-baud 115200,38400,9600 %I $TERM
4-
ExecStartPre=-/usr/bin/delphix-startup-screen
3+
ExecStart=-/sbin/agetty -n -l /usr/bin/delphix-startup-screen --keep-baud 115200,38400,9600 %I $TERM
54
StandardInput=tty
65
StandardOutput=tty

files/common/usr/bin/delphix-startup-screen

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ import curses
2323
import curses.ascii
2424
import curses.textpad
2525
import sys
26+
import signal
2627
import os
2728
import logging
2829
import subprocess
2930
from typing import List, Any, Tuple, Generator
31+
from netifaces import interfaces, ifaddresses, AF_INET
3032

3133
STATUS_HEADER: str = "STATUS\t\t\tSERVICE\t\t\t"
3234
LAYOUT_STR: str = "Keyboard layout (press 9 to change):"
@@ -201,6 +203,11 @@ def getstatus() -> str:
201203
status = ""
202204
for i in getstatus_pair(list(run_svcs("Description"))):
203205
#
206+
# Don't print any inactive services
207+
#
208+
if i[-1].strip() == "inactive":
209+
continue
210+
#
204211
# Switch the state and description
205212
#
206213
status += f"{i[-1]}\t{i[0]}\n"
@@ -209,22 +216,17 @@ def getstatus() -> str:
209216

210217
def get_network_status() -> Tuple[str, str]:
211218
"""
212-
Returns a tuple of (hostname, ipaddr) for the main interface.
219+
Returns a tuple of (hostname, ipaddrs).
213220
"""
214221

215-
#
216-
# We get the primary address based on the default route. The
217-
# address we use follows the 'src' key in the output.
218-
#
219-
cmd = ['ip', 'route', 'show', '0.0.0.0/0']
220-
cp = subprocess.run(cmd,
221-
stdout=subprocess.PIPE,
222-
universal_newlines=True,
223-
check=True)
224-
output = cp.stdout.split()
225-
ipaddr = output[output.index("src") + 1]
222+
ipaddrs = []
223+
for interface in interfaces():
224+
if interface == "lo":
225+
continue
226+
for link in ifaddresses(interface)[AF_INET]:
227+
ipaddrs.append(link['addr'])
226228
hostname = os.uname()[1]
227-
return (hostname, ipaddr)
229+
return (hostname, ", ".join(ipaddrs))
228230

229231

230232
# pylint: disable-msg=too-many-locals
@@ -239,11 +241,11 @@ def display_status(stdscr, win):
239241
layout = get_keyboard_layout()
240242

241243
width = X - 10
242-
height = Y - 8
244+
height = Y - 6
243245
status = 0
244246

245247
x = int((X - width) / 2) + 2
246-
y = (Y - height - 1)
248+
y = (Y - height)
247249

248250
win.clear()
249251
win.box()
@@ -270,10 +272,12 @@ def display_status(stdscr, win):
270272
sys.stdout.flush()
271273
sys.stderr.flush()
272274

273-
(hostname, ipaddr) = get_network_status()
275+
(hostname, ipaddrs) = get_network_status()
274276
netwin.clear()
275-
netwin.addstr(0, 0, "Host: http://" + hostname + "/", curses.A_BOLD)
276-
netwin.addstr(1, 0, "IP: " + ipaddr, curses.A_BOLD)
277+
if hostname:
278+
hostname = "https://" + hostname
279+
netwin.addstr(0, 0, "Host: " + hostname, curses.A_BOLD)
280+
netwin.addstr(1, 0, "IPs: " + ipaddrs, curses.A_BOLD)
277281
netwin.noutrefresh()
278282

279283
# We get status every 10 secs
@@ -373,7 +377,7 @@ def display_keyboard_layout_selection(stdscr, win):
373377
#
374378
# Main function.
375379
#
376-
def installer_main(stdscr):
380+
def console_main(stdscr):
377381
"""
378382
Main
379383
"""
@@ -389,6 +393,27 @@ def installer_main(stdscr):
389393

390394

391395
if __name__ == '__main__':
392-
logging.basicConfig(filename=log_file, level=logging.DEBUG)
396+
#
397+
# We need to ensure that any errors in the rest of the script won't
398+
# prevent us from logging into the system.
399+
#
400+
try:
401+
logging.basicConfig(filename=log_file, level=logging.DEBUG)
393402

394-
curses.wrapper(installer_main)
403+
#
404+
# Since we are going to invoke the login process directly
405+
# from the startup screen, we want to ensure that we ignore
406+
# any signals which would cause the status screen to restart.
407+
# This way the login prompt behaves the same as if it were
408+
# invoked from the getty service.
409+
#
410+
signal.signal(signal.SIGTTOU, signal.SIG_IGN)
411+
signal.signal(signal.SIGTSTP, signal.SIG_IGN)
412+
signal.signal(signal.SIGHUP, signal.SIG_IGN)
413+
signal.signal(signal.SIGINT, signal.SIG_IGN)
414+
signal.signal(signal.SIGQUIT, signal.SIG_IGN)
415+
416+
curses.wrapper(console_main)
417+
finally:
418+
login_cmd: List[str] = ['/bin/login', '-p']
419+
subprocess.run(login_cmd, shell=False, check=True)

0 commit comments

Comments
 (0)