Skip to content

Commit

Permalink
Added restart/reload code on push attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
Crash0v3r1de committed Jan 20, 2023
1 parent 0dd46d1 commit d759b94
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using BalenaNebraUpdater.Core;
using BalenaNebraUpdater.Tools;
using BalenaNebraUpdater.Tracking;
using System.Diagnostics;

Console.CancelKeyPress += delegate {
new LoadingUnloading().Save();
Environment.Exit(0); // User canceled program
Expand All @@ -17,7 +19,6 @@
//bel.GetFleets("key");



if (!ld.Loaded()) { // No settings - prompt for initial config
SettingsStatic.Settings.ApiKey = con.BalenaApiKey();
SettingsStatic.Settings.OrgName = belInitial.GetOrgName(SettingsStatic.Settings.ApiKey);
Expand Down Expand Up @@ -50,8 +51,10 @@
SettingsStatic.Settings.CurrentCommit = currentCommit;
try { ld.Save(); } catch { Console.WriteLine($"{DateTime.Now} | Failed to save settings after commit update - please report this as an issue on Github"); }
Discord.SendWebhook();
ReloadMyself();
}
else Console.WriteLine($"{DateTime.Now} | Commit update push failed - please report this as an issue on Github");
else Console.WriteLine($"{DateTime.Now} | Commit update push failed - please report this as an issue on Github"); ReloadMyself();
// We'll reload ourself on failure to see if maybe the token just went stale anyway
}
else
{
Expand All @@ -63,13 +66,15 @@
SettingsStatic.Settings.CurrentCommit = currentCommit;
try { ld.Save(); } catch { Console.WriteLine($"{DateTime.Now} | Failed to save settings after initial commit update - please report this as an issue on Github"); }
Discord.SendWebhook();
ReloadMyself();
}
else Console.WriteLine($"{DateTime.Now} | Initial build failed - please report this as an issue on Github");
}
else Console.WriteLine($"{DateTime.Now} | Initial build failed - please report this as an issue on Github"); ReloadMyself();
} // We'll reload ourself on failure to see if maybe the token just went stale anyway
else Console.WriteLine($"{DateTime.Now} | Update not needed");

}
} catch(Exception ex) { Console.WriteLine("FATAL ERROR! Please report an issue to github | Failed logic loop"); Logger.SaveEntry($"Logic loop failed | {ex.Message}",BalenaNebraUpdater.Objs.Enums.ErrorLevel.Fatal); }
} catch(Exception ex) { Console.WriteLine("FATAL ERROR! Please report an issue to github | Failed logic loop"); Logger.SaveEntry($"Logic loop failed | {ex.Message}",BalenaNebraUpdater.Objs.Enums.ErrorLevel.Fatal); ReloadMyself(); }
// We'll reload ourself on failure to see if maybe the token just went stale anyway

// Add console menu options to use the balenacli option, this code would then be used. Api is just better for easability
//if (git.NeedsCloned())
Expand All @@ -88,4 +93,15 @@
//}
//if (!updated) { Console.WriteLine($"{DateTime.Now} | Update not needed"); }
Thread.Sleep(3600000); // hard coded hour wait for now
}

static void ReloadMyself()
{
// This is a quick workaround for the token issues with Balena push after an initial fleet update, restart the app so the token is valid next update push
// Whenever I get time (if I get time) to get another capture of multi update pushes to balena I'll reverse it and see what changes for the second push and update this proj
try {
Process.Start(Environment.ProcessPath);
Environment.Exit(4); // We'll use exit code 4 to mark that this is basically restarting a new process
}
catch(Exception ex) { Console.WriteLine("Error occured trying to start ourself after image push"); Console.WriteLine(ex.Message); }
}

0 comments on commit d759b94

Please sign in to comment.