agent finished and updates servers
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -1,6 +1,11 @@
|
||||
# ---> Node
|
||||
testFiles
|
||||
builds
|
||||
.includes
|
||||
.buildNumber
|
||||
temp
|
||||
.scriptCreds
|
||||
node-v24.14.0-x64.msi
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import axios from "axios";
|
||||
import { settings } from "backend/db/schema/settings.schema.js";
|
||||
import { addHours } from "date-fns";
|
||||
import { formatInTimeZone } from "date-fns-tz";
|
||||
import { eq, sql } from "drizzle-orm";
|
||||
import { db } from "../db/db.controller.js";
|
||||
import { opendockApt } from "../db/schema/opendock.schema.js";
|
||||
import { settings } from "../db/schema/settings.schema.js";
|
||||
import { createLogger } from "../logger/logger.controller.js";
|
||||
import { prodQuery } from "../prodSql/prodSqlQuery.controller.js";
|
||||
import {
|
||||
@@ -80,9 +80,9 @@ const postRelease = async (release: Releases) => {
|
||||
: release.DeliveryState === 3 // this will consider finished and if a correction needs made to the bol we need to cancel and reactivate the order
|
||||
? "Completed"
|
||||
: release.DeliveryState === 4 && "Completed",
|
||||
userId: "2629b4f6-0003-472d-8b26-66a69ce5ac50", // this should be the carrierid
|
||||
loadTypeId: "0aa7988e-b17b-4f10-acdd-3d029b44a773", // well get this and make it a default one
|
||||
dockId: "00ba4386-ce5a-4dd1-9356-6e6d10a24609", // this the warehouse we want it in to start out
|
||||
userId: process.env.DEFAULT_CARRIER, // this should be the carrierid
|
||||
loadTypeId: process.env.DEFAULT_LOAD_TYPE, // well get this and make it a default one
|
||||
dockId: process.env.DEFAULT_DOCK, // this the warehouse we want it in to start out
|
||||
refNumbers: [release.ReleaseNumber],
|
||||
refNumber: release.ReleaseNumber,
|
||||
start: release.DeliveryDate,
|
||||
|
||||
@@ -16,6 +16,7 @@ router.get("/", async (_, res) => {
|
||||
res.status(200).json({
|
||||
status: "ok",
|
||||
uptime: process.uptime(),
|
||||
nodeVersion: process.version,
|
||||
memoryUsage: `Heap: ${(used.heapUsed / 1024 / 1024).toFixed(2)} MB / RSS: ${(
|
||||
used.rss / 1024 / 1024
|
||||
).toFixed(2)} MB`,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { requireAuth } from "backend/middleware/auth.middleware.js";
|
||||
import type { Express } from "express";
|
||||
import { requireAuth } from "../middleware/auth.middleware.js";
|
||||
import getSettings from "./settings.route.js";
|
||||
import updSetting from "./settingsUpdate.route.js";
|
||||
import stats from "./stats.route.js";
|
||||
|
||||
@@ -5,7 +5,7 @@ meta {
|
||||
}
|
||||
|
||||
post {
|
||||
url: {{url}}/lst/api/authentication/login
|
||||
url: {{url}}/api/authentication/login
|
||||
body: json
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
@@ -5,16 +5,16 @@ meta {
|
||||
}
|
||||
|
||||
post {
|
||||
url: {{url}}/lst/api/authentication/register
|
||||
url: {{url}}/authentication/register
|
||||
body: json
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
body:json {
|
||||
{
|
||||
"username": "jane005",
|
||||
"email": "jane@alpla.com",
|
||||
"password": "superSecretPassword"
|
||||
"username": "matthes01",
|
||||
"email": "blake.matthes@alpla.com",
|
||||
"password": "nova0511"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ meta {
|
||||
}
|
||||
|
||||
get {
|
||||
url: {{url}}/lst/api/datamart
|
||||
url: {{url}}/api/datamart
|
||||
body: none
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ meta {
|
||||
}
|
||||
|
||||
get {
|
||||
url: {{url}}/lst/api/datamart/:name
|
||||
url: {{url}}/api/datamart/:name
|
||||
body: none
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
vars {
|
||||
url: http://localhost:3000
|
||||
url: http://usmcd1vms036:3100
|
||||
~session_cookie:
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ meta {
|
||||
}
|
||||
|
||||
get {
|
||||
url: {{url}}/lst/api/opendock
|
||||
url: {{url}}/api/opendock
|
||||
body: none
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
@@ -5,11 +5,12 @@ meta {
|
||||
}
|
||||
|
||||
post {
|
||||
url: {{url}}/lst/api/system/prodsql/start
|
||||
url: {{url}}/api/system/prodsql/start
|
||||
body: none
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
settings {
|
||||
encodeUrl: true
|
||||
timeout: 0
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ meta {
|
||||
}
|
||||
|
||||
post {
|
||||
url: {{url}}/lst/api/system/prodsql/restart
|
||||
url: {{url}}/api/system/prodsql/restart
|
||||
body: none
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ meta {
|
||||
}
|
||||
|
||||
post {
|
||||
url: {{url}}/lst/api/system/prodsql/stop
|
||||
url: {{url}}/api/system/prodsql/stop
|
||||
body: none
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ meta {
|
||||
}
|
||||
|
||||
get {
|
||||
url: {{url}}/lst/api/settings
|
||||
url: {{url}}/api/settings
|
||||
body: none
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ meta {
|
||||
}
|
||||
|
||||
get {
|
||||
url: {{url}}/lst/api/stats
|
||||
url: {{url}}/api/stats
|
||||
body: none
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ meta {
|
||||
}
|
||||
|
||||
patch {
|
||||
url: {{url}}/lst/api/settings/opendock_sync
|
||||
url: {{url}}/api/settings/opendock_sync
|
||||
body: json
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ meta {
|
||||
}
|
||||
|
||||
get {
|
||||
url: {{url}}/lst/api/utils/croner
|
||||
url: {{url}}/api/utils/croner
|
||||
body: none
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
meta {
|
||||
name: Change status
|
||||
name: Change job status
|
||||
type: http
|
||||
seq: 2
|
||||
}
|
||||
|
||||
patch {
|
||||
url: {{url}}/lst/api/utils/croner/stop
|
||||
url: {{url}}/api/utils/croner/stop
|
||||
body: json
|
||||
auth: inherit
|
||||
}
|
||||
5
migrations/0015_neat_donald_blake.sql
Normal file
5
migrations/0015_neat_donald_blake.sql
Normal file
@@ -0,0 +1,5 @@
|
||||
CREATE TABLE "stats" (
|
||||
"id" text PRIMARY KEY DEFAULT 'serverStats' NOT NULL,
|
||||
"build" integer DEFAULT 1 NOT NULL,
|
||||
"last_update" timestamp DEFAULT now()
|
||||
);
|
||||
1147
migrations/meta/0015_snapshot.json
Normal file
1147
migrations/meta/0015_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -106,6 +106,13 @@
|
||||
"when": 1772012229060,
|
||||
"tag": "0014_heavy_kitty_pryde",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 15,
|
||||
"version": "7",
|
||||
"when": 1772415040979,
|
||||
"tag": "0015_neat_donald_blake",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -12,7 +12,7 @@
|
||||
"dev:db:generate": "tsc && npx drizzle-kit generate --config=drizzle.config.ts",
|
||||
"build": "rimraf dist && npm run dev:db:generate && npm run dev:db:migrate && npm run build:app && npm run build:copySql",
|
||||
"build:app": "tsc",
|
||||
"build:agent": "cd agent && tsc -p tsconfig.json",
|
||||
"agent": "powershell -ExecutionPolicy Bypass -File scripts/agentController.ps1",
|
||||
"build:docker": "docker compose up --force-recreate --build -d",
|
||||
"build:copySql": "xcopy backend\\prodSql\\queries dist\\backend\\prodSql\\queries\\ /E /I /Y ",
|
||||
"lint": "tsc && biome lint",
|
||||
@@ -24,6 +24,7 @@
|
||||
"version": "changeset version",
|
||||
"release": "dotenvx run -f .env -- npm run version && git push --follow-tags && node scripts/create-release.js",
|
||||
"specCheck": "node scripts/check-route-specs.mjs"
|
||||
|
||||
},
|
||||
"workspaces": [
|
||||
"backend",
|
||||
|
||||
@@ -1,18 +1,67 @@
|
||||
# param (
|
||||
# [string]$username,
|
||||
# [string]$password
|
||||
# )
|
||||
|
||||
Set-StrictMode -Version Latest
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
# .\agentController.ps1 -username "blake" -password "blake"
|
||||
# config
|
||||
$Servers = @("appserver1", "appserver2") # hostnames or IPs
|
||||
$ServiceName = "MyAppService" # Windows service name (or pm2 process name logic)
|
||||
$ServiceName = "LSTV3_app"
|
||||
$AppDir= "C:\Users\matthes01\Documents\lst_v3"
|
||||
$RemoteTempZip = "C:\Windows\Temp\release.zip"
|
||||
$RemoteReleasesRoot = "C:\App\releases"
|
||||
$RemoteCurrent = "C:\App\current"
|
||||
$KeepLast = 10 # how many builds do we want to keep.
|
||||
$Servers = @(
|
||||
[PSCustomObject]@{
|
||||
server = "uslim1vms006"
|
||||
token = "uslim1"
|
||||
loc = "E$\LST_V3"
|
||||
},
|
||||
[PSCustomObject]@{
|
||||
server = "usmcd1vms036"
|
||||
token = "uslim1"
|
||||
loc = "E$\LST_V3"
|
||||
}
|
||||
#@{ server = "usmcd1vms036"; token = "test1"; loc = "E$\LST\lst_backend"; }
|
||||
#@{ server = "usiow1vms036"; token = "test1"; loc = "E$\LST\lst_backend"; }
|
||||
#@{ server = "usbet1vms006"; token = "usbet1";loc = "C$\Users\adm_matthes01\Desktop\lst_backend"; }
|
||||
#@{ server = "usbow1vms006"; token = "usbow1"; loc = "C$\Users\adm_matthes01\Desktop\lst_backend" ; }
|
||||
#@{ server = "usbow2vms006"; token = "usbow2"; loc = "C$\Users\adm_matthes01\Desktop\lst_backend" ; }
|
||||
#@{ server = "usday1vms006"; token = "usday1"; loc = "E$\LST\lst_backend" ; }
|
||||
#@{ server = "usflo1vms006"; token = "usflo1"; loc = "C$\Users\adm_matthes01\Desktop\lst_backend" ; }
|
||||
#@{ server = "ushou1vms006"; token = "ushou1"; loc = "C$\Users\adm_matthes01\Desktop\lst_backend" ;}
|
||||
#@{ server = "usiow1vms006"; token = "usiow1"; loc = "C$\Users\adm_matthes01\Desktop\lst_backend" ; }
|
||||
#@{ server = "usiow1vms006"; token = "usiow2"; loc = "D$\lst\lst_backend_2" ; }
|
||||
#@{ server = "usjci1vms006"; token = "usjci1"; loc = "D$\LST\lst_backend" ; }
|
||||
#@{ server = "usksc1vms006"; token = "uskc1"; loc = "C$\Users\adm_matthes01\Desktop\lst_backend" ;}
|
||||
#@{ server = "usmcd1vms006"; token = "usmcd1"; loc = "C$\Users\adm_matthes01\Desktop\lst_backend" ; }
|
||||
#@{ server = "usshe1vms006"; token = "usshe1"; loc = "C$\Users\adm_matthes01\Desktop\lst_backend" ;}
|
||||
#@{ server = "usslc1vms006"; token = "usslc1"; loc = "C$\Users\adm_matthes01\Desktop\lst_backend" ;}
|
||||
#@{ server = "usstp1vms006"; token = "usstp1"; loc = "E$\LST\lst_backend" ; }
|
||||
#@{ server = "usweb1vms006"; token = "usweb1"; loc = "C$\Users\adm_matthes01\Desktop\lst_backend" ;}
|
||||
#@{ server = "usmar1vms006"; token = "test1"; loc = "E$\LST\lst_backend"; }
|
||||
|
||||
)
|
||||
#--------------------------------------------------
|
||||
# below this shouldnt really need to be messed with
|
||||
# below this shouldn't really need to be messed with
|
||||
#--------------------------------------------------
|
||||
|
||||
# create the username and password to sign into the server and do the udpate stuff
|
||||
$credFile = Join-Path $AppDir ".scriptCreds"
|
||||
$credData = @{}
|
||||
|
||||
Get-Content $credFile | ForEach-Object {
|
||||
if ($_ -match "=") {
|
||||
$key, $value = $_ -split "=", 2
|
||||
$credData[$key.Trim()] = $value.Trim()
|
||||
}
|
||||
}
|
||||
$username = $credData["user"]
|
||||
$password = $credData["password"]
|
||||
|
||||
$securePass = ConvertTo-SecureString $password -AsPlainText -Force
|
||||
$credentials = New-Object System.Management.Automation.PSCredential($username, $securePass)
|
||||
|
||||
function Show-Menu {
|
||||
Clear-Host
|
||||
Write-Host "==============================="
|
||||
@@ -26,51 +75,320 @@ function Show-Menu {
|
||||
}
|
||||
|
||||
function Select-Server {
|
||||
param([string[]]$List)
|
||||
param([object[]]$List)
|
||||
for ($i = 0; $i -lt $List.Count; $i++) {
|
||||
Write-Host ("{0}. {1}" -f ($i+1), $List[$i])
|
||||
Write-Host ("{0}. {1}" -f ($i+1), $List[$i].server)
|
||||
}
|
||||
Write-Host "$($List.Count + 1) All"
|
||||
Write-Host "$($List.Count + 2) exit"
|
||||
|
||||
$sel = Read-Host "Select server by number"
|
||||
|
||||
if ($sel -eq $List.Count + 1) {
|
||||
return "all"
|
||||
}
|
||||
|
||||
if ($sel -eq $List.Count + 2) {
|
||||
return $null
|
||||
}
|
||||
if ($sel -match '^\d+$' -and [int]$sel -ge 1 -and [int]$sel -le $List.Count) {
|
||||
return $List[[int]$sel - 1]
|
||||
} else {
|
||||
Write-Host "Invalid selection"
|
||||
Read-Host -Prompt "Press Enter to continue..."
|
||||
Select-Server -List $Servers
|
||||
return $null
|
||||
}
|
||||
}
|
||||
|
||||
function Build-App {
|
||||
try {
|
||||
Push-Location $AppDir
|
||||
Write-Host "Running: npm run build in $AppDir"
|
||||
npm run build
|
||||
Start-Sleep -Seconds 3
|
||||
Write-Host "Build completed successfully."
|
||||
}
|
||||
catch {
|
||||
Write-Host "Build failed: $_"
|
||||
throw
|
||||
}
|
||||
finally {
|
||||
Pop-Location
|
||||
}
|
||||
}
|
||||
|
||||
function Zip-App {
|
||||
$BuildNumber = "1"
|
||||
$buildFile = Join-Path $AppDir ".buildNumber"
|
||||
|
||||
# validate we have a build file and create it if not there
|
||||
if (-Not (Test-Path $buildfile)) {
|
||||
Write-Error "File not found: $buildfile, creating it."
|
||||
New-Item -Path $buildfile -ItemType File | Out-Null
|
||||
$BuildNumber = "1"
|
||||
Set-Content -Path $BuildFile -Value $BuildNumber
|
||||
}
|
||||
|
||||
#bump the build number
|
||||
if (Test-Path $BuildFile) {
|
||||
$content = Get-Content $BuildFile | Select-Object -First 1
|
||||
$num = $content.Trim() -as [int] # safe cast
|
||||
|
||||
if ($num) {
|
||||
$BuildNumber = $num + 1
|
||||
} else {
|
||||
$BuildNumber = 1
|
||||
}
|
||||
}
|
||||
$BuildNumber = $BuildNumber.ToString()
|
||||
Set-Content -Path $BuildFile -Value $BuildNumber
|
||||
Write-Output "New Build Number: $BuildNumber"
|
||||
|
||||
# get the include data
|
||||
$Includes = Join-Path $AppDir ".includes"
|
||||
if (-Not (Test-Path $Includes)) {
|
||||
Write-Error "File not found: $Includes, exiting as we dont want to zip up the entire app."
|
||||
exit 1
|
||||
}
|
||||
|
||||
$BuildFolder = Join-Path $AppDir "builds"
|
||||
|
||||
if (-Not (Test-Path $BuildFolder)) {
|
||||
write-host "Build folder missing creating it"
|
||||
New-Item -Path $BuildFolder -ItemType Directory | Out-Null
|
||||
}
|
||||
|
||||
# do the zip stuff
|
||||
$itemsToZip = @()
|
||||
Get-Content $Includes | ForEach-Object {
|
||||
$relPath = $_.Trim()
|
||||
if ($relPath -ne "") {
|
||||
$fullPath = Join-Path $AppDir $relPath
|
||||
if (Test-Path $fullPath) {
|
||||
$itemsToZip += [PSCustomObject]@{
|
||||
FullPath = $fullPath
|
||||
RelativePath = $relPath
|
||||
}
|
||||
} else {
|
||||
Write-Warning "Path not found: $fullPath"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (-Not $itemsToZip) {
|
||||
Write-Warning "No valid files or folders to zip."
|
||||
return
|
||||
}
|
||||
|
||||
$zipFileName = Join-Path $BuildFolder "LSTV3-$BuildNumber.zip"
|
||||
|
||||
if (Test-Path $zipFileName) {
|
||||
Remove-Item $zipFileName
|
||||
}
|
||||
|
||||
$tempFolder = Join-Path $AppDir "temp\zip-temp-$BuildNumber"
|
||||
if (Test-Path $tempFolder) { Remove-Item $tempFolder -Recurse -Force }
|
||||
New-Item -Path $tempFolder -ItemType Directory | Out-Null
|
||||
|
||||
foreach ($item in $itemsToZip) {
|
||||
$dest = Join-Path $tempFolder $item.RelativePath
|
||||
$destDir = Split-Path $dest
|
||||
if (-Not (Test-Path $destDir)) { New-Item -Path $destDir -ItemType Directory | Out-Null }
|
||||
|
||||
if ((Get-Item $item.FullPath).PSIsContainer) {
|
||||
Copy-Item -Path $item.FullPath -Destination $dest -Recurse
|
||||
} else {
|
||||
Copy-Item -Path $item.FullPath -Destination $dest
|
||||
}
|
||||
}
|
||||
|
||||
Compress-Archive -Path (Join-Path $tempFolder "*") -DestinationPath $zipFileName
|
||||
|
||||
# Cleanup temp folder
|
||||
Remove-Item $tempFolder -Recurse -Force
|
||||
|
||||
Write-Output "Created zip: $zipFileName"
|
||||
|
||||
#clean up builds to not get overwhelmed
|
||||
|
||||
if (Test-Path $BuildFolder) {
|
||||
# Get all zip files in build folder matching pattern
|
||||
$zips = @(Get-ChildItem -Path $BuildFolder -Filter "LSTV3-*.zip" |
|
||||
Sort-Object LastWriteTime -Descending)
|
||||
|
||||
$toRemove = $zips | Select-Object -Skip $KeepLast
|
||||
|
||||
foreach ($zip in $toRemove) {
|
||||
Remove-Item $zip.FullName -Force
|
||||
Write-Output "Removed old build: $($zip.Name)"
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function Update-Server {
|
||||
param (
|
||||
[string]$Destination,
|
||||
[string]$Server,
|
||||
[string]$Token
|
||||
)
|
||||
$buildFile = Join-Path $AppDir ".buildNumber"
|
||||
$BuildNumber = 1
|
||||
$BuildFolder = Join-Path $AppDir "builds"
|
||||
|
||||
if (Test-Path $BuildFile) {
|
||||
$content = Get-Content $BuildFile | Select-Object -First 1
|
||||
$num = $content.Trim() -as [int] # safe cast
|
||||
|
||||
if ($num) {
|
||||
$BuildNumber = $num + 1
|
||||
}
|
||||
else {
|
||||
$BuildNumber = 1
|
||||
}
|
||||
}
|
||||
|
||||
# Get The current Build we have zipped up
|
||||
$BuildNumber = ([int]$BuildNumber - 1).ToString()
|
||||
|
||||
|
||||
# copy the latest build over
|
||||
Write-Host "Forcing the removal of the mapped drive."
|
||||
Get-PSDrive -Name "z" -ErrorAction SilentlyContinue | Remove-PSDrive -Force
|
||||
|
||||
try {
|
||||
|
||||
New-PSDrive -Name "z" -PSProvider FileSystem -Root "\\$Server\$Destination" -Credential $credentials
|
||||
|
||||
# Create the update folder if it doesn't exist
|
||||
if (-not (Test-Path -Path "\\$Server\$Destination")) {
|
||||
New-Item -ItemType Directory -Path "\\$Server\$Destination" -Force
|
||||
}
|
||||
|
||||
# Copying files to the server
|
||||
Write-Host "Copying files to $($Server)"
|
||||
$zipFile = Join-Path $BuildFolder "LSTV3-$BuildNumber.zip"
|
||||
Copy-Item -Path $zipFile -Destination "z:\" -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"
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host "Updating the app to LSTV3-$BuildNumber.zip"
|
||||
# do the stop services, unzip, and restart service and pool
|
||||
$AppUpdate = {
|
||||
param ($Server, $Token, $Destination, $BuildFile)
|
||||
|
||||
#convert everything to the server fun
|
||||
$LocalPath = $Destination -replace '\$', ':'
|
||||
$BuildFileLoc = "$LocalPath\$BuildFile"
|
||||
|
||||
Write-Host "Updating the app to $($BuildFile)"
|
||||
|
||||
Write-Host "Stopping the services to do the updates, pkgs and db changes."
|
||||
$app_name = "LSTV3_app$(if ($Token -eq "usiow2") { "_2" })"
|
||||
|
||||
# TODO: add in the iis reset later
|
||||
|
||||
Write-Host "Stopping $($app_name)"
|
||||
Stop-Service -DisplayName $app_name -Force
|
||||
Start-Sleep -Seconds 1
|
||||
|
||||
Write-Host "Unzipping the folder..."
|
||||
|
||||
try {
|
||||
# Expand the archive
|
||||
Expand-Archive -Path $BuildFileLoc -DestinationPath $LocalPath -Force
|
||||
}
|
||||
catch {
|
||||
Write-Host "Error: $_"
|
||||
exit 1 # Exit with a non-zero code if there's an error
|
||||
}
|
||||
|
||||
# Delete the zip file after extraction
|
||||
Write-Host "Deleting the zip file..."
|
||||
Remove-Item -Path $BuildFileLoc -Force
|
||||
Start-Sleep -Seconds 1
|
||||
|
||||
try {
|
||||
# do the install/update
|
||||
Push-Location $LocalPath
|
||||
Write-Host "Running install/update in: $LocalPath"
|
||||
npm install
|
||||
Start-Sleep -Seconds 3
|
||||
Write-Host "Install/update completed."
|
||||
# do the migrations
|
||||
Push-Location $LocalPath
|
||||
Write-Host "Running migrations"
|
||||
npm run dev:db:migrate
|
||||
Start-Sleep -Seconds 3
|
||||
Write-Host "Migrations Completed."
|
||||
}
|
||||
catch {
|
||||
Write-Host "Migration: $_"
|
||||
}
|
||||
finally {
|
||||
Pop-Location
|
||||
}
|
||||
|
||||
|
||||
Write-Host "Starting $($app_name)"
|
||||
Start-Service -DisplayName $app_name -ErrorAction Stop
|
||||
Start-Sleep -Seconds 1
|
||||
|
||||
}
|
||||
|
||||
Invoke-Command -ComputerName $Server -ScriptBlock $AppUpdate -ArgumentList $Server, $Token, $Destination, "LSTV3-$BuildNumber.zip" -Credential $credentials
|
||||
}
|
||||
|
||||
do {
|
||||
Show-Menu
|
||||
$choice = Read-Host "Select an option"
|
||||
|
||||
switch ($choice) {
|
||||
"1" {
|
||||
try {
|
||||
Push-Location $AppDir
|
||||
Write-Host "Running: npm run build in $AppDir"
|
||||
npm run build
|
||||
|
||||
Write-Host "Build completed successfully."
|
||||
Read-Host -Prompt "Press Enter to continue..."
|
||||
}
|
||||
catch {
|
||||
Write-Host "Build failed: $_"
|
||||
throw
|
||||
}
|
||||
finally {
|
||||
Pop-Location
|
||||
}
|
||||
Build-App
|
||||
Zip-App
|
||||
Read-Host -Prompt "Press Enter to continue..."
|
||||
}
|
||||
"2" {
|
||||
$server = Select-Server -List $Servers
|
||||
if ($null -ne $server) {
|
||||
$zip = Read-Host "Path to zip (local)"
|
||||
Deploy-ToServer -Server $server -ZipPath $zip
|
||||
|
||||
if($server -eq "all") {
|
||||
Write-Host "Updating all servers"
|
||||
for ($i = 0; $i -lt $Servers.Count; $i++) {
|
||||
Write-Host "Updating $($Servers[$i].server)"
|
||||
Update-Server -Server $Servers[$i].server -Destination $Servers[$i].loc -Token $Servers[$i].token
|
||||
Start-Sleep -Seconds 1
|
||||
}
|
||||
Read-Host -Prompt "Press Enter to continue..."
|
||||
}
|
||||
|
||||
if ($server -ne "all") {
|
||||
Write-Host "You selected $($server.server)"
|
||||
# do the update to the server.
|
||||
# copy to the server
|
||||
Update-Server -Server $server.server -Destination $server.loc -Token $server.token
|
||||
# stop service
|
||||
# extract zip
|
||||
# run update check
|
||||
# run migration
|
||||
# start service backup
|
||||
|
||||
Read-Host -Prompt "Press Enter to continue..."
|
||||
}
|
||||
}
|
||||
"3" {
|
||||
Write-Host "Restart selected"
|
||||
psql -h localhost -p 5433 -U adm_cowch -d lst_dev -c "SELECT count(*) FROM public.logs;"
|
||||
}
|
||||
"4" {
|
||||
Write-Host "Exiting..."
|
||||
|
||||
@@ -6,5 +6,205 @@ param (
|
||||
[string]$description,
|
||||
[string]$remote,
|
||||
[string]$server,
|
||||
[string]$username,
|
||||
[string]$admpass
|
||||
)
|
||||
|
||||
# Example string to run with the parameters in it.
|
||||
# .\scripts\services.ps1 -serviceName "LSTV3_app" -option "install" -appPath "E:\LST_V3" -description "Logistics Support Tool" -command "run start"
|
||||
|
||||
$nssmPath = $AppPath + "\nssm.exe"
|
||||
$npmPath = "C:\Program Files\nodejs\npm.cmd" # Path to npm.cmd
|
||||
|
||||
if ($remote -eq "true") {
|
||||
# Convert the plain-text password to a SecureString
|
||||
$securePass = ConvertTo-SecureString $admpass -AsPlainText -Force
|
||||
$credentials = New-Object System.Management.Automation.PSCredential($username, $securePass)
|
||||
|
||||
# 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
|
||||
& $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 "$($appPath)\logs\service.log"
|
||||
& $nssmPath set $serviceName AppStderr "$($appPath)\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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user