@@ -156,16 +156,33 @@ public static CoordinatedShutdown Get(ActorSystem sys)
156
156
public const string PhaseBeforeActorSystemTerminate = "before-actor-system-terminate" ;
157
157
public const string PhaseActorSystemTerminate = "actor-system-terminate" ;
158
158
159
-
159
+ /// <summary>
160
+ /// Common exit codes supported out of the box.
161
+ /// Note: When adding new exit codes, make sure that the exit code adheres
162
+ /// to the Linux standard.
163
+ /// See: https://manpages.ubuntu.com/manpages/lunar/man3/sysexits.h.3head.html
164
+ /// See: https://manpages.ubuntu.com/manpages/noble/man3/EXIT_SUCCESS.3const.html
165
+ /// </summary>
166
+ internal enum CommonExitCodes
167
+ {
168
+ Ok = 0 ,
169
+ UnknownReason = 1 ,
170
+ // Exit code 2 is reserved for Linux Bash for "Incorrect Usage"
171
+ ClusterDowned = 3 ,
172
+ ClusterJoinFailed = 4 ,
173
+ // Exit codes 64-78 is reserved by Linux sysexits.h
174
+ // Exit codes 126 and above is reserved by Linux shell
175
+ }
160
176
161
177
/// <summary>
162
178
/// Reason for the shutdown, which can be used by tasks in case they need to do
163
179
/// different things depending on what caused the shutdown. There are some
164
180
/// predefined reasons, but external libraries applications may also define
165
181
/// other reasons.
166
182
/// </summary>
167
- public class Reason
183
+ public abstract class Reason
168
184
{
185
+ public abstract int ExitCode { get ; }
169
186
protected Reason ( )
170
187
{
171
188
@@ -179,6 +196,8 @@ public class UnknownReason : Reason
179
196
{
180
197
public static readonly Reason Instance = new UnknownReason ( ) ;
181
198
199
+ public override int ExitCode => ( int ) CommonExitCodes . UnknownReason ;
200
+
182
201
private UnknownReason ( )
183
202
{
184
203
@@ -192,6 +211,8 @@ public class ActorSystemTerminateReason : Reason
192
211
{
193
212
public static readonly Reason Instance = new ActorSystemTerminateReason ( ) ;
194
213
214
+ public override int ExitCode => ( int ) CommonExitCodes . Ok ;
215
+
195
216
private ActorSystemTerminateReason ( )
196
217
{
197
218
@@ -205,6 +226,8 @@ public class ClrExitReason : Reason
205
226
{
206
227
public static readonly Reason Instance = new ClrExitReason ( ) ;
207
228
229
+ public override int ExitCode => ( int ) CommonExitCodes . Ok ;
230
+
208
231
private ClrExitReason ( )
209
232
{
210
233
@@ -219,6 +242,8 @@ public class ClusterDowningReason : Reason
219
242
{
220
243
public static readonly Reason Instance = new ClusterDowningReason ( ) ;
221
244
245
+ public override int ExitCode => ( int ) CommonExitCodes . ClusterDowned ;
246
+
222
247
private ClusterDowningReason ( )
223
248
{
224
249
@@ -233,6 +258,8 @@ public class ClusterLeavingReason : Reason
233
258
{
234
259
public static readonly Reason Instance = new ClusterLeavingReason ( ) ;
235
260
261
+ public override int ExitCode => ( int ) CommonExitCodes . Ok ;
262
+
236
263
private ClusterLeavingReason ( )
237
264
{
238
265
@@ -245,6 +272,9 @@ private ClusterLeavingReason()
245
272
public class ClusterJoinUnsuccessfulReason : Reason
246
273
{
247
274
public static readonly Reason Instance = new ClusterJoinUnsuccessfulReason ( ) ;
275
+
276
+ public override int ExitCode => ( int ) CommonExitCodes . ClusterJoinFailed ;
277
+
248
278
private ClusterJoinUnsuccessfulReason ( ) { }
249
279
}
250
280
@@ -646,7 +676,7 @@ internal static void InitPhaseActorSystemTerminate(ActorSystem system, Config co
646
676
{
647
677
if ( ! system . WhenTerminated . Wait ( timeout ) && ! coord . _runningClrHook )
648
678
{
649
- Environment . Exit ( 0 ) ;
679
+ Environment . Exit ( coord . ShutdownReason ? . ExitCode ?? 0 ) ;
650
680
}
651
681
} ) ;
652
682
}
@@ -665,7 +695,7 @@ internal static void InitPhaseActorSystemTerminate(ActorSystem system, Config co
665
695
}
666
696
else if ( exitClr )
667
697
{
668
- Environment . Exit ( 0 ) ;
698
+ Environment . Exit ( coord . ShutdownReason ? . ExitCode ?? 0 ) ;
669
699
return TaskEx . Completed ;
670
700
}
671
701
else
0 commit comments