Make --process-required default, add ShutdownIfPossible instead

This commit is contained in:
Łukasz Domeradzki 2024-04-17 12:02:26 +02:00
parent 656c1b8d5d
commit 10986289e6
No known key found for this signature in database
GPG key ID: 6B138B4C64555AEA
7 changed files with 18 additions and 11 deletions

View file

@ -25,12 +25,15 @@ using System.Linq;
using System.Threading.Tasks;
using ArchiSteamFarm.Localization;
using ArchiSteamFarm.Steam;
using ArchiSteamFarm.Storage;
namespace ArchiSteamFarm.Core;
internal static class Events {
internal static async Task OnBotShutdown() {
if (Program.ProcessRequired || ((Bot.Bots != null) && Bot.Bots.Values.Any(static bot => bot.KeepRunning))) {
bool shutdownIfPossible = ASF.GlobalConfig?.ShutdownIfPossible ?? GlobalConfig.DefaultShutdownIfPossible;
if (!shutdownIfPossible || (Bot.Bots?.Values.Any(static bot => bot.KeepRunning) == true)) {
return;
}
@ -39,7 +42,7 @@ internal static class Events {
// We give user extra 5 seconds for eventual config changes
await Task.Delay(5000).ConfigureAwait(false);
if (Program.ProcessRequired || ((Bot.Bots != null) && Bot.Bots.Values.Any(static bot => bot.KeepRunning))) {
if (Bot.Bots?.Values.Any(static bot => bot.KeepRunning) == true) {
return;
}

View file

@ -54,7 +54,6 @@ internal static class Program {
internal static bool ConfigWatch { get; private set; } = true;
internal static bool IgnoreUnsupportedEnvironment { get; private set; }
internal static string? NetworkGroup { get; private set; }
internal static bool ProcessRequired { get; private set; }
internal static bool RestartAllowed { get; private set; } = true;
internal static bool Service { get; private set; }
internal static bool ShutdownSequenceInitialized { get; private set; }
@ -593,10 +592,6 @@ internal static class Program {
case "--NO-STEAM-PARENTAL-GENERATION" when noArgumentValueNext():
SteamParentalGeneration = false;
break;
case "--PROCESS-REQUIRED" when noArgumentValueNext():
ProcessRequired = true;
break;
case "--PATH" when noArgumentValueNext():
pathNext = true;

View file

@ -112,6 +112,9 @@ public sealed class GlobalConfig {
[PublicAPI]
public const EPluginsUpdateMode DefaultPluginsUpdateMode = EPluginsUpdateMode.Whitelist;
[PublicAPI]
public const bool DefaultShutdownIfPossible = true;
[PublicAPI]
public const string? DefaultSteamMessagePrefix = "/me ";
@ -293,6 +296,9 @@ public sealed class GlobalConfig {
[JsonInclude]
public EPluginsUpdateMode PluginsUpdateMode { get; private init; } = DefaultPluginsUpdateMode;
[JsonInclude]
public bool ShutdownIfPossible { get; private init; } = DefaultShutdownIfPossible;
[JsonInclude]
[MaxLength(SteamChatMessage.MaxMessagePrefixBytes / SteamChatMessage.ReservedEscapeMessageBytes)]
[UnconditionalSuppressMessage("AssemblyLoadTrimming", "IL2026:RequiresUnreferencedCode", Justification = "This is optional, supportive attribute, we don't care if it gets trimmed or not")]
@ -439,6 +445,9 @@ public sealed class GlobalConfig {
[UsedImplicitly]
public bool ShouldSerializePluginsUpdateMode() => !Saving || (PluginsUpdateMode != DefaultPluginsUpdateMode);
[UsedImplicitly]
public bool ShouldSerializeShutdownIfPossible() => !Saving || (ShutdownIfPossible != DefaultShutdownIfPossible);
[UsedImplicitly]
public bool ShouldSerializeSSteamOwnerID() => !Saving;

View file

@ -3,7 +3,7 @@ WantedBy=multi-user.target
[Service]
EnvironmentFile=-/etc/asf/%i
ExecStart=/home/%i/ArchiSteamFarm/ArchiSteamFarm --no-restart --process-required --service --system-required
ExecStart=/home/%i/ArchiSteamFarm/ArchiSteamFarm --no-restart --service --system-required
Restart=on-success
RestartSec=1s
SyslogIdentifier=asf-%i

View file

@ -3,7 +3,7 @@ WantedBy=multi-user.target
[Service]
EnvironmentFile=-/etc/asf/%i
ExecStart=dotnet /home/%i/ArchiSteamFarm/ArchiSteamFarm.dll --no-restart --process-required --service --system-required
ExecStart=dotnet /home/%i/ArchiSteamFarm/ArchiSteamFarm.dll --no-restart --service --system-required
Restart=on-success
RestartSec=1s
SyslogIdentifier=asf-%i

View file

@ -84,4 +84,4 @@ RUN set -eu; \
VOLUME ["/app/config", "/app/logs"]
HEALTHCHECK CMD ["pidof", "-q", "dotnet"]
ENTRYPOINT ["ArchiSteamFarm", "--no-restart", "--process-required", "--system-required"]
ENTRYPOINT ["ArchiSteamFarm", "--no-restart", "--system-required"]

View file

@ -84,4 +84,4 @@ RUN set -eu; \
VOLUME ["/app/config", "/app/logs"]
HEALTHCHECK CMD ["pidof", "-q", "ArchiSteamFarm"]
ENTRYPOINT ["ArchiSteamFarm", "--no-restart", "--process-required", "--system-required"]
ENTRYPOINT ["ArchiSteamFarm", "--no-restart", "--system-required"]