Jump to content

How to: Automatically start armbianmonitor on serial terminal


Recommended Posts

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

 

 

Link to comment
Share on other sites

Armbian & Khadas are rewarding contributors

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines