Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Sadhill94/7a36c03e5a247396cbc98de74bb25012 to your computer and use it in GitHub Desktop.
Save Sadhill94/7a36c03e5a247396cbc98de74bb25012 to your computer and use it in GitHub Desktop.
A script for lazy people. Close the dex(if open), kill all your lnd process active, delete your lnd log files and clean your debug.log
#Requires -RunAsAdministrator
### Script used for:
### Kill all lnd process.exe that are listed below. It will also close the dex if it's still running
### Delete all lnd.log files in your assets folder
### Clean debug.log file
### How to run
### 1.Script must be run in Admin mode
### 2. If you get an 'execution of scripts is disabled on this system' error, please run once the command below to activate unsigned scripts
### set-executionpolicy remotesigned
$logFolderAbsolutePath = "$env:LOCALAPPDATA\Stakenet\stakenet-wallet"
$coinsLogsRelativePath = "$logFolderAbsolutePath\lnd\COIN_ACRONYM\logs\COIN_NAME\mainnet"
$lndLogFileName = "lnd.log"
$coinsList = @(
[pscustomobject]@{Acronym='btc';Name='bitcoin'}
[pscustomobject]@{Acronym='xsn';Name='xsncoin'}
[pscustomobject]@{Acronym='ltc';Name='litecoin'}
)
## kill Stakenet dex if still active
Kill-Lnd-Process-If-Running "Stakenet"
## kills all processs
foreach($process in $coinsList){
Kill-Lnd-Process-If-Running "lnd_$($process.Acronym)"
}
## delete all lnd.log file for each asset
foreach($coin in $coinsList){
$currentCoinLndLogPath = $coinsLogsRelativePath.replace('COIN_ACRONYM',$coin.Acronym).replace('COIN_NAME', $coin.Name)
if(Does-Path-Exist $currentCoinLndLogPath){
Delete-File-If-Exist "$currentCoinLndLogPath\*" $lndLogFileName
} else {
Write-Warning "Lnd Folder for $coin not found"
}
}
## clear debug.log
Clear-Content-File-If-Exist $logFolderAbsolutePath debug.log
## Functions
function Kill-Lnd-Process-If-Running {
param([string]$processName)
$lndProcess = Get-Process -Name $processName -ErrorAction SilentlyContinue
if($lndProcess){
$lndProcess | Stop-Process -Force
Write-Information "Process $processName stopped"
}
}
function Does-Path-Exist {
param([string]$path)
return Test-Path -Path $path
}
function Delete-File-If-Exist {
param([string]$path, [string]$fileName)
if(Test-Path -Path "$path" -Include $fileName) {
Remove-Item "$path" -Include $fileName
Write-Information "File in $path successfully deleted"
}
}
function Clear-Content-File-If-Exist {
param([string]$path, [string]$fileName)
if(Test-Path -Path "$path\*" -Include $fileName) {
Clear-Content $path"\"$fileName
Write-Information "file $fileName cleaned"
} else {
Write-Warning "file $fileName not found"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment