djurny Posted June 24, 2021 Posted June 24, 2021 Hi, To enable the armbianmonitor to show information on the running system on the serial console, I used to have a custom startup script, called from /etc/rc.local. After some time, I thought it was more neat to have this automatically started (and stopped) for login sessions that are started on serial consoles/terminals. This lead (led?) me to the following systemd unit file: [Unit] Description=armbianmonitor on ttyS2 Requires=serial-getty@ttyS2.service After=serial-getty@ttyS2.service After=getty.target BindsTo=serial-getty@ttyS2.service [Service] Type=idle ExecStartPre=-/bin/sleep 10 ExecStart=/usr/bin/armbianmonitor -m TTYPath=/dev/ttyS2 StandardInput=null StandardOutput=tty StandardError=syslog KillSignal=SIGKILL SendSIGHUP=yes [Install] WantedBy=serial-getty@ttyS2.service File goes into /usr/lib/systemd/system/armbianmonitor@ttyS2.service. To 'activate' it, perform the following after creating the file at the specified location: sudo systemctl daemon-reload sudo systemctl enable armbianmonitor@ttyS2 sudo systemctl stop armbianmonitor@ttyS2 sudo systemctl start armbianmonitor@ttyS2 This is currently working for me on OrangePi Zero, NanoPi R2S, Helios4 (@ttyS0) and Helios64. If you do not have serial-getty services started on ttyS2 - like in the example unit file - you will need to modify the 'ttyS2' with the serial console matching your situation. Note that the new armbianmonitor@ttyX service will auto-start when seial-getty@ttyX is started and it will also stop when serial-getty@ttyX is stopped. This is to prevent orphaned armbianmonitors. Fun thing to try is to stop and start serial-getty@ttyX and also see the armbianmonitor service for that tty stop/start in tandem. Hope this helps anyone out there, it's always nice to have serial output available in case things happen (and they always happen unexpectedly). Groetjes, p.s. See below spoiler for auto-adding these unit files based on your currently enabled serial-getty services. Spoiler #!/bin/bash systemctl list-units --type=service --state=active,inactive --full --no-pager --no-legend --plain "serial-getty@*" | while read _UNIT _DONTCARE do _DEVICE="${_UNIT%.service}" _DEVICE="${_DEVICE##*@}" _FILE="/lib/systemd/system/armbianmonitor@${_DEVICE:?}.service" { cat << EOF [Unit] Description=armbianmonitor on ${_DEVICE:?} Requires=${_UNIT:?} After=${_UNIT:?} After=getty.target BindsTo=${_UNIT:?} [Service] Type=idle ExecStartPre=-/bin/sleep 10 ExecStart=/usr/bin/armbianmonitor -m TTYPath=/dev/${_DEVICE:?} StandardInput=null StandardOutput=tty StandardError=syslog KillSignal=SIGKILL SendSIGHUP=yes [Install] WantedBy=${_UNIT:?} EOF } | sudo tee "${_FILE:?}" > /dev/null sudo chown root:root "${_FILE:?}" sudo chmod 0644 "${_FILE:?}" sudo systemctl daemon-reload done # EOF
Recommended Posts