Message boards : ATLAS Application : Top Monitoring at ALT-F3
Message board moderation

To post messages, you must log in.

AuthorMessage
computezrmle
Volunteer moderator
Project tester
Volunteer developer
Volunteer tester
Help desk expert
Avatar

Send message
Joined: 28 Jul 16
Posts: 473
Credit: 389,411
RAC: 77
Message 6753 - Posted: 9 Oct 2019, 15:32:10 UTC

@David Cameron

Is the following code still used to produce the top output at tty3?
# tty3: top
cat > /home/atlas/top.sh << EOF
while true; do sleep 5; top -b -n1 | head -36 >/dev/tty3 2>/dev/null; done
EOF
sudo sh /home/atlas/top.sh &


If yes it might be replaced by the following snippet:
# tty3: top
(
# add a user with limited privileges
echo -e 'user_on_tty3="montty3"'
echo -e 'pass_on_tty3="$(tr -dc '\''a-zA-Z0-9'\'' </dev/urandom |fold -w $(( 13 + RANDOM % 18)) |head -n 1)"'

# instead of /bin/bash the new user's login shell will be /usr/bin/top
echo -e 'useradd -s /usr/bin/top -U ${user_on_tty3}'
echo -e 'echo ${user_on_tty3}:${pass_on_tty3} |chpasswd'


# set top's secure mode as default together with an update delay of 7 seconds
echo -e 'echo -e "s\\n7.0" >/etc/toprc'


# systemd's default service on tty3 must be modified to avoid conflicts.
# The modified service will then take care of (re)starting the top monitoring
echo -e 'mkdir -p /etc/systemd/system/getty@tty3.service.d'
echo -e 'override_tty3="/etc/systemd/system/getty@tty3.service.d/override.conf"'

echo -e 'echo -e "[Service]" > ${override_tty3}'
echo -e 'echo -e "ExecStart=" >> ${override_tty3}'
echo -e 'echo -e "ExecStart=-/sbin/agetty --autologin ${user_on_tty3} %I linux" >> ${override_tty3}'

echo -e 'systemctl daemon-reload'
echo -e 'systemctl stop getty@tty3.service'
) > /home/atlas/top_on_tty3

sudo sh /home/atlas/top_on_tty3



ATM it's a proof of concept.
It works on an opensuse VM and I'm curious if it also works on CERN's CentOS VMs.
ID: 6753 · Rating: 0 · rate: Rate + / Rate - Report as offensive     Reply Quote
computezrmle
Volunteer moderator
Project tester
Volunteer developer
Volunteer tester
Help desk expert
Avatar

Send message
Joined: 28 Jul 16
Posts: 473
Credit: 389,411
RAC: 77
Message 6762 - Posted: 16 Oct 2019, 9:28:11 UTC

Improved version using nested "heredocs"
# tty3: top

cat > /home/atlas/top_on_tty3 << 'EOF_top_on_tty3'
#!/bin/bash

# add a user with limited privileges
# new user accounts are not activated by default
# activation can be done by setting a password
# here a random password is used that is only valid during the VM's lifetime
# instead of /bin/bash the new user's login shell will be /usr/bin/top

user_on_tty3="montty3"

min_pw_length=13
max_pw_length=18
pass_on_tty3="$(tr -dc 'a-zA-Z0-9' </dev/urandom |fold -w $(( ${min_pw_length} + RANDOM % $(( ${max_pw_length} - ${min_pw_length} )) )) |head -n 1)"

useradd -s /usr/bin/top -U ${user_on_tty3} >/dev/null 2>&1
echo ${user_on_tty3}:${pass_on_tty3} |chpasswd



# set top's secure mode as default together with an update delay of 7 seconds
cat > /etc/toprc << 'EOF_toprc'
s
7.0
EOF_toprc



# systemd's default service on tty3 must be modified to avoid conflicts.
# The modified service will then take care of (re)starting the top monitoring

masked_term='$TERM'
mkdir -p /etc/systemd/system/getty@tty3.service.d

cat > /etc/systemd/system/getty@tty3.service.d/override.conf << EOF_override_tty3_service
[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin ${user_on_tty3} %I ${masked_term}
EOF_override_tty3_service


systemctl daemon-reload

if [ "$(systemctl show -p ActiveState getty@tty3.service)" != "ActiveState=inactive" ]
then
    systemctl stop getty@tty3.service
fi
EOF_top_on_tty3

sudo sh /home/atlas/top_on_tty3
ID: 6762 · Rating: 0 · rate: Rate + / Rate - Report as offensive     Reply Quote
David Cameron
Project administrator
Project developer
Project tester
Project scientist

Send message
Joined: 20 Apr 16
Posts: 180
Credit: 1,355,327
RAC: 0
Message 6763 - Posted: 17 Oct 2019, 12:37:34 UTC - in response to Message 6762.  

Wow, I tested this out on the CentOS7 VM and it looks great, thanks a lot! Great idea to set up a user with login shell as top :)

I have added this now to the vbox bootstrap script, so should become active in a couple of hours.
ID: 6763 · Rating: 0 · rate: Rate + / Rate - Report as offensive     Reply Quote

Message boards : ATLAS Application : Top Monitoring at ALT-F3


©2024 CERN