Skip to content

Commit

Permalink
examples: simple script examples used for testing
Browse files Browse the repository at this point in the history
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
  • Loading branch information
troglobit committed Jan 2, 2024
1 parent d6292f0 commit 3c49b8a
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
EXTRA_DIST = monitor-script.sh supervisor-script.sh tempmon.sh
bin_PROGRAMS = ex1 ex2
AM_CFLAGS = -W -Wall -Wextra -std=gnu99
AM_CPPFLAGS = -I$(top_srcdir)/src
Expand Down
11 changes: 11 additions & 0 deletions examples/monitor-script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

PID=$(pidof sysrepo-plugind)
if [ -z "$PID" ]; then
# logger -sk -t monitor -I $PPID -p user.error "sysrepo-plugind is not running"
exit 0
fi
MEM=$(awk '/VmRSS/{print $2}' /proc/$PID/status)

logger -sk -t monitor -I $PPID -p user.notice "sysrepo-plugind memory usage: $MEM kB"
exit 0
22 changes: 22 additions & 0 deletions examples/supervisor-script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh

role=$1
code=$2
pid=$3
label=$4

case $code in
3)
logger -sp user.err -I $$ "process $pid failed a kick, cause $code, restarting service."
;;
5)
logger -sp user.err -I $$ "process $pid failed to meet its deadline, cause $code"
logger -sp user.err -I $$ "this cause is unrecoverable, exit 1!"
exit 1
;;
*)
;;
esac

logger -sp user.err -I $$ "system recovered, exit 0"
exit 0
18 changes: 18 additions & 0 deletions examples/tempmon.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh

TEMP=/sys/class/thermal/thermal_zone0/temp

check()
{
awk '{temp=$1; temp=temp/1000; rc=sprintf("%.1f", temp); exit rc < 55.0 }' < "$1"
}

if [ ! -f "$TEMP" ]; then
logger -sk -t tempmon -I $PPID -p user.warn "No such sensor $TEMP"
exit 1
fi

if check "$TEMP"; then
echo "Too hot!"
exit 10
fi

0 comments on commit 3c49b8a

Please sign in to comment.