Skip to content

Commit

Permalink
Make --process-required default, add ShutdownIfPossible instead
Browse files Browse the repository at this point in the history
  • Loading branch information
JustArchi committed Apr 17, 2024
1 parent 656c1b8 commit 1098628
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 11 deletions.
7 changes: 5 additions & 2 deletions ArchiSteamFarm/Core/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@
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;
}

Expand All @@ -39,7 +42,7 @@ internal static async Task OnBotShutdown() {
// 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;
}

Expand Down
5 changes: 0 additions & 5 deletions ArchiSteamFarm/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -593,10 +592,6 @@ private static async Task<bool> ParseArgs(IReadOnlyCollection<string> args) {
case "--NO-STEAM-PARENTAL-GENERATION" when noArgumentValueNext():
SteamParentalGeneration = false;

break;
case "--PROCESS-REQUIRED" when noArgumentValueNext():
ProcessRequired = true;

break;
case "--PATH" when noArgumentValueNext():
pathNext = true;
Expand Down
9 changes: 9 additions & 0 deletions ArchiSteamFarm/Storage/GlobalConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ";

Expand Down Expand Up @@ -293,6 +296,9 @@ internal set {
[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")]
Expand Down Expand Up @@ -439,6 +445,9 @@ internal GlobalConfig() { }
[UsedImplicitly]
public bool ShouldSerializePluginsUpdateMode() => !Saving || (PluginsUpdateMode != DefaultPluginsUpdateMode);

[UsedImplicitly]
public bool ShouldSerializeShutdownIfPossible() => !Saving || (ShutdownIfPossible != DefaultShutdownIfPossible);

[UsedImplicitly]
public bool ShouldSerializeSSteamOwnerID() => !Saving;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
2 changes: 1 addition & 1 deletion Dockerfile.Service
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

0 comments on commit 1098628

Please sign in to comment.