generated from pi-ux-ce/dotnet_build
loop through stuck process and kill them
Gitea Actions Demo / Explore-Gitea-Actions (8.0.x) (push) Successful in 2m7s
Gitea Actions Demo / Explore-Gitea-Actions (8.0.x) (push) Successful in 2m7s
This commit is contained in:
+74
-1
@@ -1,5 +1,7 @@
|
|||||||
using System.Configuration;
|
using System.Configuration;
|
||||||
using System.Configuration.Internal;
|
using System.Configuration.Internal;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
//using Microsoft.Extensions.Configuration;
|
//using Microsoft.Extensions.Configuration;
|
||||||
namespace PrometheusServiceManager;
|
namespace PrometheusServiceManager;
|
||||||
using System.ServiceProcess;
|
using System.ServiceProcess;
|
||||||
@@ -10,13 +12,14 @@ using System.ServiceProcess;
|
|||||||
// V1.1 adding the Administrator option at the start
|
// V1.1 adding the Administrator option at the start
|
||||||
// cancelled as the program would crash , to be investigated
|
// cancelled as the program would crash , to be investigated
|
||||||
// V1.2 displaying starting complete 2025/10/15
|
// V1.2 displaying starting complete 2025/10/15
|
||||||
|
// V1.3 detect stuck processes and kill them
|
||||||
static class Program
|
static class Program
|
||||||
{
|
{
|
||||||
private static readonly Dictionary<string,string> ServicesList = ConfigurationManager.AppSettings.AllKeys.ToDictionary(key => key, key => ConfigurationManager.AppSettings[key]);
|
private static readonly Dictionary<string,string> ServicesList = ConfigurationManager.AppSettings.AllKeys.ToDictionary(key => key, key => ConfigurationManager.AppSettings[key]);
|
||||||
public static bool KeycloakHidden = true;
|
public static bool KeycloakHidden = true;
|
||||||
public static bool PostgreSqlHidden = true;
|
public static bool PostgreSqlHidden = true;
|
||||||
|
|
||||||
public static readonly string version = "V1.2";
|
public static readonly string version = "V1.3";
|
||||||
|
|
||||||
[STAThread]
|
[STAThread]
|
||||||
|
|
||||||
@@ -85,6 +88,8 @@ static class Program
|
|||||||
|
|
||||||
public static void ShutdownServices(bool keycloakRestartRequired)
|
public static void ShutdownServices(bool keycloakRestartRequired)
|
||||||
{
|
{
|
||||||
|
//DisplayNetstat();
|
||||||
|
Thread.Sleep(TimeSpan.FromSeconds(3));
|
||||||
if(!Form1.KeycloakCheckBox.Checked)
|
if(!Form1.KeycloakCheckBox.Checked)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Keycloak unchecked");
|
Console.WriteLine("Keycloak unchecked");
|
||||||
@@ -103,6 +108,25 @@ static class Program
|
|||||||
//wait 1 second before
|
//wait 1 second before
|
||||||
Thread.Sleep(TimeSpan.FromSeconds(1));
|
Thread.Sleep(TimeSpan.FromSeconds(1));
|
||||||
|
|
||||||
|
//check if there is a process still active
|
||||||
|
Process[] localByName = Process.GetProcessesByName(Service.Value);
|
||||||
|
if (localByName.Length > 0)
|
||||||
|
{
|
||||||
|
Form1.TextDisplay.Text = "there is a process running ";
|
||||||
|
Form1.TextDisplay.Update();
|
||||||
|
Thread.Sleep(TimeSpan.FromSeconds(1));
|
||||||
|
|
||||||
|
//loop through every process if multiples
|
||||||
|
foreach (Process process in localByName)
|
||||||
|
{
|
||||||
|
process.Kill();
|
||||||
|
}
|
||||||
|
|
||||||
|
Form1.TextDisplay.Text = "kill done ";
|
||||||
|
Form1.TextDisplay.Update();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//displaying end of operation
|
//displaying end of operation
|
||||||
Form1.TextDisplay.Text = "Stopping complete ! ";
|
Form1.TextDisplay.Text = "Stopping complete ! ";
|
||||||
Form1.TextDisplay.Update();
|
Form1.TextDisplay.Update();
|
||||||
@@ -157,12 +181,61 @@ static class Program
|
|||||||
//wait 1 second before
|
//wait 1 second before
|
||||||
Thread.Sleep(TimeSpan.FromSeconds(1));
|
Thread.Sleep(TimeSpan.FromSeconds(1));
|
||||||
|
|
||||||
|
//check if there is a process still active
|
||||||
|
Process[] localByName = Process.GetProcessesByName(Service.Value);
|
||||||
|
if (localByName.Length > 0)
|
||||||
|
{
|
||||||
|
Form1.TextDisplay.Text = "there is a process running ";
|
||||||
|
Form1.TextDisplay.Update();
|
||||||
|
Thread.Sleep(TimeSpan.FromSeconds(1));
|
||||||
|
|
||||||
|
//loop through every process if multiples
|
||||||
|
foreach (Process process in localByName)
|
||||||
|
{
|
||||||
|
process.Kill();
|
||||||
|
}
|
||||||
|
|
||||||
|
Form1.TextDisplay.Text = "kill done ";
|
||||||
|
Form1.TextDisplay.Update();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//displaying end of operation
|
//displaying end of operation
|
||||||
Form1.TextDisplay.Text = "Starting complete ! ";
|
Form1.TextDisplay.Text = "Starting complete ! ";
|
||||||
Form1.TextDisplay.Update();
|
Form1.TextDisplay.Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void DisplayNetstat()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
Process[] localByName = Process.GetProcessesByName("TurnaroundService.api");
|
||||||
|
if (localByName.Length > 0)
|
||||||
|
{
|
||||||
|
Form1.TextDisplay.Text = "there is a service running ";
|
||||||
|
Form1.TextDisplay.Update();
|
||||||
|
Thread.Sleep(TimeSpan.FromSeconds(2));
|
||||||
|
localByName[0].Kill();
|
||||||
|
Form1.TextDisplay.Text = "kill done ";
|
||||||
|
Form1.TextDisplay.Update();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Form1.TextDisplay.Text = "Kill failed ! ";
|
||||||
|
Form1.TextDisplay.Update();
|
||||||
|
Console.WriteLine(e);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void Main()
|
static void Main()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user