test(services): testing remove restart and stop
This commit is contained in:
@@ -125,7 +125,9 @@ export default function ServerPage() {
|
|||||||
token={token as string}
|
token={token as string}
|
||||||
/>
|
/>
|
||||||
<StartServer />
|
<StartServer />
|
||||||
<StopServer />
|
<StopServer
|
||||||
|
plantData={server}
|
||||||
|
/>
|
||||||
<RestartServer />
|
<RestartServer />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -1,14 +1,46 @@
|
|||||||
import {Button} from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import {Tooltip, TooltipContent, TooltipProvider, TooltipTrigger} from "@/components/ui/tooltip";
|
import {
|
||||||
import {Octagon} from "lucide-react";
|
Tooltip,
|
||||||
|
TooltipContent,
|
||||||
|
TooltipProvider,
|
||||||
|
TooltipTrigger,
|
||||||
|
} from "@/components/ui/tooltip";
|
||||||
|
import axios from "axios";
|
||||||
|
import { Octagon } from "lucide-react";
|
||||||
|
|
||||||
export default function StopServer() {
|
export default function StopServer(plantData: any) {
|
||||||
|
const token = localStorage.getItem("auth_token");
|
||||||
|
const handleStopServer = async (plant: string) => {
|
||||||
|
let data: any = {
|
||||||
|
processType: "stop",
|
||||||
|
plantToken: plant,
|
||||||
|
};
|
||||||
|
const url: string = window.location.host.split(":")[0];
|
||||||
|
if (url === "localhost") {
|
||||||
|
data = { ...data, remote: "true" };
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const res = await axios.post("/api/server/serviceprocess", data, {
|
||||||
|
headers: { Authorization: `Bearer ${token}` },
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(res);
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
};
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<TooltipProvider>
|
<TooltipProvider>
|
||||||
<Tooltip>
|
<Tooltip>
|
||||||
<TooltipTrigger asChild>
|
<TooltipTrigger asChild>
|
||||||
<Button variant={"outline"} size={"icon"}>
|
<Button
|
||||||
|
variant="destructive"
|
||||||
|
size={"icon"}
|
||||||
|
onClick={() =>
|
||||||
|
handleStopServer(plantData.plantToken)
|
||||||
|
}
|
||||||
|
>
|
||||||
<Octagon />
|
<Octagon />
|
||||||
</Button>
|
</Button>
|
||||||
</TooltipTrigger>
|
</TooltipTrigger>
|
||||||
|
|||||||
@@ -1,23 +1,34 @@
|
|||||||
import {Button} from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import {CircleFadingArrowUp} from "lucide-react";
|
import { CircleFadingArrowUp } from "lucide-react";
|
||||||
import {toast} from "sonner";
|
import { toast } from "sonner";
|
||||||
import {Servers} from "./ServerPage";
|
import { Servers } from "./ServerPage";
|
||||||
import {useQuery} from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import {getSettings} from "@/utils/querys/settings";
|
import { getSettings } from "@/utils/querys/settings";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import {Tooltip, TooltipContent, TooltipProvider, TooltipTrigger} from "@/components/ui/tooltip";
|
import {
|
||||||
|
Tooltip,
|
||||||
|
TooltipContent,
|
||||||
|
TooltipProvider,
|
||||||
|
TooltipTrigger,
|
||||||
|
} from "@/components/ui/tooltip";
|
||||||
|
|
||||||
export default function UpdateServer({server, token}: {server: Servers; token: string}) {
|
export default function UpdateServer({
|
||||||
const {data} = useQuery(getSettings(token ?? ""));
|
server,
|
||||||
|
token,
|
||||||
|
}: {
|
||||||
|
server: Servers;
|
||||||
|
token: string;
|
||||||
|
}) {
|
||||||
|
const { data } = useQuery(getSettings(token ?? ""));
|
||||||
const upgrade = async () => {
|
const upgrade = async () => {
|
||||||
let devDir = data.filter((n: any) => n.name === "devDir");
|
let devDir = data.filter((n: any) => n.name === "devDir");
|
||||||
toast.success("Server being upgraded in the background please wait.");
|
toast.success("Server being upgraded in the background please wait.");
|
||||||
try {
|
try {
|
||||||
const result = await axios.post(
|
const result = await axios.post(
|
||||||
`/api/server/update/${server.plantToken}`,
|
`/api/server/update/${server.plantToken}`,
|
||||||
{devDir: devDir[0].value},
|
{ devDir: devDir[0].value },
|
||||||
{
|
{
|
||||||
headers: {Authorization: `Bearer ${token}`},
|
headers: { Authorization: `Bearer ${token}` },
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -29,7 +40,9 @@ export default function UpdateServer({server, token}: {server: Servers; token: s
|
|||||||
toast.success(result.data.message);
|
toast.success(result.data.message);
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
toast.error(`There was an error updating the server: ${error.data.message}`);
|
toast.error(
|
||||||
|
`There was an error updating the server: ${error.data.message}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
@@ -37,7 +50,12 @@ export default function UpdateServer({server, token}: {server: Servers; token: s
|
|||||||
<TooltipProvider>
|
<TooltipProvider>
|
||||||
<Tooltip>
|
<Tooltip>
|
||||||
<TooltipTrigger asChild>
|
<TooltipTrigger asChild>
|
||||||
<Button variant={"outline"} size={"icon"} onClick={upgrade} disabled={server.isUpgrading}>
|
<Button
|
||||||
|
variant={`${server.isUpgrading ? "ghost" : "outline"}`}
|
||||||
|
size={"icon"}
|
||||||
|
onClick={upgrade}
|
||||||
|
disabled={server.isUpgrading}
|
||||||
|
>
|
||||||
<CircleFadingArrowUp />
|
<CircleFadingArrowUp />
|
||||||
</Button>
|
</Button>
|
||||||
</TooltipTrigger>
|
</TooltipTrigger>
|
||||||
|
|||||||
@@ -53,14 +53,12 @@ add in the below and change each setting area that says change me to something t
|
|||||||
|
|
||||||
```env
|
```env
|
||||||
# PORTS
|
# PORTS
|
||||||
|
PROD_PORT=4000
|
||||||
# To keep it all simple we will pass VITE to the ports that are used on both sides.
|
# To keep it all simple we will pass VITE to the ports that are used on both sides.
|
||||||
VITE_SERVER_PORT=4400
|
VITE_SERVER_PORT=4000
|
||||||
|
|
||||||
# logLevel
|
# logLevel
|
||||||
LOG_LEVEL=debug
|
LOG_LEVEL=info
|
||||||
PROD_PORT=4000
|
|
||||||
# DUE to lstv1 we need 3000
|
|
||||||
SEC_PORT=3000
|
|
||||||
# Auth stuff
|
# Auth stuff
|
||||||
SALTING=12
|
SALTING=12
|
||||||
SECRET=CHANGEME
|
SECRET=CHANGEME
|
||||||
@@ -138,6 +136,36 @@ Next use the example command below to get the service up and running.
|
|||||||
.\services.ps1 -serviceName "LSTV2" -option "install" -appPath "E:\LST\lstV2" -description "Logistics Support Tool V2" -command "run start"
|
.\services.ps1 -serviceName "LSTV2" -option "install" -appPath "E:\LST\lstV2" -description "Logistics Support Tool V2" -command "run start"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Adding servers to the mix to update on from the front end
|
||||||
|
|
||||||
|
you will need to add your servers into the serverData.json.
|
||||||
|
when the server starts up it will look at this file and make changes as needed.
|
||||||
|
below is an example of the server
|
||||||
|
|
||||||
|
```JSON
|
||||||
|
{
|
||||||
|
"sName": "Kansas City",
|
||||||
|
"serverDNS": "usksc1vms006",
|
||||||
|
"plantToken": "usksc1",
|
||||||
|
"idAddress": "10.42.9.26",
|
||||||
|
"greatPlainsPlantCode": "85",
|
||||||
|
"streetAddress": "1800 E 94th St Suite 300",
|
||||||
|
"cityState": "Kansas City, MO",
|
||||||
|
"zipcode": "64131",
|
||||||
|
"contactEmail": "example@example.com",
|
||||||
|
"contactPhone": "555-555-5555",
|
||||||
|
"customerTiAcc": "ALPL01KCINT",
|
||||||
|
"lstServerPort": "4000",
|
||||||
|
"active": false,
|
||||||
|
"serverLoc": "E:\\LST\\lstv2",
|
||||||
|
"oldVersion": "E:\\LST\\lst_backend",
|
||||||
|
"shippingHours": "[{\"early\": \"06:30\", \"late\": \"23:00\"}]",
|
||||||
|
"tiPostTime": "[{\"from\": \"24\", \"to\": \"24\"}]",
|
||||||
|
"otherSettings": [{ "specialInstructions": "" }]
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
# Migrating From V1 to V2
|
# Migrating From V1 to V2
|
||||||
|
|
||||||
## User migration
|
## User migration
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ param (
|
|||||||
[string]$appPath,
|
[string]$appPath,
|
||||||
[string]$command, # just the command like run startadm or what ever you have in npm.
|
[string]$command, # just the command like run startadm or what ever you have in npm.
|
||||||
[string]$description
|
[string]$description
|
||||||
|
[string]$remote
|
||||||
)
|
)
|
||||||
|
|
||||||
# Example string to run with the parameters in it.
|
# Example string to run with the parameters in it.
|
||||||
@@ -24,6 +25,16 @@ param (
|
|||||||
$nssmPath = $AppPath + "\nssm.exe"
|
$nssmPath = $AppPath + "\nssm.exe"
|
||||||
$npmPath = "C:\Program Files\nodejs\npm.cmd" # Path to npm.cmd
|
$npmPath = "C:\Program Files\nodejs\npm.cmd" # Path to npm.cmd
|
||||||
|
|
||||||
|
if($remote -eq "true"){
|
||||||
|
$plantFunness = {
|
||||||
|
param ($service, $processType, $location)
|
||||||
|
# Call your PowerShell script inside plantFunness
|
||||||
|
& "$($location)\dist\server\scripts\services.ps1" -serviceName $service -option $processType -appPath $location
|
||||||
|
}
|
||||||
|
|
||||||
|
Invoke-Command -ComputerName $server -ScriptBlock $plantFunness -ArgumentList $service, $option, $appPath -Credential $credentials
|
||||||
|
}
|
||||||
|
|
||||||
if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
|
if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
|
||||||
Write-Host "Error: This script must be run as Administrator."
|
Write-Host "Error: This script must be run as Administrator."
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
@@ -132,6 +132,17 @@ $plantFunness = {
|
|||||||
exit 1 # Exit with a non-zero code if there's an error
|
exit 1 # Exit with a non-zero code if there's an error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# for iowa 2 need to change the port config on the start up of nextjs server
|
||||||
|
if($token -eq "usiow2"){
|
||||||
|
$jsonPkgloc = "$($obslst)\apps\frontend\package.json"
|
||||||
|
#read the file
|
||||||
|
$jsonContent = Get-Content -Path $jsonPkgloc | ConvertFrom-Json
|
||||||
|
#change the second we want to update
|
||||||
|
$jsonContent.scripts.start = "next start -p 3001"
|
||||||
|
# convert back to json
|
||||||
|
$jsonContent | ConvertTo-Json | Set-Content -Path $jsonPkgloc
|
||||||
|
}
|
||||||
|
|
||||||
############################################################################
|
############################################################################
|
||||||
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."
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,10 @@
|
|||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"resolveJsonModule": true
|
"resolveJsonModule": true
|
||||||
},
|
},
|
||||||
"include": ["server", "scripts/**/*.ts", "testFiles/test-tiPostOrders.ts"],
|
"include": [
|
||||||
"exclude": ["node_modules", "frontend", "dist", "testFiles"]
|
"server",
|
||||||
|
"scripts/**/*.ts",
|
||||||
|
"database/testFiles/test-tiPostOrders.ts"
|
||||||
|
],
|
||||||
|
"exclude": ["node_modules", "frontend", "dist", "database/testFiles"]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user