build(controller): updates to not build the controller every time we update
this is incase we just want to test on a server then send this same build to all the other servers
This commit is contained in:
@@ -5,7 +5,8 @@ function Update-Server {
|
|||||||
[string]$AppRoot,
|
[string]$AppRoot,
|
||||||
[string]$Destination,
|
[string]$Destination,
|
||||||
[string]$Server,
|
[string]$Server,
|
||||||
[string]$Token
|
[string]$Token,
|
||||||
|
[string]$ControllerBuild
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -26,7 +27,8 @@ function Update-Server {
|
|||||||
|
|
||||||
if ($num) {
|
if ($num) {
|
||||||
$BuildNumber = $num + 1
|
$BuildNumber = $num + 1
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
$BuildNumber = 1
|
$BuildNumber = 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -35,7 +37,13 @@ function Update-Server {
|
|||||||
$BuildNumber = $BuildNumber - 1
|
$BuildNumber = $BuildNumber - 1
|
||||||
|
|
||||||
# Convert to string
|
# Convert to string
|
||||||
$BuildNumber = $BuildNumber.ToString()
|
if ($ControllerBuild -eq "yes") {
|
||||||
|
$BuildNumber = $BuildNumber.ToString()
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$BuildNumber = ([int]$BuildNumber - 1).ToString()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# copy the latest build over
|
# copy the latest build over
|
||||||
|
|
||||||
@@ -56,9 +64,11 @@ function Update-Server {
|
|||||||
$zipFile = Join-Path $BuildFolder "controllers-$BuildNumber.zip"
|
$zipFile = Join-Path $BuildFolder "controllers-$BuildNumber.zip"
|
||||||
Copy-Item -Path $zipFile -Destination "z:\" -Force
|
Copy-Item -Path $zipFile -Destination "z:\" -Force
|
||||||
Write-Host "Files copied to $($Server)"
|
Write-Host "Files copied to $($Server)"
|
||||||
} catch {
|
}
|
||||||
|
catch {
|
||||||
Write-Host "Error: $_"
|
Write-Host "Error: $_"
|
||||||
} finally {
|
}
|
||||||
|
finally {
|
||||||
# Remove the mapped drive after copying
|
# Remove the mapped drive after copying
|
||||||
if (Get-PSDrive -Name "z" -ErrorAction SilentlyContinue) {
|
if (Get-PSDrive -Name "z" -ErrorAction SilentlyContinue) {
|
||||||
Write-Host "Removing mapped drive..."
|
Write-Host "Removing mapped drive..."
|
||||||
@@ -68,73 +78,78 @@ function Update-Server {
|
|||||||
|
|
||||||
# do the stop services, unzip, and restart service and pool
|
# do the stop services, unzip, and restart service and pool
|
||||||
|
|
||||||
$ControllerUpdate = {
|
$ControllerUpdate = {
|
||||||
param ($Server, $Token, $Destination, $BuildFile)
|
param ($Server, $Token, $Destination, $BuildFile)
|
||||||
|
|
||||||
|
|
||||||
write-host "Running the update process now"
|
write-host "Running the update process now"
|
||||||
# Change the destination to be local
|
# Change the destination to be local
|
||||||
$LocalPath = $Destination -replace '\$', ':'
|
$LocalPath = $Destination -replace '\$', ':'
|
||||||
$BuildFileLoc = "$LocalPath\$BuildFile"
|
$BuildFileLoc = "$LocalPath\$BuildFile"
|
||||||
|
|
||||||
# where is nssm.exe
|
# where is nssm.exe
|
||||||
$nssmPath= Join-Path $LocalPath "nssm.exe"
|
#$nssmPath = Join-Path $LocalPath "nssm.exe"
|
||||||
$npmPath = "C:\Program Files\nodejs\npm.cmd"
|
#$npmPath = "C:\Program Files\nodejs\npm.cmd"
|
||||||
|
|
||||||
Write-Host "Stopping the services to do the updates, pkgs and db changes."
|
Write-Host "Stopping the services to do the updates, pkgs and db changes."
|
||||||
|
|
||||||
$Controller = "LST_ctl$(if ($Token -eq "usiow2") { "_2" })"
|
$Controller = "LST_ctl$(if ($Token -eq "usiow2") { "_2" })"
|
||||||
$Wrapper = "LogisticsSupportTool$(if ($token -eq "usiow2") { "_2" })"
|
$Wrapper = "LogisticsSupportTool$(if ($token -eq "usiow2") { "_2" })"
|
||||||
|
|
||||||
Write-Host "Stopping $($Controller)"
|
Write-Host "Stopping $($Controller)"
|
||||||
Stop-Service -DisplayName $Controller -Force
|
Stop-Service -DisplayName $Controller -Force
|
||||||
Start-Sleep -Seconds 1
|
Start-Sleep -Seconds 1
|
||||||
|
|
||||||
try {
|
Write-Host "Stopping $($Wrapper)"
|
||||||
Stop-WebAppPool -Name $Wrapper -ErrorAction Stop
|
try {
|
||||||
|
Stop-WebAppPool -Name $Wrapper -ErrorAction Stop
|
||||||
|
|
||||||
Start-Sleep -Seconds 2
|
Start-Sleep -Seconds 2
|
||||||
$state = (Get-WebAppPoolState -Name $Wrapper).Value
|
$state = (Get-WebAppPoolState -Name $Wrapper).Value
|
||||||
Write-Host "Result: $state"
|
Write-Host "Result: $state"
|
||||||
} catch {
|
}
|
||||||
Write-Error $_.Exception.Message
|
catch {
|
||||||
}
|
Write-Error $_.Exception.Message
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Write-Host "Unzipping the folder..."
|
Write-Host "Unzipping the folder..."
|
||||||
write-host $BuildFileLoc
|
#write-host $BuildFileLoc
|
||||||
write-host $LocalPath
|
#write-host $LocalPath
|
||||||
|
|
||||||
# Extract the files to the build path
|
# Extract the files to the build path
|
||||||
try {
|
try {
|
||||||
# Expand the archive
|
# Expand the archive
|
||||||
Expand-Archive -Path $BuildFileLoc -DestinationPath $LocalPath -Force
|
Expand-Archive -Path $BuildFileLoc -DestinationPath $LocalPath -Force
|
||||||
} catch {
|
}
|
||||||
Write-Host "Error: $_"
|
catch {
|
||||||
exit 1 # Exit with a non-zero code if there's an error
|
Write-Host "Error: $_"
|
||||||
}
|
exit 1 # Exit with a non-zero code if there's an error
|
||||||
|
}
|
||||||
|
|
||||||
# Delete the zip file after extraction
|
# Delete the zip file after extraction
|
||||||
Write-Host "Deleting the zip file..."
|
Write-Host "Deleting the zip file..."
|
||||||
Remove-Item -Path $BuildFileLoc -Force
|
Remove-Item -Path $BuildFileLoc -Force
|
||||||
|
|
||||||
Start-Sleep -Seconds 1
|
Start-Sleep -Seconds 1
|
||||||
|
|
||||||
Write-Host "Starting $($Controller)"
|
Write-Host "Starting $($Controller)"
|
||||||
Start-Service -DisplayName $Controller
|
Start-Service -DisplayName $Controller
|
||||||
Start-Sleep -Seconds 1
|
Start-Sleep -Seconds 1
|
||||||
|
|
||||||
try {
|
Write-Host "Starting $($Wrapper)"
|
||||||
Start-WebAppPool -Name $Wrapper
|
try {
|
||||||
Start-Sleep -Seconds 2
|
Start-WebAppPool -Name $Wrapper
|
||||||
$state = (Get-WebAppPoolState -Name $Wrapper).Value
|
Start-Sleep -Seconds 2
|
||||||
Write-Host "Result: $state"
|
$state = (Get-WebAppPoolState -Name $Wrapper).Value
|
||||||
} catch {
|
Write-Host "Result: $state"
|
||||||
Write-Error $_.Exception.Message
|
}
|
||||||
exit 1
|
catch {
|
||||||
}
|
Write-Error $_.Exception.Message
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
write-host "Controllers updated and restarted :D"
|
write-host "Controllers updated and restarted :D"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
param (
|
param (
|
||||||
[string]$App_Path = "C:\Users\matthes01\Documents\lst", # with this it makes it optional to pass a new parameter over.
|
[string]$App_Path = "C:\Users\matthes01\Documents\lst", # with this it makes it optional to pass a new parameter over.
|
||||||
[string]$Server = "usmcd1vms036",
|
|
||||||
[string]$Token = "test3",
|
[string]$Token = "test3",
|
||||||
[string]$Remote_Path = "E$\LST"
|
[string]$Remote_Path = "E$\LST",
|
||||||
|
[string]$BuildController = "yes",
|
||||||
|
[string]$PlantToUpdate = "all"
|
||||||
)
|
)
|
||||||
|
|
||||||
# imports of the other functions
|
# imports of the other functions
|
||||||
@@ -11,7 +12,19 @@ param (
|
|||||||
. ".\update-controller-server"
|
. ".\update-controller-server"
|
||||||
|
|
||||||
# example string to pass over, you must be in the script dir when you run this script. or it will fail to find the linked scripts
|
# example string to pass over, you must be in the script dir when you run this script. or it will fail to find the linked scripts
|
||||||
# .\update-controllers.ps1 -App_Path "C:\Users\matthes01\Documents\lst" -Server "usmcd1vms036" -Token "test3" -Remote_Path "E$\LST"
|
|
||||||
|
# If we do not pass plant to update over it will auto do all plants if we want a specific plant we need to do like below
|
||||||
|
# .\update-controllers.ps1 -App_Path "C:\Users\matthes01\Documents\lst" -Token "test3" -BuildController no -PlantToUpdate "usmcd1vms006" -Remote_Path "E$\LST"
|
||||||
|
|
||||||
|
$Plants = @(
|
||||||
|
@{ Server = "usmcd1vms036"; Token = "test3"; Remote_Path = "E$\LST"}
|
||||||
|
@{ Server = "usmar1vms006"; Token = "usmar1" ; Remote_Path = "E$\LST"}
|
||||||
|
@{ Server = "usbet1vms006"; Token = "usbet1"; Remote_Path = "E$\LST" }
|
||||||
|
@{ Server = "usbow1vms006"; Token = "usbow1" ; Remote_Path = "E$\LST"}
|
||||||
|
@{ Server = "usslc1vms006"; Token = "usslc1" ; Remote_Path = "E$\LST"}
|
||||||
|
@{ Server = "usstp1vms006"; Token = "usstp1" ; Remote_Path = "D$\LST"}
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
$EnvFile = Join-Path $App_Path ".env"
|
$EnvFile = Join-Path $App_Path ".env"
|
||||||
if (-Not (Test-Path $EnvFile)) {
|
if (-Not (Test-Path $EnvFile)) {
|
||||||
@@ -63,7 +76,7 @@ else {
|
|||||||
if (![string]::IsNullOrWhiteSpace($content)) {
|
if (![string]::IsNullOrWhiteSpace($content)) {
|
||||||
$BuildNumber = $content.Trim()
|
$BuildNumber = $content.Trim()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -77,35 +90,64 @@ if (-Not (Test-Path $ControlIncludes)) {
|
|||||||
|
|
||||||
# last one to make sure we have is the build folder
|
# last one to make sure we have is the build folder
|
||||||
$BuildFolder = Join-Path $App_Path "controllerBuilds"
|
$BuildFolder = Join-Path $App_Path "controllerBuilds"
|
||||||
|
|
||||||
if (-Not (Test-Path $BuildFolder)) {
|
if (-Not (Test-Path $BuildFolder)) {
|
||||||
write-host "Build folder missing creating it"
|
write-host "Build folder missing creating it"
|
||||||
New-Item -Path $BuildFolder -ItemType Directory | Out-Null
|
New-Item -Path $BuildFolder -ItemType Directory | Out-Null
|
||||||
}
|
}
|
||||||
|
|
||||||
# now we can create the zip
|
# only rebuild if we push yes over
|
||||||
Zip-Includes -IncludesFile $ControlIncludes -BuildNumber $BuildNumber -BuildFolder $BuildFolder -AppRoot $App_Path
|
if ($BuildController -eq "yes") {
|
||||||
Start-Sleep -Seconds 3
|
# now we can create the zip
|
||||||
#------------------------------------------------------------------------------------
|
Zip-Includes -IncludesFile $ControlIncludes -BuildNumber $BuildNumber -BuildFolder $BuildFolder -AppRoot $App_Path
|
||||||
|
Start-Sleep -Seconds 3
|
||||||
# Checking to make sure the server is up and online
|
|
||||||
Write-Output "Checking if $($Token) is online to update."
|
|
||||||
$pingResult = Test-Connection -ComputerName $Server -Count 2 -Quiet
|
|
||||||
|
|
||||||
if (-not $pingResult) {
|
|
||||||
Write-Output "Server $($Server), token $($Token) is NOT reachable. Exiting script."
|
|
||||||
exit 1 # Terminate the script with a non-zero exit code
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
Write-Output "Server $($Server), token $($Token) is online."
|
$BuildNumber = ([int]$BuildNumber - 1).ToString()
|
||||||
|
}
|
||||||
|
#------------------------------------------------------------------------------------
|
||||||
|
|
||||||
# now that the server is up lets update the server with the current build
|
# now that the server is up lets update the server with the current build
|
||||||
# do the update to the plant.
|
# do the update to the plant.
|
||||||
Update-Server -ADM_USER $ADM_USER -ADM_PASS $ADM_PASS -AppRoot $App_Path -Destination $Remote_Path -Server $Server -Token $Token
|
if ($PlantToUpdate -ne "all") {
|
||||||
|
|
||||||
|
# Checking to make sure the server is up and online
|
||||||
|
Write-Output "Checking if $($Token) is online to update."
|
||||||
|
$pingResult = Test-Connection -ComputerName $Server -Count 2 -Quiet
|
||||||
|
|
||||||
|
if (-not $pingResult) {
|
||||||
|
Write-Output "Server $($PlantToUpdate), token $($Token) is NOT reachable. Exiting script."
|
||||||
|
exit 1 # Terminate the script with a non-zero exit code
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Output "Server $($PlantToUpdate), token $($Token) is online."
|
||||||
|
|
||||||
|
Update-Server -ADM_USER $ADM_USER -ADM_PASS $ADM_PASS -AppRoot $App_Path -Destination $Remote_Path -Server $PlantToUpdate -Token $Token -ControllerBuild $BuildController
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
foreach ($plant in $Plants) {
|
||||||
|
|
||||||
|
# Checking to make sure the server is up and online
|
||||||
|
Write-Output "Checking if $($plant.Token) is online to update."
|
||||||
|
$pingResult = Test-Connection -ComputerName $plant.Server -Count 2 -Quiet
|
||||||
|
|
||||||
|
if (-not $pingResult) {
|
||||||
|
Write-Output "Server $($plant.Server), token $($plant.Token) is NOT reachable. Exiting script."
|
||||||
|
exit 1 # Terminate the script with a non-zero exit code
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Output "Server $($plant.Server), token $($plant.Token) is online."
|
||||||
|
Write-Output "Plant to update: $($plant.Token)"
|
||||||
|
Update-Server -ADM_USER $ADM_USER -ADM_PASS $ADM_PASS -AppRoot $App_Path -Destination $plant.Remote_Path -Server $plant.Server -Token $plant.Token
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# bump the build number
|
# bump the build number
|
||||||
$BuildNumber = Bump-Build -AppRoot $App_Path
|
if ($BuildController -eq "yes") {
|
||||||
|
$BuildNumber = Bump-Build -AppRoot $App_Path
|
||||||
|
}
|
||||||
|
|
||||||
# function to create the zip controller-1.zip
|
# function to create the zip controller-1.zip
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user