Skip to content

feat(ns-don): enhance session management with logging and expiration checks#1554

Open
stephdl wants to merge 4 commits intomainfrom
sdl-1542
Open

feat(ns-don): enhance session management with logging and expiration checks#1554
stephdl wants to merge 4 commits intomainfrom
sdl-1542

Conversation

@stephdl
Copy link
Contributor

@stephdl stephdl commented Mar 4, 2026

Improve session management by adding logging for session events and implementing expiration checks. This update allows for better tracking of session status and automatic handling of expired sessions.

#1542

script to test the expiration manually

#!/bin/bash

echo "=========================================="
echo "  DON CHECK-EXPIRY TEST"
echo "=========================================="
echo ""

# Step 1: Stop any existing session
echo "[1/6] Stopping any existing session..."
don stop 2>/dev/null
sleep 1
echo ""

# Step 2: Start new session
echo "[2/6] Starting new session..."
don start
echo ""

# Step 3: Check initial status
echo "[3/6] Checking status (should show 24h remaining)..."
don status
echo ""

# Step 4: Simulate 25 hours passed
echo "[4/6] Simulating 25 hours have passed..."
current_time=$(date +%s)
old_time=$((current_time - 90000))  # 90000 seconds = 25 hours
echo $old_time > /var/run/don/session_start
echo "    Modified session_start timestamp to: $old_time"
echo ""

# Step 5: Check status (should show EXPIRED)
echo "[5/6] Checking status (should show EXPIRED)..."
don status
echo ""

# Step 6: Run check-expiry (should auto-stop and log)
echo "[6/6] Running check-expiry (should auto-stop service)..."
don check-expiry
sleep 1
echo ""

# Verification
echo "=========================================="
echo "  VERIFICATION"
echo "=========================================="
echo ""

echo "Service status:"
don status
echo ""

echo "Recent logs:"
tail -10 /var/log/messages | grep don
echo ""

echo "=========================================="
echo "  TEST COMPLETE"
echo "=========================================="
root@NethSec:~# cat test7days.sh 
#!/bin/bash

echo "=========================================="
echo "  DON CHECK-EXPIRY TEST WITH EXTENSION"
echo "=========================================="
echo ""

# Step 1: Stop any existing session
echo "[1/8] Stopping any existing session..."
don stop 2>/dev/null
sleep 1
echo ""

# Step 2: Start new session
echo "[2/8] Starting new session..."
don start
echo ""

# Step 3: Check initial status (24h)
echo "[3/8] Checking status (should show ~24h remaining)..."
don status
echo ""

# Step 4: Extend session by 7 days
echo "[4/8] Extending session by 7 days..."
don extend
echo ""

# Step 5: Verify extension timestamp
echo "[5/8] Verifying session_extended timestamp..."
if [ -f /var/run/don/session_extended ]; then
    session_extended=$(cat /var/run/don/session_extended)
    current_time=$(date +%s)
    time_diff=$((session_extended - current_time))
    days=$((time_diff / 86400))
    hours=$(( (time_diff % 86400) / 3600 ))
    echo "    session_start: $(cat /var/run/don/session_start)"
    echo "    session_extended: $session_extended"
    echo "    current_time: $current_time"
    echo "    Time until expiry: ${days}d ${hours}h (should be ~7d)"
else
    echo "    ERROR: session_extended file not found!"
fi
echo ""

# Step 6: Check status after extension (should show 7d)
echo "[6/8] Checking status after extension (should show ~7d remaining)..."
don status
echo ""

# Step 7: Simulate 8 days passed (should expire because extended was only 7d)
echo "[7/8] Simulating 8 days have passed..."
current_time=$(date +%s)
old_time=$((current_time - 691200))  # 691200 seconds = 8 days
echo $old_time > /var/run/don/session_start
echo "    Modified session_start timestamp to: $old_time"
# Also update session_extended to be in the past
old_extended=$((current_time - 86400))  # Set extended to 1 day ago
echo $old_extended > /var/run/don/session_extended
echo "    Modified session_extended timestamp to: $old_extended"
echo ""

# Step 8: Run check-expiry (should auto-stop because extended expiry passed)
echo "[8/8] Running check-expiry (should auto-stop service because extended expiry passed)..."
don check-expiry
sleep 1
echo ""

# Verification
echo "=========================================="
echo "  VERIFICATION"
echo "=========================================="
echo ""

echo "Service status (should show 'not running'):"
don status
echo ""

echo "Recent logs:"
tail -15 /var/log/messages | grep -E "don|support"
echo ""

echo "=========================================="
echo "  TEST COMPLETE"
echo "=========================================="

@stephdl stephdl requested review from Tbaile and gsanchietti March 5, 2026 11:29
@stephdl stephdl force-pushed the sdl-1542 branch 3 times, most recently from 4aff3ab to fd4d2ab Compare March 5, 2026 16:32
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@stephdl stephdl requested a review from Copilot March 5, 2026 18:44
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Member

@gsanchietti gsanchietti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove also the init script

@stephdl stephdl changed the title Enhance session management with logging and expiration checks fix(ns-don): enhance session management with logging and expiration checks Mar 6, 2026
@stephdl stephdl requested review from Tbaile and gsanchietti March 6, 2026 13:54
@stephdl stephdl changed the title fix(ns-don): enhance session management with logging and expiration checks feat(ns-don): enhance session management with logging and expiration checks Mar 6, 2026
Copy link
Collaborator

@Tbaile Tbaile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good for me, will merge after image release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants