Spaces:
Sleeping
Sleeping
Commit
·
c4c4d66
1
Parent(s):
3994c21
Add model update scripts and startup logging
Browse filesIntroduced PowerShell and Bash scripts for automated model updates with resource limits and locking mechanisms for both Windows and Linux environments. Added a PowerShell script to check for model updates on startup and log results. Created a startup_update.log file for logging update activities.
- logs/startup_update.log +0 -0
- scripts/startup_check.ps1 +32 -0
- scripts/update_models.ps1 +72 -0
- scripts/update_models.sh +65 -0
logs/startup_update.log
ADDED
Binary file (542 Bytes). View file
|
|
scripts/startup_check.ps1
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# UFC Model Update - Run on Startup
|
2 |
+
# This script runs when you start your laptop and checks for model updates
|
3 |
+
|
4 |
+
$PROJECT_DIR = "C:\Users\Alvaro\Desktop\ufc"
|
5 |
+
$LOG_FILE = "$PROJECT_DIR\logs\startup_update.log"
|
6 |
+
|
7 |
+
function Write-Log {
|
8 |
+
param($Message)
|
9 |
+
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
|
10 |
+
"[$timestamp] $Message" | Out-File -FilePath $LOG_FILE -Append
|
11 |
+
Write-Host "[$timestamp] $Message"
|
12 |
+
}
|
13 |
+
|
14 |
+
try {
|
15 |
+
Write-Log "Startup model check initiated..."
|
16 |
+
Set-Location $PROJECT_DIR
|
17 |
+
|
18 |
+
# Run a quick check (won't retrain unless needed)
|
19 |
+
$result = python -m src.main --pipeline update 2>&1
|
20 |
+
Write-Log "Update result: $result"
|
21 |
+
|
22 |
+
if ($result -like "*retraining*") {
|
23 |
+
# Show notification if models were updated
|
24 |
+
Add-Type -AssemblyName System.Windows.Forms
|
25 |
+
[System.Windows.Forms.MessageBox]::Show("UFC models were updated with new data!", "Model Update", "OK", "Information")
|
26 |
+
}
|
27 |
+
|
28 |
+
} catch {
|
29 |
+
Write-Log "Error during startup check: $($_.Exception.Message)"
|
30 |
+
}
|
31 |
+
|
32 |
+
Write-Log "Startup check completed."
|
scripts/update_models.ps1
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# UFC Model Update Script for Windows Task Scheduler
|
2 |
+
# This script safely updates models with resource limits
|
3 |
+
|
4 |
+
# Configuration
|
5 |
+
$PROJECT_DIR = "C:\Users\Alvaro\Desktop\ufc" # Change this to your actual path
|
6 |
+
$LOG_DIR = "$PROJECT_DIR\logs"
|
7 |
+
$LOG_FILE = "$LOG_DIR\model_update.log"
|
8 |
+
$LOCK_FILE = "$LOG_DIR\update.lock"
|
9 |
+
$MAX_TIMEOUT_MINUTES = 120 # 2 hours timeout
|
10 |
+
|
11 |
+
# Create logs directory if it doesn't exist
|
12 |
+
if (!(Test-Path $LOG_DIR)) {
|
13 |
+
New-Item -ItemType Directory -Path $LOG_DIR -Force
|
14 |
+
}
|
15 |
+
|
16 |
+
# Function to log with timestamp
|
17 |
+
function Write-Log {
|
18 |
+
param($Message)
|
19 |
+
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
|
20 |
+
"[$timestamp] $Message" | Out-File -FilePath $LOG_FILE -Append
|
21 |
+
Write-Host "[$timestamp] $Message"
|
22 |
+
}
|
23 |
+
|
24 |
+
# Check if another update is already running
|
25 |
+
if (Test-Path $LOCK_FILE) {
|
26 |
+
Write-Log "Another update process is already running. Exiting."
|
27 |
+
exit 1
|
28 |
+
}
|
29 |
+
|
30 |
+
# Create lock file
|
31 |
+
$PID | Out-File -FilePath $LOCK_FILE
|
32 |
+
|
33 |
+
try {
|
34 |
+
Write-Log "Starting model update check..."
|
35 |
+
|
36 |
+
# Change to project directory
|
37 |
+
Set-Location $PROJECT_DIR
|
38 |
+
|
39 |
+
# Create a job to run the update with timeout
|
40 |
+
$job = Start-Job -ScriptBlock {
|
41 |
+
param($projectDir)
|
42 |
+
Set-Location $projectDir
|
43 |
+
python -m src.main --pipeline update
|
44 |
+
} -ArgumentList $PROJECT_DIR
|
45 |
+
|
46 |
+
# Wait for job completion with timeout
|
47 |
+
if (Wait-Job $job -Timeout ($MAX_TIMEOUT_MINUTES * 60)) {
|
48 |
+
$result = Receive-Job $job
|
49 |
+
$exitCode = $job.State
|
50 |
+
|
51 |
+
if ($exitCode -eq "Completed") {
|
52 |
+
Write-Log "Model update completed successfully."
|
53 |
+
Write-Log "Output: $result"
|
54 |
+
} else {
|
55 |
+
Write-Log "Model update failed. State: $exitCode"
|
56 |
+
}
|
57 |
+
} else {
|
58 |
+
Write-Log "Model update timed out after $MAX_TIMEOUT_MINUTES minutes. Stopping job."
|
59 |
+
Stop-Job $job
|
60 |
+
}
|
61 |
+
|
62 |
+
Remove-Job $job -Force
|
63 |
+
|
64 |
+
} catch {
|
65 |
+
Write-Log "Error during model update: $($_.Exception.Message)"
|
66 |
+
} finally {
|
67 |
+
# Cleanup lock file
|
68 |
+
if (Test-Path $LOCK_FILE) {
|
69 |
+
Remove-Item $LOCK_FILE -Force
|
70 |
+
}
|
71 |
+
Write-Log "Update check completed."
|
72 |
+
}
|
scripts/update_models.sh
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/bin/bash
|
2 |
+
|
3 |
+
# UFC Model Update Script for Cron
|
4 |
+
# This script safely updates models with resource limits
|
5 |
+
|
6 |
+
# Configuration
|
7 |
+
PROJECT_DIR="/path/to/your/ufc" # Change this to your actual path
|
8 |
+
LOG_FILE="$PROJECT_DIR/logs/model_update.log"
|
9 |
+
LOCK_FILE="$PROJECT_DIR/logs/update.lock"
|
10 |
+
MAX_MEMORY="4G" # Limit memory usage
|
11 |
+
NICE_LEVEL="10" # Lower priority (higher number = lower priority)
|
12 |
+
|
13 |
+
# Create logs directory if it doesn't exist
|
14 |
+
mkdir -p "$PROJECT_DIR/logs"
|
15 |
+
|
16 |
+
# Function to log with timestamp
|
17 |
+
log() {
|
18 |
+
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" >> "$LOG_FILE"
|
19 |
+
}
|
20 |
+
|
21 |
+
# Check if another update is already running
|
22 |
+
if [ -f "$LOCK_FILE" ]; then
|
23 |
+
log "Another update process is already running. Exiting."
|
24 |
+
exit 1
|
25 |
+
fi
|
26 |
+
|
27 |
+
# Create lock file
|
28 |
+
echo $$ > "$LOCK_FILE"
|
29 |
+
|
30 |
+
# Cleanup function
|
31 |
+
cleanup() {
|
32 |
+
rm -f "$LOCK_FILE"
|
33 |
+
log "Update process finished."
|
34 |
+
}
|
35 |
+
|
36 |
+
# Set trap to cleanup on exit
|
37 |
+
trap cleanup EXIT
|
38 |
+
|
39 |
+
log "Starting model update check..."
|
40 |
+
|
41 |
+
# Change to project directory
|
42 |
+
cd "$PROJECT_DIR"
|
43 |
+
|
44 |
+
# Run the update with resource limits
|
45 |
+
# nice: lower CPU priority
|
46 |
+
# timeout: kill if it takes longer than 2 hours
|
47 |
+
# ulimit: limit memory usage
|
48 |
+
nice -n "$NICE_LEVEL" timeout 7200 bash -c "
|
49 |
+
ulimit -v $((4 * 1024 * 1024)) # 4GB virtual memory limit
|
50 |
+
python -m src.main --pipeline update 2>&1
|
51 |
+
" >> "$LOG_FILE" 2>&1
|
52 |
+
|
53 |
+
# Check exit code
|
54 |
+
EXIT_CODE=$?
|
55 |
+
if [ $EXIT_CODE -eq 0 ]; then
|
56 |
+
log "Model update completed successfully."
|
57 |
+
elif [ $EXIT_CODE -eq 124 ]; then
|
58 |
+
log "Model update timed out after 2 hours."
|
59 |
+
elif [ $EXIT_CODE -eq 137 ]; then
|
60 |
+
log "Model update killed due to memory limit."
|
61 |
+
else
|
62 |
+
log "Model update failed with exit code: $EXIT_CODE"
|
63 |
+
fi
|
64 |
+
|
65 |
+
log "Update check completed."
|