Add Reboot to IPMonitor
This commit is contained in:
@@ -51,6 +51,7 @@ namespace IPMonitor
|
||||
force=commandArgs.Coalesce<bool>("FORCE");
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,$"FORCE={force}");
|
||||
}
|
||||
VerifyNetwork();
|
||||
String ipAddress=GetPublicIPAddress();
|
||||
UpdateIPAddress(ipAddress,force);
|
||||
}
|
||||
@@ -84,6 +85,47 @@ namespace IPMonitor
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verified that we are connected to the internet.00000000
|
||||
/// Tghe method will retry for 5 minutes and then issue a reboot
|
||||
/// </summary>
|
||||
public static void VerifyNetwork()
|
||||
{
|
||||
int MAX_RETRIES=10;
|
||||
int TIMEOUT_BETWEEN_ATTEMPTS=30000;
|
||||
bool isNetworkAvailable=false;
|
||||
|
||||
try
|
||||
{
|
||||
for(int index=0;index<MAX_RETRIES && !isNetworkAvailable;index++)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,"Checking network status...");
|
||||
isNetworkAvailable=NetworkStatus.IsNetworkAvailable();
|
||||
if(!isNetworkAvailable)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,$"The Network seems to be disconnected. Will retry after {TIMEOUT_BETWEEN_ATTEMPTS} (ms) ");
|
||||
try{Thread.Sleep(TIMEOUT_BETWEEN_ATTEMPTS);}catch{;}
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,"The network is connected.");
|
||||
}
|
||||
}
|
||||
if(!isNetworkAvailable)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,$"IPMonitor has determined that the network has been down for {(TIMEOUT_BETWEEN_ATTEMPTS*MAX_RETRIES)/60000} minutes, rebooting");
|
||||
Utility.Reboot();
|
||||
}
|
||||
}
|
||||
catch(Exception exception)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,"IPMonitor encountered an issue checking the status of the network.");
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,exception.ToString());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retains a record of current ip address in ipaddress.txt file and updates that ip address to ZoneEdit for DNS
|
||||
/// </summary>
|
||||
@@ -135,7 +177,7 @@ namespace IPMonitor
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the public IP Address
|
||||
/// Retrieves the public IP Address.
|
||||
/// </summary>
|
||||
/// <param name="ipAddress"></param>
|
||||
public static String GetPublicIPAddress()
|
||||
@@ -150,12 +192,12 @@ namespace IPMonitor
|
||||
for(int index=0;index<MAX_RETRIES && null==address;index++)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,$"Requesting IPAddress from {request}");
|
||||
if(!NetworkStatus.IsNetworkAvailable())
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("The Network seems to be disconnected. Will retry after {0} (ms) ",request,TIMEOUT_BETWEEN_ATTEMPTS));
|
||||
try{Thread.Sleep(TIMEOUT_BETWEEN_ATTEMPTS);}catch{;}
|
||||
continue;
|
||||
}
|
||||
// if(!NetworkStatus.IsNetworkAvailable())
|
||||
// {
|
||||
// MDTrace.WriteLine(LogLevel.DEBUG,$"The Network seems to be disconnected. Will retry after {TIMEOUT_BETWEEN_ATTEMPTS} (ms) ");
|
||||
// try{Thread.Sleep(TIMEOUT_BETWEEN_ATTEMPTS);}catch{;}
|
||||
// continue;
|
||||
// }
|
||||
HttpNetResponse response = HttpNetRequest.GetRequestNoEncodingV7(request);
|
||||
if(!response.Success)
|
||||
{
|
||||
|
||||
@@ -27,6 +27,31 @@ namespace MarketData.Utils
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restarts the computer ARM64
|
||||
/// -r = restart the computer
|
||||
/// </summary>
|
||||
public static void Reboot()
|
||||
{
|
||||
string arguments = "-r now";
|
||||
string shutdownProcess = "shutdown";
|
||||
ProcessStartInfo processStartInfo = new ProcessStartInfo(shutdownProcess, arguments)
|
||||
{
|
||||
CreateNoWindow = true,
|
||||
UseShellExecute = false
|
||||
};
|
||||
try
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,$"Executing {shutdownProcess} {arguments}");
|
||||
Process.Start(processStartInfo);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,$"An error was encountered executing the command: {shutdownProcess} {arguments}");
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,$"{exception.ToString()}");
|
||||
}
|
||||
}
|
||||
|
||||
public static String ThreadStateToString(Thread thread)
|
||||
{
|
||||
switch(thread.ThreadState)
|
||||
|
||||
Reference in New Issue
Block a user