Very low maintenance, ever since I added automatic restart scripts on a 24 hour interval and watchdog scripts to restart and log automatically whenever it notices 0% GPU use or network disconnection. I take a little hit while it restarts though.
Care to share more about these scripts? I'd find that very helpful. Thanks!
I have a script called autoexec.cmd start on logon using the Task Scheduler. Autoexec.cmd is a little take on the good times of the past. It will start the miner program and watchdog. I choose the miner program I want to use by commenting out the others using the REM command. After it has started the miner, it will run C:\Tools\watchdog.cmd which will start monitoring that the system is on the network and the GPU's are doing meaningful work. The Autoexec.cmd script will then hibernate (but still stay running) for 24 hours before it restarts the system. All this while watchdog is on another command line session monitoring the system.
As long as we are sharing scripts, here is what I use to solve "hash drop" on an 8 Vega rig running Cast (not XMR). All credit goes to the Jericho Jones/CircusDad/StellarX88. I have not encountered BSODs with this rig, but hash drop is common and occurs on average about once or twice per day. The script monitors for that drop (based on whatever custom value you input) and restarts the process. It works well, crazy well in fact.
<#
.NOTES
JJ's XMR-CAST_XMR HashRate Monitor and Restart Tool
*** IMPORTANT NOTE ***: If the script cannot kill the miner it will stop and wait for input.
Otherwise it would invoke the miner over and over until the PC ran out of memory.
In testing I have not seen it fail to kill the miner but I need to account for it.
Requirements: Elevated privilege (Run as Administrator)
Enable Powershell scripts to run.
Usage: Powershell.exe -ExecutionPolicy Bypass -File JJs_HashMonitor.ps1
Future enhancements under consideration: SMS/email alerts
Move settings out of the script and into a simple
txt file to make it easier to manage them.
#>
######################################################################################
# !! Scroll down to "USER VARIABLES SECTION"
# !! There are variables you want to review/modify for your setup
######################################################################################
$ver = "3"
######################################################################################
#################DO NOT MODIFY ANYTHING IN THE ELEVATION SECTION ####################
############################## BEGIN ELEVATION #######################################
# If you can't Elevate you're going to have a bad time...
# Get the ID and security principal of the current user account
$myWindowsID=[System.Security.Principal.WindowsIdentity]::GetCurrent()
$myWindowsPrincipal=new-object System.Security.Principal.WindowsPrincipal($myWindowsID)
# Get the security principal for the Administrator role
$adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator
# Check to see if we are currently running "as Administrator"
if ($myWindowsPrincipal.IsInRole($adminRole))
{
# We are running "as Administrator" - so change the title and background color to indicate this
$Host.UI.RawUI.WindowTitle = "JJ's XMR-CAST_XMR HashRate Monitor and Restart Tool v $ver"
$Host.UI.RawUI.BackgroundColor = "DarkBlue"
clear-host
}
else
{
# We are not running "as Administrator" - so relaunch as administrator
# Create a new process object that starts PowerShell
$newProcess = new-object System.Diagnostics.ProcessStartInfo "PowerShell";
# Specify the current script path and name as a parameter
$newProcess.Arguments = $myInvocation.MyCommand.Definition;
# Indicate that the process should be elevated
$newProcess.Verb = "runas";
# Start the new process
[System.Diagnostics.Process]::Start($newProcess) | Out-Null;
# Exit from the current, unelevated, process
exit
}
Clear-Host
Write-Host "Starting the Hash Monitor Script..."
Push-Location $PSScriptRoot
######################################################################################
################# DO NOT MODIFY ANYTHING IN THE ELEVATION SECTION ####################
################################ END ELEVATION #######################################
############# STATIC Variables - DO NOT CHANGE ##########################
$ScriptDir = Split-Path $MyInvocation.MyCommand.Path -Parent
$ScriptName = $MyInvocation.MyCommand.Name
$global:runDays = $null
$global:runHours = $null
$global:runMinutes = $null
$global:web = New-Object System.Net.WebClient
$global:maxhash = 0
$global:currHash = 0
$vidTool = @()
########## END STATIC Variables - MAKE NO CHANGES ABOVE THIS LINE #######
######################################################################################
########################### USER VARIABLES SECTION ###################################
######################################################################################
#########################################################################
# Set the REQUIRED variables for your Mining Configuration
#########################################################################
# Read this section carefully or you may end up overclocking your video
# card when you don't want to!! YOU HAVE BEEN WARNED
#########################################################################
$Logfile = "Cast_Restart_$(get-date -f yyyy-MM-dd).log" # Log what we do, delete or REMARK if you don't want logging
$global:CAST_XMRexe = "cast_xmr-vega.exe" # The miner. Expects to be in same folder as this script
$global:CAST_XMRcmdline = "-S mine.xmrpool.net:7777 -u 'YOUR_WALLET_ADDRESS.YOUR_WORKER_NAME' -p x -O 1 -G 0,1,2,3,4,5,6,7 -R -I 7 --fastswitch"
# CAST_XMR arguments. Not required, REMARK out if not needed
$CAST_XMRIP = '127.0.0.1' # IP or hostname of the machine running CAST_XMR (ALWAYS LOCAL) Remote start/restart of the miner is UNSUPPORTED.
# !! DON'T FORGET TO ENABLE THE WEBSERVER IN YOUR CONFIG FILE !!
$CAST_XMRPort = '7777' # Port CAST_XMR is listening on
##### Start Video Card Management Tools Definitions
# These will be executed in order prior to the miner
# Create as many as needed
#### Vid Tool 1
#$vidTool += 'OverdriveNTool.exe -r0 -r1 -r2 -r3 -r4 -r5 -r6 -r7 -p0Vega0 -p1Vega1 -p2Vega0 -p3Vega0 -p4Vega0 -p5Vega0 -p6Vega0 -p7Vega0'
# Expects to be in same folder as this script
# Delete or REMARK if you don't want use it
#### Vid Tool 2
#$vidTool += '[X]' # Expects to be in same folder as this script
# Delete or REMARK if you don't want use it
#### Vid Tool 3
#$vidTool += '[X]' # Expects to be in same folder as this script
# Delete or REMARK if you don't want use it
#### Vid Tool 4
#$vidTool += '[X]' # Expects to be in same folder as this script
# Delete or REMARK if you don't want use it
#### Vid Tool 5
#$vidTool += '[X]' # Expects to be in same folder as this script
# Delete or REMARK if you don't want use it
#### Vid Tool 6
#$vidTool += '[X]' # Expects to be in same folder as this script
# Delete or REMARK if you don't want use it
##### End VidTools
$global:Url = "http://$CAST_XMRIP`:$CAST_XMRPort" # <-- DO NOT CHANGE THIS !!
#########################################################################
# Set drop trigger and startup timeout
#########################################################################
$hdiff = 1000000 # This is the drop in total hash rate where we
# trigger a restart (Starting HASHRATE-$hdiff)
#
$timeout = 90 # (STARTUP ONLY)How long to wait for CAST_XMR to
# return a hashrate before we fail out and
# restart. There is no limiter on the number of restarts.
# Press CTRL-C to EXIT
#
$CAST_XMRstable = 90 # How long to wait for the hashrate to stabilize.
#
$global:vegaHash = 15000000 # Minimum vega hash rate before we also trigger
# a restart
#########################################################################
###################### END USER DEFINED VARIABLES #######################
#################### MAKE NO CHANGES BELOW THIS LINE ####################
##### BEGIN FUNCTIONS #####
function call-self
{
Start-Process -FilePath "C:\WINDOWS\system32\WindowsPowerShell\v1.0\Powershell.exe" -ArgumentList $ScriptDir\$ScriptName -WorkingDirectory $ScriptDir -NoNewWindow
EXIT
}
Function log-Write
{
Param ([string]$logstring)
If ($Logfile)
{
Add-content $Logfile -value $logstring
}
}
function reset-VegaDriver {
###################################
##### Reset Video Card driver #####
##### No error checking
Write-host "Resetting Driver..."
$timeStamp = "{0:yyyy-MM-dd_HH:mm}" -f (Get-Date)
log-Write ("$timeStamp Running Driver Reset")
$d = Get-PnpDevice| where {$_.friendlyname -like 'Radeon RX Vega'}
$d | Disable-PnpDevice -ErrorAction Ignore -Confirm:$false | Out-Null
$timeStamp = "{0:yyyy-MM-dd_HH:mm}" -f (Get-Date)
log-Write ("$timeStamp Video driver disabled")
Write-host -fore Green "Video driver disabled"
# Wait 5 seconds
Start-Sleep -s 5
$d | Enable-PnpDevice -ErrorAction Ignore -Confirm:$false | Out-Null
$timeStamp = "{0:yyyy-MM-dd_HH:mm}" -f (Get-Date)
log-Write ("$timeStamp Video driver enabled")
Write-host -fore Green "Video driver enabled"
# Wait 5 seconds
Start-Sleep -s 10
$timeStamp = "{0:yyyy-MM-dd_HH:mm}" -f (Get-Date)
log-Write ("$timeStamp Video driver reset completed")
}
Function Run-Tools ($app)
{
foreach ($item in $app)
{
$prog = ($item -split "\s", 2)
if (Test-Path $prog[0])
{
Write-host -fore Green "Starting " $prog[0]
$timeStamp = "{0:yyyy-MM-dd_HH:mm}" -f (Get-Date)
log-Write ("$timeStamp Starting $item ")
If ($prog[1]) {
Start-Process -FilePath $prog[0] -ArgumentList $prog[1] | Out-Null
}
Else
{
Start-Process -FilePath $prog[0] | Out-Null
}
Start-Sleep -s 1
}
Else
{
Write-Host -fore Red $prog[0] NOT found. This is not fatal. Continuing...
}
}
}
function start-Mining
{
##### Start CAST_XMR #####
$timeStamp = "{0:yyyy-MM-dd_HH:mm}" -f (Get-Date)
log-Write ("$timeStamp Starting CAST_XMR...")
If (Test-Path $global:CAST_XMRexe)
{
Write-Host "Starting CAST_XMR..."
If ($CAST_XMRcmdline)
{
Start-Process -FilePath $ScriptDir\$CAST_XMRexe -ArgumentList $CAST_XMRcmdline -WindowStyle Minimized
}
Else
{
Start-Process -FilePath $ScriptDir\$CAST_XMRexe
}
}
Else
{
$timeStamp = "{0:yyyy-MM-dd_HH:mm}" -f (Get-Date)
log-Write ("$timeStamp $global:CAST_XMRexe NOT FOUND.. EXITING")
Clear-Host
Write-Host -fore Red `n`n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Write-Host -fore Red " $global:CAST_XMRexe NOT found. "
Write-Host -fore Red " Can't do much without the miner now can you!"
Write-Host -fore Red " Now exploding... buh bye!"
Write-Host -fore Red !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Write-Host -NoNewLine "Press any key to continue..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
Exit
}
}
Function chk-CAST_XMR($global:Url) {
$timeStamp = "{0:yyyy-MM-dd_HH:mm}" -f (Get-Date)
log-Write ("$timeStamp Waiting for CAST_XMR HTTP daemon to start")
Write-host "Waiting for CAST_XMR HTTP daemon to start"
$flag = "False"
$web = New-Object System.Net.WebClient
$TimeStart = Get-Date -format HH:mm:ss
$timer = $timeout
DO {
Try {
$result = $web.DownloadString($global:Url)
$flag = "True"
}
Catch {
$timeEnd = Get-Date -format HH:mm:ss
$timeDiff = (New-TimeSpan -Start $timeStart -End (Get-Date -format HH:mm:ss)).TotalSeconds
If ($timeDiff -lt $timeout)
{
Write-host -fore Red "CAST_XMR not ready... Waiting up to $timer seconds."
Write-host -fore Red "Press CTRL-C to EXIT NOW"
}
If ($timeDiff -gt $timeout)
{
$timeout = 0
}
Start-Sleep -s 10
$timer = $timer - 10
}
} While (($timeout -gt 1) -And ($flag -eq "False"))
If ($flag -eq "True")
{
Clear-Host
Write-host -fore Green "`n`n`n## CAST_XMR HTTP daemon has started ##`n"
$timeStamp = "{0:yyyy-MM-dd_HH:mm}" -f (Get-Date)
log-Write ("$timeStamp CAST_XMR started successfully")
}
ElseIf ($flag -eq "False")
{
Clear-Host
Write-host -fore Red "`n`n`n!! Timed out waiting for CAST_XMR HTTP daemon to start !!`n"
start-sleep -s 10
$timeStamp = "{0:yyyy-MM-dd_HH:mm}" -f (Get-Date)
log-Write ("$timeStamp Timed out waiting for CAST_XMR HTTP daemon to start")
Start-Sleep -s 10
#Write-Host -NoNewLine "Press any key to EXIT..."
#$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
call-Self
EXIT
}
Else
{
Clear-Host
Write-host -fore Red "`n`n`n*** Unknown failure (Daemon failed to start?)... EXITING ***`n"
start-sleep -s 10
$timeStamp = "{0:yyyy-MM-dd_HH:mm}" -f (Get-Date)
log-Write ("$timeStamp Unknown failure starting CAST_XMR (Daemon failed to start?)")
Start-Sleep -s 10
#Write-Host -NoNewLine "Press any key to EXIT..."
#$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
call-Self
EXIT
}
}
function starting-Hash
{
$timeStamp = "{0:yyyy-MM-dd_HH:mm}" -f (Get-Date)
log-Write ("$timeStamp Waiting for hash rate to stabilize")
#Write-host -fore Green "Waiting for hash rate to stabilize"
#$startTestHash = 1
$currTestHash = 0
# Wait x seconds for hash rate to stabilize
while ($CAST_XMRstable -gt 0)
{
$data = $null
$total = $null
$data = @{}
$total = @{}
$rawdata = Invoke-WebRequest -UseBasicParsing -Uri $global:Url
If ($rawdata)
{
$data = $rawdata | ConvertFrom-Json
$rawtotal = $data.total_hash_rate
$total = $rawtotal
$currTestHash = $total
If (!$startTestHash)
{
$startTestHash = $currTestHash
}
Clear-Host
If ($currTestHash)
{
Write-host -fore Green "`n`nCurrent Hash Rate: $currTestHash H/s"
}
Write-host -fore Green "`n`nWaiting $CAST_XMRstable seconds for hashrate to stabilize."
Write-host -fore Green "Press CTRL-C to EXIT NOW"
Start-Sleep -s 1
$CAST_XMRstable = $CAST_XMRstable - 1
}
}
If (!$currTestHash)
{
Clear-Host
Write-host -fore Green `nCould not get hashrate... restarting
$timeStamp = "{0:yyyy-MM-dd_HH:mm}" -f (Get-Date)
log-Write ("$timeStamp Could not get hashrate... restarting")
call-Self
Exit
}
ElseIf ($currTestHash -gt $startTestHash)
{
$global:maxhash = $currTestHash
}
Else
{
$global:maxhash = $startTestHash
}
$global:currHash = $currTestHash
$global:rTarget = ($global:maxhash - $hdiff)
$timeStamp = "{0:yyyy-MM-dd_HH:mm}" -f (Get-Date)
log-Write ("$timeStamp Hash rate stabilized")
log-Write ("$timeStamp Starting Hashrate: $global:maxhash H/s Drop Target Hashrate: $global:rTarget H/s")
}
function current-Hash
{
# Check our current hashrate against low target every 60 seconds
Clear-Host
Write-host -fore Green `nHash monitoring has begun.
$timer = 0
$runTime = 0
$flag = "False"
$timeStamp = "{0:yyyy-MM-dd_HH:mm}" -f (Get-Date)
log-Write ("$timeStamp Hash monitoring has begun")
DO
{
Try {
$data = $null
$total = $null
$data = @{}
$total = @{}
Write-host -fore Green `nQuerying CAST_XMR...this can take a minute.
$rawdata = Invoke-WebRequest -UseBasicParsing -Uri $global:Url
$flag = "True"
}
Catch
{
Clear-Host
Write-host -fore Red "`nWe seem to have lost connectivity to CAST_XMR"
Write-host -fore Red "Restarting in 10 seconds"
$timeStamp = "{0:yyyy-MM-dd_HH:mm}" -f (Get-Date)
log-Write ("$timeStamp Restarting - Lost connectivity to CAST_XMR")
Start-Sleep -s 10
kill-Process ($CAST_XMRexe)
$flag = "False"
#Break
}
If ($flag -eq "False")
{
Break
}
$data = $rawdata | ConvertFrom-Json
$rawtotal = $data.total_hash_rate
$total = $rawtotal
$global:currHash = $total
refresh-Screen
Start-Sleep -s 15
$timer = ($timer + 15)
$runTime = ($timer)
} while (($global:currHash -gt $global:vegaHash) -and ($global:currHash -gt $global:rTarget))
# ($global:currVega -gt $global:vegaHash)
# ($global:currHash -gt $global:rTarget)
If ($flag -eq "True")
{
Clear-Host
# Write-host -fore Red "`n`nHash rate dropped from $global:maxhash H/s to $global:currHash H/s"
Write-host -fore Red "Vega56 hash rate: $global:currVega H/s is below $global:vegaHash H/s"
Write-host -fore Red "`nRestarting in 10 seconds"
$timeStamp = "{0:yyyy-MM-dd_HH:mm}" -f (Get-Date)
$tFormat = get-RunTime ($runTime)
#log-Write ("$timeStamp Restarting after $tFormat - Hash rate dropped from $global:maxhash H/s to $global:currHash H/s")
log-Write ("$timeStamp Restarting - Vega56 hash rate: $global:currVega H/s is below $global:vegaHash H/s")
Start-Sleep -s 10
}
}
function kill-Process ($CAST_XMRexe) {
try
{
$prog = ($CAST_XMRexe -split "\.", 2)
$prog = $prog[0]
# get CAST_XMR process
$CAST_XMRPROC = Get-Process $prog -ErrorAction SilentlyContinue
if ($CAST_XMRPROC) {
# try gracefully first
$CAST_XMRPROC.CloseMainWindow() | Out-Null
# kill after five seconds
Sleep 5
if (!$CAST_XMRPROC.HasExited) {
$CAST_XMRPROC | Stop-Process -Force | Out-Null
}
if (!$CAST_XMRPROC.HasExited) {
Write-host -fore Red "Failed to kill the process $prog"
Write-host -fore Red "`nIf we don't stop here CAST_XMR would be invoked"
Write-host -fore Red "`nover and over until the PC crashed."
Write-host -fore Red "`n`n That would be very bad."
Write-host -fore Red 'Press any key to EXIT...';
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
$timeStamp = "{0:yyyy-MM-dd_HH:mm}" -f (Get-Date)
log-Write ("$timeStamp Failed to kill $prog")
EXIT
}
Else
{
Write-host -fore Green "Successfully killed the process $prog"
$timeStamp = "{0:yyyy-MM-dd_HH:mm}" -f (Get-Date)
log-Write ("$timeStamp CAST_XMR closed successfully")
}
}
Else
{
Write-host -fore Green "`n$prog process was not found"
$timeStamp = "{0:yyyy-MM-dd_HH:mm}" -f (Get-Date)
log-Write ("$timeStamp $prog process was not found")
}
}
Catch
{
Write-host -fore Red "Failed to kill the process $prog"
Write-host -fore Red "`nIf we don't stop here CAST_XMR would be invoked"
Write-host -fore Red "`nover and over until the PC crashed."
Write-host -fore Red "`n`n That would be very bad."
Write-host -fore Red 'Press any key to EXIT...';
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
$timeStamp = "{0:yyyy-MM-dd_HH:mm}" -f (Get-Date)
log-Write ("$timeStamp Failed to kill $prog")
EXIT
}
}
Function refresh-Screen
{
Clear-Host
$tFormat = get-RunTime ($runTime)
Write-Host "=================================================="
Write-host -fore Green `nStarting Hash Rate: $global:maxhash H/s
Write-host -fore Green `nRestart Target Hash Rate: $global:rTarget H/s
Write-host -fore Green `nCurrent Hash Rate: $global:currHash H/s
Write-host -fore Green `nVega56 Hash Rate: $global:currVega H/s
Write-host -fore Green `nMonitoring Uptime: $tFormat `n
Write-Host "=================================================="
}
function resize-Console ($Width,$Height)
{
$targetWindow = (get-host).ui.rawui
$windowSize = $targetWindow.windowsize
$windowSize.height = $Height
$windowSize.width = $Width
$targetWindow.windowsize = $windowSize
$bufferSize = $targetWindow.buffersize
$bufferSize.height = $Height
$bufferSize.width = $Width
$targetWindow.buffersize = $bufferSize
}
function set-CAST_XMRVars
{
Write-host -fore Green "Setting Env Variables for CAST_XMR"
$timeStamp = "{0:yyyy-MM-dd_HH:mm}" -f (Get-Date)
log-Write ("$timeStamp Setting Env Variables for CAST_XMR")
[System.Environment]::SetEnvironmentVariable("GPU_FORCE_64BIT_PTR", "1", "User")
[System.Environment]::SetEnvironmentVariable("GPU_MAX_HEAP_SIZE", "99", "User")
[System.Environment]::SetEnvironmentVariable("GPU_MAX_ALLOC_PERCENT", "99", "User")
[System.Environment]::SetEnvironmentVariable("GPU_SINGLE_ALLOC_PERCENT", "99", "User")
Write-host -fore Green "Env Variables for CAST_XMR have been set"
$timeStamp = "{0:yyyy-MM-dd_HH:mm}" -f (Get-Date)
log-Write ("$timeStamp Env Variables for CAST_XMR have been set")
}
function get-RunTime ($sec)
{
$myTimeSpan = (new-timespan -seconds $sec)
If ($sec -ge 3600 -And $sec -lt 86400)
{
$global:runHours = $myTimeSpan.Hours
$global:runMinutes = $myTimeSpan.Minutes
Return "$global:runHours Hours $global:runMinutes Min"
}
ElseIf ($sec -ge 86400)
{
$global:runDays = $myTimeSpan.Days
$global:runHours = $myTimeSpan.Hours
$global:runMinutes = $myTimeSpan.Minutes
Return "$global:runDays Days $global:runHours Hours $global:runMinutes Min"
}
Elseif ($sec -ge 60 -And $sec -lt 3600)
{
$global:runMinutes = $myTimeSpan.Minutes
Return "$global:runMinutes Min"
}
Elseif ($sec -lt 60)
{
Return "Less than 1 minute"
}
}
##### END FUNCTIONS #####
##### MAIN - or The Fun Starts Here #####
$timeStamp = "{0:yyyy-MM-dd_HH:mm}" -f (Get-Date)
log-Write ("$timeStamp Script Started")
resize-Console 50 16
kill-Process ($CAST_XMRexe)
reset-VegaDriver ($devID)
If ($vidTool) # If $vidTool is defined
{
Run-Tools ($vidTool) # Run your tools
}
set-CAST_XMRVars # Set suggested environment variables
start-Mining # Start mining software
chk-CAST_XMR($global:Url) # Wait for CAST_XMR to return a hash rate
starting-Hash # Get the starting hash rate
current-Hash # Gather the current hash rate every 60 seconds until it drops beneath the threshold
$timeStamp = "{0:yyyy-MM-dd_HH:mm}" -f (Get-Date)
log-Write ("$timeStamp Script Ended")
call-Self # Restart the script
##### The End of the World as we know it #####
EXIT
Visit vegamining blog for the details. This script has been modified to work with Cast. There are two parts: the script above and then a .cmd file that you run and which points to this script.
VidTool is worth un-remarking out if you have one or two dud cards that need a gentler OverDriveNTool profile. I believe the above was based on StellarX88's modfications to JJ's 2.9 release. A compare between this and whatever current script JJ has released should reveal the important changes. StellarX88's mods may be found in the Vega hash rate threads.
Also, I have set a wicked large system paging file around 70000MB or roughly 8GB per Vega card + a little extra.