Skip to content

Commit 46a3fb5

Browse files
authored
Merge pull request #689 from PureStorage-OpenConnect/training-20250919
Training 20250919
2 parents 663b9bd + 93ae2cd commit 46a3fb5

6 files changed

Lines changed: 47 additions & 20 deletions

File tree

assets/pxctl.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
NAMESPACE=$(kubectl get stc -A -o jsonpath='{.items[].metadata.namespace}')
2-
POD=$(kubectl get pods -n $NAMESPACE -l name=portworx -o wide | tail -1 | cut -f 1 -d " ")
2+
[ -z $NAMESPACE ] && echo "Cannot find StorageCluster in any namespace." && exit 1
3+
POD=$(kubectl get pods -n $NAMESPACE --field-selector=status.phase==Running -l name=portworx -o wide -o jsonpath='{.items[0].metadata.name}')
4+
[ -z $POD ] && echo "Cannot find a running oci-monitor pod in namespace $NAMESPACE." && exit 1
35
ADMIN_TOKEN=$(kubectl -n $NAMESPACE get secret px-admin-token -o jsonpath='{.data.auth-token}' 2>/dev/null | base64 -d)
46
[ "$ADMIN_TOKEN" ] && kubectl -n $NAMESPACE exec -ti $POD -c portworx -- /opt/pwx/bin/pxctl context create admin --token=$ADMIN_TOKEN
57
kubectl -n $NAMESPACE exec -ti $POD -c portworx -- bash -c "/opt/pwx/bin/pxctl $* || true"

assets/ttysnoop/_snoop

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,26 @@
22

33
global ttys
44

5-
probe kernel.function("pty_write") {
5+
probe kernel.function("pty_open") {
66
tty = kernel_string($tty->name)
7-
if (tty =~ "^pts" && !ttys[tty] && uid() > 1000 && uid() < 1200) {
8-
ttys[tty]=1
9-
uid = sprintf("%d", uid() - 1000)
10-
system("screen -dmS training".uid.".".tty.".snoop bash -c '(trap \"\" INT; snoop ".tty.")'")
7+
if (tty =~ "^pts" && uid() > 1000 && uid() < 1200 && execname() == "sshd") {
8+
n = substr(tty, 3, 2)
9+
ttys[n]++
10+
if (ttys[n] == 2) {
11+
uid = sprintf("%d", uid() - 1000)
12+
system("screen -dmS training.".tty.".training".uid.".snoop bash -c 'trap \"\" INT; while :; do snoop ".tty."; done'")
13+
}
14+
}
15+
}
16+
17+
probe kernel.function("pty_close") {
18+
tty = kernel_string($tty->name)
19+
if (tty =~ "^ptm" && execname() == "sshd") {
20+
n = substr(tty, 3, 2)
21+
ttys[n]--
22+
if (!ttys[n]) {
23+
system("screen -S training.pts".n.". -X quit")
24+
}
1125
}
1226
}
1327

assets/ttysnoop/_snoopall

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
3+
tmux new-session -d -s snoop -n main bash -c "trap '' INT; watch screen -ls"
4+
5+
while :; do
6+
sleep 1
7+
oldscreens=$screens
8+
screens=$(screen -ls | awk '/training.*snoop/{print$1}' | sort -t . -k 2,2 -k 3,3)
9+
[ "$screens" = "$oldscreens" ] && continue
10+
tmux select-pane -t snoop:0.0
11+
tmux kill-pane -a
12+
for i in $screens; do
13+
tmux split-window -t "snoop:main" -h "screen -x $i"
14+
tmux select-pane -T $i
15+
tmux select-layout -t "snoop:main" tiled
16+
done
17+
done

assets/ttysnoop/snoopall

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1 @@
1-
#!/usr/bin/env bash
2-
3-
tmux new-session -d -s snoop -n main bash -c "watch "who | grep training""
4-
5-
for i in $(screen -ls | awk '/training.*snoop/{print$1}' | sort -t . -k 2,2 -k 3,3); do
6-
tmux split-window -t "snoop:main" -h "screen -x $i"
7-
tmux select-pane -T $i
8-
tmux select-layout -t "snoop:main" tiled
9-
done
10-
111
tmux attach -t snoop

infra/all-common

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ systemctl disable firewalld 2>/dev/null
9696
while ! yum update -y glib2; do
9797
sleep 1
9898
done
99-
while ! dnf install -y at bash-completion nfs-utils chrony unzip ca-certificates netcat net-tools vim-enhanced nano git; do
99+
while ! dnf install -y at bash-completion nfs-utils chrony unzip ca-certificates netcat net-tools vim-enhanced nano git tmux screen; do
100100
sleep 1
101101
done
102102
git config --global color.ui auto true

scripts/ttysnoop

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ rpm -ih https://dl.rockylinux.org/vault/rocky/9.5/devel/x86_64/os/Packages/k/ker
33
rpm -ih https://dl.rockylinux.org/vault/rocky/9.5/devel/x86_64/debug/tree/Packages/k/kernel-debuginfo-5.14.0-503.14.1.el9_5.x86_64.rpm https://dl.rockylinux.org/vault/rocky/9.5/devel/x86_64/os/Packages/k/kernel-debuginfo-common-x86_64-5.14.0-503.14.1.el9_5.x86_64.rpm https://dl.rockylinux.org/vault/rocky/9.5/devel/x86_64/os/Packages/k/kernel-headers-5.14.0-503.14.1.el9_5.x86_64.rpm
44
dnf install -y systemtap
55

6-
install -m 700 /assets/ttysnoop/snoop /assets/ttysnoop/snoopall /assets/ttysnoop/_snoop /usr/sbin
6+
install -m 700 /assets/ttysnoop/snoop /assets/ttysnoop/snoopall /assets/ttysnoop/_snoop /assets/ttysnoop/_snoopall /usr/sbin
77

88
snoop test &
99
while [ ! -d /proc/systemtap ]; do
@@ -12,5 +12,9 @@ while [ ! -d /proc/systemtap ]; do
1212
done
1313
kill %1
1414

15-
echo "@reboot nohup /usr/sbin/_snoop &" | crontab -
16-
nohup /usr/sbin/_snoop &
15+
cat <<EOF | crontab -
16+
@reboot nohup /usr/sbin/_snoop &
17+
@reboot nohup /usr/sbin/_snoopall &
18+
EOF
19+
nohup /usr/sbin/_snoop &
20+
nohup /usr/sbin/_snoopall &

0 commit comments

Comments
 (0)