Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions rdr/busybox/base/busybox-dc-1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ spec:
value: "/mnt/test/simple_io.sh"
- name: DATA_INTEGRITY_SCRIPT
value: "/mnt/test/simple_io_integrity_check.sh"
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
imagePullPolicy: IfNotPresent
name: busybox
volumeMounts:
Expand Down
4 changes: 4 additions & 0 deletions rdr/busybox/base/busybox-dc-10.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ spec:
value: "/mnt/test/simple_io.sh"
- name: DATA_INTEGRITY_SCRIPT
value: "/mnt/test/simple_io_integrity_check.sh"
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
imagePullPolicy: IfNotPresent
name: busybox
volumeMounts:
Expand Down
4 changes: 4 additions & 0 deletions rdr/busybox/base/busybox-dc-2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ spec:
value: "/mnt/test/simple_io.sh"
- name: DATA_INTEGRITY_SCRIPT
value: "/mnt/test/simple_io_integrity_check.sh"
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
imagePullPolicy: IfNotPresent
name: busybox
volumeMounts:
Expand Down
4 changes: 4 additions & 0 deletions rdr/busybox/base/busybox-dc-3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ spec:
value: "/mnt/test/simple_io.sh"
- name: DATA_INTEGRITY_SCRIPT
value: "/mnt/test/simple_io_integrity_check.sh"
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
imagePullPolicy: IfNotPresent
name: busybox
volumeMounts:
Expand Down
4 changes: 4 additions & 0 deletions rdr/busybox/base/busybox-dc-4.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ spec:
value: "/mnt/test/simple_io.sh"
- name: DATA_INTEGRITY_SCRIPT
value: "/mnt/test/simple_io_integrity_check.sh"
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
imagePullPolicy: IfNotPresent
name: busybox
volumeMounts:
Expand Down
4 changes: 4 additions & 0 deletions rdr/busybox/base/busybox-dc-5.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ spec:
value: "/mnt/test/simple_io.sh"
- name: DATA_INTEGRITY_SCRIPT
value: "/mnt/test/simple_io_integrity_check.sh"
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
imagePullPolicy: IfNotPresent
name: busybox
volumeMounts:
Expand Down
4 changes: 4 additions & 0 deletions rdr/busybox/base/busybox-dc-6.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ spec:
value: "/mnt/test/simple_io.sh"
- name: DATA_INTEGRITY_SCRIPT
value: "/mnt/test/simple_io_integrity_check.sh"
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
imagePullPolicy: IfNotPresent
name: busybox
volumeMounts:
Expand Down
4 changes: 4 additions & 0 deletions rdr/busybox/base/busybox-dc-7.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ spec:
value: "/mnt/test/simple_io.sh"
- name: DATA_INTEGRITY_SCRIPT
value: "/mnt/test/simple_io_integrity_check.sh"
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
imagePullPolicy: IfNotPresent
name: busybox
volumeMounts:
Expand Down
4 changes: 4 additions & 0 deletions rdr/busybox/base/busybox-dc-8.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ spec:
value: "/mnt/test/simple_io.sh"
- name: DATA_INTEGRITY_SCRIPT
value: "/mnt/test/simple_io_integrity_check.sh"
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
imagePullPolicy: IfNotPresent
name: busybox
volumeMounts:
Expand Down
4 changes: 4 additions & 0 deletions rdr/busybox/base/busybox-dc-9.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ spec:
value: "/mnt/test/simple_io.sh"
- name: DATA_INTEGRITY_SCRIPT
value: "/mnt/test/simple_io_integrity_check.sh"
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
imagePullPolicy: IfNotPresent
name: busybox
volumeMounts:
Expand Down
57 changes: 45 additions & 12 deletions rdr/busybox/scripts/simple_io.sh
Original file line number Diff line number Diff line change
@@ -1,46 +1,79 @@
#!/bin/sh

# Color codes for formatted output
Cyan='\033[0;36m'
NC='\033[0m' # No Color
Cyan='\033[0;36m'
NC='\033[0m'

# Constants
MOUNT="/mnt/test"
HASHFILE="$MOUNT/hashfile"
LOGFILE="$MOUNT/script.log"

# Simple logger: level, message...
log() {
level=$1
shift
ts=$(date '+%Y-%m-%dT%H:%M:%S%z')
# write to stdout and append to logfile (best-effort)
printf "%s [%s] %s\n" "$ts" "$level" "$*" | tee -a "$LOGFILE"
}

# Trap to handle termination signals (SIGINT, SIGTERM)
cleanup() {
echo "Received termination signal! Syncing data and exiting..."
log INFO "Received termination signal! Syncing data and exiting..."

if [ -n "$SLEEP_PID" ] && kill -0 "$SLEEP_PID" 2>/dev/null; then
log INFO "Killing background sleep (pid $SLEEP_PID)"
kill "$SLEEP_PID" 2>/dev/null
fi

sync
touch "$MOUNT/trap_$(date +%s)"
exit 1
log INFO "Exiting cleanly"
exit 0
}

trap cleanup SIGINT SIGTERM

hostname=$(hostname -f 2>/dev/null || hostname)
node="${NODE_NAME:-unknown}"

# Main loop
while true; do
hostname=$(hostname -f)
file="$MOUNT/data_$(date +%s)_$hostname"

printf "Creating file with name: ${Cyan}$file${NC}\n"
file="$MOUNT/data_$(date +%s)_${hostname}_${node}"

log INFO "Creating file with name: ${file}"

# Write random data to file
dd if=/dev/urandom of="$file" bs=4k count=$((RANDOM % 3 + 1)) oflag=direct
dd if=/dev/urandom of="$file" bs=4k count=$((RANDOM % 3 + 1)) oflag=direct 2>>"$LOGFILE"
dd_status=$?
if [ "$dd_status" -ne 0 ]; then
log ERROR "dd failed with status $dd_status; removing partial file $file"
rm -f "$file"
sync
# short backoff before continuing loop
sleep 1
continue
fi

# Compute and store hash
md5sum "$file" >> "$HASHFILE"
md5sum "$file" >> "$HASHFILE" 2>>"$LOGFILE" || log WARN "Failed to append hash for $file"
sync

# Random sleep with trap awareness
sleep_time=$((RANDOM % 15 + 1))
echo "Sleeping for $sleep_time seconds..."
log INFO "Sleeping for $sleep_time seconds..."
sleep "$sleep_time" &
SLEEP_PID=$!
wait "$SLEEP_PID"
SLEEP_PID=

# Perform random integrity check
if [ $((RANDOM % 2)) -eq 1 ]; then
md5sum -c --quiet "$HASHFILE"
if md5sum -c --quiet "$HASHFILE"; then
log INFO "Integrity check passed"
else
log WARN "Integrity check found problems (see md5sum output)"
fi
fi
done