Compare commits
7 Commits
5a95bf3ef0
...
8e039037a9
| Author | SHA1 | Date | |
|---|---|---|---|
| 8e039037a9 | |||
| ed40f4c77e | |||
| ccddef8ba8 | |||
| 05e31f4b9e | |||
| d2578b8850 | |||
| 392a9ef407 | |||
| 2d2337257f |
14
.env-example
14
.env-example
@@ -1,14 +1,18 @@
|
|||||||
# uncomment this out to run in productions
|
# uncomment this out to run in productions
|
||||||
# APP_ENV=production
|
# APP_ENV=production
|
||||||
|
|
||||||
|
# lstv2 loc
|
||||||
|
LSTV2="C\drive\loc"
|
||||||
|
|
||||||
|
# dev stuff below
|
||||||
|
|
||||||
# Gitea Info
|
# Gitea Info
|
||||||
GITEA_URL=git repo
|
GITEA_URL=git repo
|
||||||
GITEA_USERNAME=username
|
GITEA_USERNAME=username
|
||||||
GITEA_REPO=logistics_support_tool
|
GITEA_REPO=logistics_support_tool
|
||||||
GITEA_TOKEN=ad8eac91a01e3a1885a1dc10
|
GITEA_TOKEN=ad8eac91a01e3a1885a1dc10
|
||||||
|
|
||||||
# Build number info
|
# dev locs
|
||||||
BUILD_NAME=rushjnnhj7212n
|
DEV_FOLDER=C\drive\loc
|
||||||
|
ADMUSER=username
|
||||||
# lstv2 loc
|
ADMPASSWORD=password
|
||||||
LSTV2=C\drive\loc
|
|
||||||
@@ -26,10 +26,10 @@ if (Test-Path $envFile) {
|
|||||||
Write-Host ".env file not found at $envFile"
|
Write-Host ".env file not found at $envFile"
|
||||||
}
|
}
|
||||||
|
|
||||||
if (-not $env:BUILD_NAME) {
|
# if (-not $env:BUILD_NAME) {
|
||||||
Write-Warning "BUILD_NAME environment variable is not set. Please make sure you have entered the correct info the env"
|
# Write-Warning "BUILD_NAME environment variable is not set. Please make sure you have entered the correct info the env"
|
||||||
exit 1
|
# exit 1
|
||||||
}
|
# }
|
||||||
|
|
||||||
function Get-PackageVersion {
|
function Get-PackageVersion {
|
||||||
param (
|
param (
|
||||||
@@ -78,7 +78,7 @@ function Update-BuildNumber {
|
|||||||
$name = $matches[2]
|
$name = $matches[2]
|
||||||
|
|
||||||
$newNumber = $number + 1
|
$newNumber = $number + 1
|
||||||
$newBuildNumber = "$newNumber-$name"
|
$newBuildNumber = "$newNumber"
|
||||||
|
|
||||||
Set-Content -Path $buildNumberFile -Value $newBuildNumber
|
Set-Content -Path $buildNumberFile -Value $newBuildNumber
|
||||||
|
|
||||||
@@ -95,14 +95,14 @@ function Update-BuildNumber {
|
|||||||
Push-Location $rootDir/backend
|
Push-Location $rootDir/backend
|
||||||
Write-Host "Building the app"
|
Write-Host "Building the app"
|
||||||
go get
|
go get
|
||||||
go build -ldflags "-X main.version=$($version)-$($initialBuildValue)" -o lst_backend.exe ./main.go
|
go build -ldflags "-X main.version=$($version)-$($initialBuildValue)" -o lst_app.exe ./main.go
|
||||||
if ($LASTEXITCODE -ne 0) {
|
if ($LASTEXITCODE -ne 0) {
|
||||||
Write-Warning "Backend build failed!"
|
Write-Warning "app build failed!"
|
||||||
Pop-Location
|
Pop-Location
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "Backend build finished successfully."
|
Write-Host "app build finished successfully."
|
||||||
|
|
||||||
Pop-Location
|
Pop-Location
|
||||||
|
|
||||||
@@ -123,10 +123,10 @@ function Update-BuildNumber {
|
|||||||
Write-Host "Building wrapper"
|
Write-Host "Building wrapper"
|
||||||
Push-Location $rootDir/LstWrapper
|
Push-Location $rootDir/LstWrapper
|
||||||
#remove the publish folder as we done need it
|
#remove the publish folder as we done need it
|
||||||
if (-not (Test-Path "/publish")) {
|
if (-not (Test-Path "publish")) {
|
||||||
Write-Host "The publish folder is already deleted nothing else to do"
|
Write-Host "The publish folder is already deleted nothing else to do"
|
||||||
} else {
|
} else {
|
||||||
Remove-Item -LiteralPath "/publish" -Force -Recurse
|
Remove-Item -LiteralPath "publish" -Force -Recurse
|
||||||
}
|
}
|
||||||
|
|
||||||
dotnet publish -c Release -o ./publish
|
dotnet publish -c Release -o ./publish
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ $tempStageDir = New-Item -ItemType Directory -Path (Join-Path $env:TEMP "lst_sta
|
|||||||
|
|
||||||
# Copy files to organized structure
|
# Copy files to organized structure
|
||||||
$filesToCopy = @(
|
$filesToCopy = @(
|
||||||
@{ Source = "backend\lst_backend.exe"; Destination = "app\lst_backend.exe" },
|
@{ Source = "backend\lst_app.exe"; Destination = "app\lst_app.exe" },
|
||||||
@{ Source = "backend\docs"; Destination = "app\docs\" },
|
@{ Source = "backend\docs"; Destination = "app\docs\" },
|
||||||
@{ Source = "backend\frontend"; Destination = "app\frontend\" },
|
@{ Source = "backend\frontend"; Destination = "app\frontend\" },
|
||||||
@{ Source = "LstWrapper\publish"; Destination = "lstwrapper\" },
|
@{ Source = "LstWrapper\publish"; Destination = "lstwrapper\" },
|
||||||
@@ -85,6 +85,7 @@ $filesToCopy = @(
|
|||||||
# scripts to be copied over
|
# scripts to be copied over
|
||||||
@{ Source = "scripts\tmp"; Destination = "tmp" }
|
@{ Source = "scripts\tmp"; Destination = "tmp" }
|
||||||
@{ Source = "scripts\iisControls.ps1"; Destination = "scripts\iisControls.ps1" }
|
@{ Source = "scripts\iisControls.ps1"; Destination = "scripts\iisControls.ps1" }
|
||||||
|
@{ Source = "scripts\services.ps1"; Destination = "scripts\services.ps1" }
|
||||||
# docs
|
# docs
|
||||||
# @{ Source = "lst-docs\build"; Destination = "lst-docs\build" }
|
# @{ Source = "lst-docs\build"; Destination = "lst-docs\build" }
|
||||||
)
|
)
|
||||||
@@ -103,7 +104,7 @@ Remove-Item $tempStageDir -Recurse -Force
|
|||||||
|
|
||||||
Write-Host "`nRelease package created at: $($zipPath)"
|
Write-Host "`nRelease package created at: $($zipPath)"
|
||||||
Write-Host "Organized structure:"
|
Write-Host "Organized structure:"
|
||||||
Write-Host "- backend/"
|
Write-Host "- app/"
|
||||||
Write-Host "- frontend/"
|
Write-Host "- frontend/"
|
||||||
Write-Host "- lstwrapper/"
|
Write-Host "- lstwrapper/"
|
||||||
Write-Host "- scripts/"
|
Write-Host "- scripts/"
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ param (
|
|||||||
[string]$StopOrStart
|
[string]$StopOrStart
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Example string to run with the parameters in it.
|
||||||
|
# .\iisControls.ps1 -ServerName "usmcd1vms036" -AppPoolName "LogisticsSupportTool" -StopOrStart "stop"
|
||||||
|
|
||||||
write-host $StopOrStart
|
write-host $StopOrStart
|
||||||
if ($StopOrStart -eq "stop") {
|
if ($StopOrStart -eq "stop") {
|
||||||
Invoke-Command -ComputerName $ServerName -Credential $cred -ScriptBlock {
|
Invoke-Command -ComputerName $ServerName -Credential $cred -ScriptBlock {
|
||||||
|
|||||||
@@ -36,11 +36,20 @@ function Build-LstV2-And-Copy {
|
|||||||
New-Item -Path $scriptDir -Name "tmp" -ItemType "Directory"
|
New-Item -Path $scriptDir -Name "tmp" -ItemType "Directory"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$defaultChoice = "n"
|
||||||
|
$input = Read-Host "Do we want to build lstV2? (Y/n) [$defaultChoice]"
|
||||||
|
|
||||||
|
$choice = if ([string]::IsNullOrWhiteSpace($input)) { $defaultChoice } else { $input.ToLower() }
|
||||||
|
|
||||||
|
if($choice -eq "n"){
|
||||||
|
Write-Host "Just going to copy the latest build over as we dont want to build a new one."
|
||||||
|
} else {
|
||||||
Write-Host "Jumping into lstV2 to build it."
|
Write-Host "Jumping into lstV2 to build it."
|
||||||
Push-Location $lstv2Loc
|
Push-Location $lstv2Loc
|
||||||
npm run build
|
npm run build
|
||||||
|
|
||||||
Write-Host "LSTV2 Finished building."
|
Write-Host "LSTV2 Finished building."
|
||||||
|
}
|
||||||
|
|
||||||
Write-Host "Copy the latest build to the tmpLoc"
|
Write-Host "Copy the latest build to the tmpLoc"
|
||||||
|
|
||||||
|
|||||||
207
scripts/services.ps1
Normal file
207
scripts/services.ps1
Normal file
@@ -0,0 +1,207 @@
|
|||||||
|
param (
|
||||||
|
[string]$serviceName,
|
||||||
|
[string]$option,
|
||||||
|
[string]$appPath,
|
||||||
|
[string]$command, # just the command like run start or what ever you have in npm.
|
||||||
|
[string]$description,
|
||||||
|
[string]$remote,
|
||||||
|
[string]$server,
|
||||||
|
[string]$username,
|
||||||
|
[string]$admpass
|
||||||
|
)
|
||||||
|
|
||||||
|
# Example string to run with the parameters in it.
|
||||||
|
# .\scripts\services.ps1 -serviceName "LST_app" -option "install" -appPath "E:\LST" -description "Logistics Support Tool in go" -command "E:\LST\app\lst_app.exe"
|
||||||
|
|
||||||
|
$nssmPath = $AppPath + "\nssm.exe"
|
||||||
|
$npmPath = "C:\Program Files\nodejs\npm.cmd" # Path to npm.cmd
|
||||||
|
|
||||||
|
# Convert the plain-text password to a SecureString
|
||||||
|
$securePass = ConvertTo-SecureString $admpass -AsPlainText -Force
|
||||||
|
$credentials = New-Object System.Management.Automation.PSCredential($username, $securePass)
|
||||||
|
|
||||||
|
if($remote -eq "true"){
|
||||||
|
|
||||||
|
# if(-not $username -or -not $admpass){
|
||||||
|
# Write-host "Missing adm account info please try again."
|
||||||
|
# exit 1
|
||||||
|
# }
|
||||||
|
|
||||||
|
$plantFunness = {
|
||||||
|
param ($service, $processType, $location)
|
||||||
|
# Call your PowerShell script inside plantFunness
|
||||||
|
# & "$($location)\dist\server\scripts\services.ps1" -serviceName $service -option $processType -appPath $location
|
||||||
|
|
||||||
|
if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
|
||||||
|
Write-Host "Error: This script must be run as Administrator."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if(-not $service -or -not $processType){
|
||||||
|
Write-host "The service name or option is missing please enter one of them and try again."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($processType -eq "start"){
|
||||||
|
write-host "Starting $($service)."
|
||||||
|
Start-Service $service
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($processType -eq "stop"){
|
||||||
|
write-host "Stoping $($service)."
|
||||||
|
Stop-Service $service
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($processType -eq "restart"){
|
||||||
|
write-host "Stoping $($service) to be restarted"
|
||||||
|
Stop-Service $service
|
||||||
|
Start-Sleep 3 # so we give it enough time to fully stop
|
||||||
|
write-host "Starting $($service)"
|
||||||
|
Start-Service $service
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($processType -eq "prodStop"){
|
||||||
|
if(-not $location){
|
||||||
|
Write-host "The path to the app is missing please add it in and try again."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
& $nssmPath stop $service
|
||||||
|
write-host "Removing $($service)"
|
||||||
|
#& $nssmPath remove $serviceName confirm
|
||||||
|
sc.exe config $service start= disabled
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($processType -eq "prodStart"){
|
||||||
|
if(-not $location){
|
||||||
|
Write-host "The path to the app is missing please add it in and try again."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
& $nssmPath start $service
|
||||||
|
write-host "Removing $($service)"
|
||||||
|
#& $nssmPath remove $serviceName confirm
|
||||||
|
sc.exe config $service start= auto
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Invoke-Command -ComputerName $server -ScriptBlock $plantFunness -ArgumentList $serviceName, $option, $appPath -Credential $credentials
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
|
||||||
|
Write-Host "Error: This script must be run as Administrator."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if(-not $serviceName -or -not $option){
|
||||||
|
Write-host "The service name or option is missing please enter one of them and try again."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($option -eq "start"){
|
||||||
|
write-host "Starting $($serviceName)."
|
||||||
|
Start-Service $serviceName
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($option -eq "stop"){
|
||||||
|
write-host "Stoping $($serviceName)."
|
||||||
|
Stop-Service $serviceName
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($option -eq "restart"){
|
||||||
|
write-host "Stoping $($serviceName) to be restarted"
|
||||||
|
Stop-Service $serviceName
|
||||||
|
Start-Sleep 3 # so we give it enough time to fully stop
|
||||||
|
write-host "Starting $($serviceName)"
|
||||||
|
Start-Service $serviceName
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($option -eq "delete"){
|
||||||
|
if(-not $appPath){
|
||||||
|
Write-host "The path to the app is missing please add it in and try again."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
& $nssmPath stop $serviceName
|
||||||
|
write-host "Removing $($serviceName)"
|
||||||
|
& $nssmPath remove $serviceName confirm
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($option -eq "prodStop"){
|
||||||
|
if(-not $appPath){
|
||||||
|
Write-host "The path to the app is missing please add it in and try again."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
& $nssmPath stop $serviceName
|
||||||
|
write-host "Removing $($serviceName)"
|
||||||
|
#& $nssmPath remove $serviceName confirm
|
||||||
|
sc.exe config $serviceName start= disabled
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($option -eq "prodStart"){
|
||||||
|
if(-not $appPath){
|
||||||
|
Write-host "The path to the app is missing please add it in and try again."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
& $nssmPath start $serviceName
|
||||||
|
write-host "Removing $($serviceName)"
|
||||||
|
#& $nssmPath remove $serviceName confirm
|
||||||
|
sc.exe config $serviceName start= auto
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if($option -eq "install"){
|
||||||
|
if(-not $appPath -or -not $description -or -not $command){
|
||||||
|
Write-host "Please check all parameters are passed to install the app.."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$service = Get-Service -Name $serviceName -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
|
if(-not $service){
|
||||||
|
write-host $serviceName "is not installed we will install it now"
|
||||||
|
|
||||||
|
Write-Host "Installing $serviceName..."
|
||||||
|
if($command.Contains(".exe")){
|
||||||
|
|
||||||
|
& $nssmPath install $serviceName $command
|
||||||
|
|
||||||
|
$fullAppPath = "$appPath\app"
|
||||||
|
& $nssmPath set $serviceName AppDirectory $fullAppPath
|
||||||
|
}else {
|
||||||
|
& $nssmPath install $serviceName $npmPath $command
|
||||||
|
& $nssmPath set $serviceName AppDirectory $appPath
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
& $nssmPath set $serviceName Description $description
|
||||||
|
& $nssmPath set $serviceName AppStdout "E:\LST\logs\service.log"
|
||||||
|
& $nssmPath set $serviceName AppStderr "E:\LST\logs\service-error.log"
|
||||||
|
& $nssmPath set $serviceName DependOnService "MSSQLSERVER"
|
||||||
|
# Set recovery options
|
||||||
|
sc.exe failure $serviceName reset= 0 actions= restart/5000/restart/5000/restart/5000
|
||||||
|
& $nssmPath start $serviceName
|
||||||
|
}else{
|
||||||
|
write-host $serviceName "is already installed will push the updated info"
|
||||||
|
Write-Host "Updating $serviceName..."
|
||||||
|
& $nssmPath stop $serviceName
|
||||||
|
|
||||||
|
if($command.Contains(".exe")){
|
||||||
|
$fullAppPath = "$appPath\app"
|
||||||
|
& $nssmPath set $serviceName AppDirectory $fullAppPath
|
||||||
|
}else {
|
||||||
|
& $nssmPath set $serviceName AppDirectory $appPath
|
||||||
|
}
|
||||||
|
|
||||||
|
& $nssmPath set $serviceName Description $description
|
||||||
|
# & $nssmPath set $serviceName DependOnService "IISADMIN MSSQLSERVER"
|
||||||
|
# Set recovery options
|
||||||
|
sc.exe failure $serviceName reset= 0 actions= restart/5000/restart/5000/restart/5000
|
||||||
|
Start-Sleep 4
|
||||||
|
& $nssmPath start $serviceName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
245
scripts/updateServer.ps1
Normal file
245
scripts/updateServer.ps1
Normal file
@@ -0,0 +1,245 @@
|
|||||||
|
param (
|
||||||
|
[string]$server,
|
||||||
|
[string]$token,
|
||||||
|
[string]$location,
|
||||||
|
[string]$devFolder,
|
||||||
|
[string]$serverIP,
|
||||||
|
[string]$build,
|
||||||
|
[string]$type,
|
||||||
|
[string]$username,
|
||||||
|
[string]$admpass,
|
||||||
|
[string]$obslst,
|
||||||
|
[string]$obsBuild
|
||||||
|
)
|
||||||
|
|
||||||
|
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition
|
||||||
|
$rootDir = Join-Path $scriptDir ".."
|
||||||
|
|
||||||
|
# example run script is
|
||||||
|
# .\updateServer.ps1 -username "username" -admpass "password" -token "test3" -server "usmcd1vms036" -serverIP "10.193.0.56" -build "C:\Users\matthes01\Documents\logistics_support_tool\releases" -location "E:\LST"
|
||||||
|
|
||||||
|
# Convert the plain-text password to a SecureString
|
||||||
|
$securePass = ConvertTo-SecureString $admpass -AsPlainText -Force
|
||||||
|
$credentials = New-Object System.Management.Automation.PSCredential($username, $securePass)
|
||||||
|
|
||||||
|
# lets get the version of the app we are updating
|
||||||
|
$pkgFile = "$rootDir\package.json"
|
||||||
|
$package = Get-Content -Path $pkgFile -Raw | ConvertFrom-Json
|
||||||
|
$buildNumberFile = Join-Path $rootDir "BUILD_NUMBER"
|
||||||
|
|
||||||
|
if (Test-Path $buildNumberFile) {
|
||||||
|
$buildNumber = Get-Content $buildNumberFile -Raw
|
||||||
|
$buildNumber = $buildNumber.Trim()
|
||||||
|
Write-Host "Current build number: $buildNumber"
|
||||||
|
} else {
|
||||||
|
Write-Warning "BUILD_NUMBER file not found at $buildNumberFile"
|
||||||
|
}
|
||||||
|
|
||||||
|
$version = "$($package.version)-$($buildNumber)"
|
||||||
|
|
||||||
|
# Checking to make sure the server is up and online
|
||||||
|
Write-Output "Checking if $($token) is online to update."
|
||||||
|
$pingResult = Test-Connection -ComputerName $serverIP -Count 2 -Quiet
|
||||||
|
|
||||||
|
if (-not $pingResult) {
|
||||||
|
Write-Output "Server $($server) $($serverIP) is NOT reachable. Exiting script."
|
||||||
|
exit 1 # Terminate the script with a non-zero exit code
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Output "Server $($server) ($serverIP) is online."
|
||||||
|
|
||||||
|
|
||||||
|
$buildZip = "release-v$version.zip"
|
||||||
|
if (-Not (Test-Path -Path "$($build)\$($buildZip)")) {
|
||||||
|
Write-Host "Build is missing from the build folder."
|
||||||
|
Write-host $buildZip
|
||||||
|
exit
|
||||||
|
} else {
|
||||||
|
Write-Host "We have the build lets move to next step"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Write-Host "Starting the update Process"
|
||||||
|
Write-Host "File to be copied over is $buildZip"
|
||||||
|
Write-Host "Coping files to $($server)"
|
||||||
|
$destination = "\\$($server)\$($location)" -replace ":", "$"
|
||||||
|
Write-Host $destination
|
||||||
|
Write-Host "Forcing the removal of the mapped drive, just incase it was lingering"
|
||||||
|
|
||||||
|
Get-PSDrive -Name "z" -ErrorAction SilentlyContinue | Remove-PSDrive -Force
|
||||||
|
|
||||||
|
|
||||||
|
# Create a mapped drive with credentials using New-PSDrive for the current session
|
||||||
|
|
||||||
|
try {
|
||||||
|
net use $server /delete /y 2>$null
|
||||||
|
#New-PSDrive -Name "z" -PSProvider FileSystem -Root $destination -Credential $credentials
|
||||||
|
New-PSDrive -Name "Z" -PSProvider FileSystem -Root $destination -Persist -Credential $credentials
|
||||||
|
|
||||||
|
# Create the update folder if it doesn't exist
|
||||||
|
if (-not (Test-Path -Path $destination)) {
|
||||||
|
New-Item -ItemType Directory -Path $destination -Force
|
||||||
|
}
|
||||||
|
|
||||||
|
# Copying files to the server
|
||||||
|
Write-Host "Copying files to $($server)"
|
||||||
|
Copy-Item -Path "$($build)\$($buildZip)" -Destination "Z:\" -Recurse -Force
|
||||||
|
Write-Host "Files copied to $($server)"
|
||||||
|
} catch {
|
||||||
|
Write-Host "Error: $_"
|
||||||
|
} finally {
|
||||||
|
# Remove the mapped drive after copying
|
||||||
|
if (Get-PSDrive -Name "Z" -ErrorAction SilentlyContinue) {
|
||||||
|
Write-Host "Removing mapped drive..."
|
||||||
|
Remove-PSDrive -Name "Z"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# create the extracted path
|
||||||
|
$extractedFolderPath = "$server\$location$(if ($token -eq "usiow2") { "_2" })"
|
||||||
|
|
||||||
|
$plantFunness = {
|
||||||
|
param ($server, $token, $location, $buildFile, $buildLoc)
|
||||||
|
|
||||||
|
$localPath = $location -replace '\$', ':'
|
||||||
|
$serverFile = "$($localPath)\$buildFile"
|
||||||
|
$serverPath = "$($localPath)"
|
||||||
|
|
||||||
|
|
||||||
|
# $appPath = $extractedFolderPath
|
||||||
|
$nssmPath = $serverPath + "\nssm.exe"
|
||||||
|
$npmPath = "C:\Program Files\nodejs\npm.cmd"
|
||||||
|
|
||||||
|
$serviceApp = "LST_app$(if ($token -eq "usiow2") { "_2" })"
|
||||||
|
#$serviceFrontEnd = "LST-frontend$(if ($token -eq "usiow2") { "_2" })"
|
||||||
|
$serviceOcme = "LST-Ocme$(if ($token -eq "usiow2") { "_2" })"
|
||||||
|
$serviceLstV2 = "LSTV2$(if ($token -eq "usiow2") { "_2" })"
|
||||||
|
|
||||||
|
Write-Host "In the plant we go!!!!!"
|
||||||
|
# $servicesScript = Join-Path $PSScriptRoot "scripts\services.ps1"
|
||||||
|
# $iisContorl = Join-Path $PSScriptRoot "scripts\iisControls.ps1"
|
||||||
|
######################################################################################
|
||||||
|
# Stop the services and iis to do the updates.
|
||||||
|
######################################################################################
|
||||||
|
Write-Host "Stopping the services to do the updates, pkgs and db changes."
|
||||||
|
|
||||||
|
Write-Host "Stopping $serviceApp"
|
||||||
|
Stop-Service -DisplayName $serviceApp -Force
|
||||||
|
Start-Sleep -Seconds 1
|
||||||
|
|
||||||
|
Write-Host "Stopping $serviceLstV2"
|
||||||
|
Stop-Service -DisplayName $serviceLstV2 -Force
|
||||||
|
Start-Sleep -Seconds 1
|
||||||
|
|
||||||
|
if($token -eq "usday1"){
|
||||||
|
Write-Host "Stopping $($serviceOcme)"
|
||||||
|
Stop-Service -DisplayName $serviceOcme -Force
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "Stopping iis application"
|
||||||
|
Stop-WebAppPool -Name LogisticsSupportTool #-ErrorAction Stop
|
||||||
|
|
||||||
|
|
||||||
|
######################################################################################
|
||||||
|
# Removing the cashed stuff to keep the folder clean.
|
||||||
|
######################################################################################
|
||||||
|
|
||||||
|
# Delete the directories after extraction
|
||||||
|
Write-Host "Deleting app and other cache stuff"
|
||||||
|
|
||||||
|
Set-Location $serverPath
|
||||||
|
if (-not (Test-Path "app")) {
|
||||||
|
Write-Host "The app folder is already deleted nothing else to do"
|
||||||
|
} else {
|
||||||
|
Remove-Item -LiteralPath "app" -Force -Recurse
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-not (Test-Path "lstWrapper")) {
|
||||||
|
Write-Host "The lstWrapper folder is already deleted nothing else to do"
|
||||||
|
} else {
|
||||||
|
Remove-Item -LiteralPath "lstWrapper" -Force -Recurse
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-not (Test-Path "scripts")) {
|
||||||
|
Write-Host "The scripts folder is already deleted nothing else to do"
|
||||||
|
} else {
|
||||||
|
Remove-Item -LiteralPath "scripts" -Force -Recurse
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-not (Test-Path "tmp")) {
|
||||||
|
Write-Host "The scripts folder is already deleted nothing else to do"
|
||||||
|
} else {
|
||||||
|
Remove-Item -LiteralPath "tmp" -Force -Recurse
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
######################################################################################
|
||||||
|
# Extract everything the cashed stuff to keep the folder clean.
|
||||||
|
######################################################################################
|
||||||
|
|
||||||
|
Write-Host "Unzipping the folder..."
|
||||||
|
try {
|
||||||
|
# Expand the archive
|
||||||
|
Expand-Archive -Path $serverFile -DestinationPath $serverPath -Force
|
||||||
|
|
||||||
|
# Delete the zip file after extraction
|
||||||
|
Write-Host "Deleting the zip file..."
|
||||||
|
Remove-Item -Path $serverFile -Force
|
||||||
|
} catch {
|
||||||
|
Write-Host "Error: $_"
|
||||||
|
exit 1 # Exit with a non-zero code if there's an error
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "Unzip the LSTV2 app"
|
||||||
|
|
||||||
|
#lstv2 loc
|
||||||
|
$lstv2 = Get-ChildItem -Path "$($localPath)\tmp" -Filter *.zip
|
||||||
|
|
||||||
|
write-host $lstv2[0].FullName
|
||||||
|
|
||||||
|
if ($lstv2.Count -eq 0) {
|
||||||
|
Write-Host "No zip files found in $localPath\tmp"
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$zipToExtract = $lstv2[0].FullName
|
||||||
|
$destination = "$localPath\lstv2"
|
||||||
|
|
||||||
|
Expand-Archive -Path $zipToExtract -DestinationPath $destination -Force
|
||||||
|
Write-Host "Extracted $zipToExtract to $destination"
|
||||||
|
|
||||||
|
$removePath = "$($localPath)\tmp"
|
||||||
|
Remove-Item -Path $removePath -Force /Y
|
||||||
|
}
|
||||||
|
|
||||||
|
######################################################################################
|
||||||
|
# Doing the update stuff.
|
||||||
|
# for now just on the old version.
|
||||||
|
######################################################################################
|
||||||
|
Push-Location $serverPath/lstv2
|
||||||
|
npm i
|
||||||
|
npm run db:migrate
|
||||||
|
|
||||||
|
######################################################################################
|
||||||
|
# Start the services and iis backup.
|
||||||
|
######################################################################################
|
||||||
|
Write-Host "Starting the services up."
|
||||||
|
|
||||||
|
Write-Host "Starting $serviceApp"
|
||||||
|
Start-Service -DisplayName $serviceApp
|
||||||
|
Start-Sleep -Seconds 1
|
||||||
|
|
||||||
|
Write-Host "Starting $serviceLstV2"
|
||||||
|
Start-Service -DisplayName $serviceLstV2
|
||||||
|
Start-Sleep -Seconds 1
|
||||||
|
|
||||||
|
if($token -eq "usday1"){
|
||||||
|
Write-Host "Starting $($serviceOcme)"
|
||||||
|
Start-Service -DisplayName $serviceOcme
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "Starting iis application"
|
||||||
|
Start-WebAppPool -Name LogisticsSupportTool
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Invoke-Command -ComputerName $server -ScriptBlock $plantFunness -ArgumentList $server, $token, $location, $buildZip, $buildLoc -Credential $credentials
|
||||||
Reference in New Issue
Block a user