OnServerRestartInterrupt
OnServerRestartInterrupt is called when a pending server restart is about to be interrupted, before the restart coroutine is stopped. Returning a non-null value cancels the interruption and lets the scheduled restart continue.
object OnServerRestartInterrupt()Return value
Returning a non-null value cancels the interruption: the toast is not shown and the existing restart coroutine is not stopped, so the previously scheduled restart continues. Returning null lets the code proceed and the restart is interrupted normally.
How it works
The hook fires inside ServerMgr.RestartServer when a restart is already scheduled (a restart coroutine exists) and the game is about to cancel it. This happens when a shutdown or restart request is issued while a previous restart countdown is still running: the server shows a toast to all clients and stops the old coroutine. The hook fires before that toast and before the coroutine is stopped, so it is your last chance to veto the cancellation.
There are no parameters. The only useful output is the return value. Returning anything non-null stops the original code path immediately, which means the toast is not shown and the existing restart coroutine keeps running to completion. Returning null (or nothing, since the method returns object) lets the restart be interrupted as usual.
This hook only fires in the interrupt branch; a first-time restart request does not run it. Keep your handler fast and free of side effects that block the main thread, because it runs on the server's main thread during shutdown handling.
Example plugin: Prevent accidental cancellation of a scheduled restart
using UnityEngine;
using System.Collections.Generic;
using System;
using Newtonsoft.Json;
using Oxide.Core;
namespace Oxide.Plugins
{
[Info("Restart Interrupt Guard", "RustPluginGenerator", "1.0.0")]
[Description("Blocks accidental cancellation of a scheduled server restart.")]
public class RestartInterruptGuard : RustPlugin
{
private const string PermAdmin = "restartinterruptguard.admin";
private PluginConfig config;
private class PluginConfig
{
[JsonProperty("Block interruption of scheduled restart")]
public bool BlockInterrupt { get; set; } = true;
}
protected override void LoadDefaultConfig() => config = new PluginConfig();
protected override void LoadConfig()
{
base.LoadConfig();
try
{
config = Config.ReadObject<PluginConfig>();
if (config == null) throw new Exception();
}
catch
{
PrintWarning("Configuration file is invalid, using defaults");
LoadDefaultConfig();
}
SaveConfig();
}
protected override void SaveConfig() => Config.WriteObject(config);
protected override void LoadDefaultMessages()
{
lang.RegisterMessages(new Dictionary<string, string>
{
["Blocked"] = "Restart interruption is currently blocked.",
["Allowed"] = "Restart interruption is currently allowed.",
["Toggled"] = "Restart interruption is now {0}.",
["NoPerm"] = "You do not have permission to use this command."
}, this);
}
private string Msg(string key, string userId = null, params object[] args) =>
string.Format(lang.GetMessage(key, this, userId), args);
private void Init()
{
permission.RegisterPermission(PermAdmin, this);
}
private object OnServerRestartInterrupt()
{
if (!config.BlockInterrupt) return null;
return true;
}
[ChatCommand("restartguard")]
private void CmdRestartGuard(BasePlayer player, string command, string[] args)
{
if (player == null) return;
if (!permission.UserHasPermission(player.UserIDString, PermAdmin))
{
player.ChatMessage(Msg("NoPerm", player.UserIDString));
return;
}
player.ChatMessage(Msg(config.BlockInterrupt ? "Blocked" : "Allowed", player.UserIDString));
}
[ConsoleCommand("restartguard.toggle")]
private void CcmdToggle(ConsoleSystem.Arg arg)
{
if (arg == null) return;
if (!arg.IsAdmin && (arg.Player() == null || !permission.UserHasPermission(arg.Player().UserIDString, PermAdmin)))
{
arg.ReplyWith(Msg("NoPerm"));
return;
}
config.BlockInterrupt = !config.BlockInterrupt;
SaveConfig();
arg.ReplyWith(Msg("Toggled", null, config.BlockInterrupt ? "blocked" : "allowed"));
}
}
}The plugin makes scheduled restarts sticky. When OnServerRestartInterrupt fires, it checks the config flag; if BlockInterrupt is enabled it returns true, which stops ServerMgr.RestartServer from showing the toast and stopping the restart coroutine. The existing countdown therefore keeps running. An admin command restartguard.toggle flips the flag at runtime and persists it to the config file. A chat command prints the current state so admins can confirm behavior before a real restart. The hook returns null when blocking is disabled, preserving vanilla interruption behavior.
Common use cases
Protect scheduled restarts from accidental cancellation
Server managers often restart a second time by mistake or via an RCON race, cancelling the original countdown. Blocking the interruption keeps the first scheduled restart intact.
Keep maintenance windows predictable
During a planned maintenance window you can ignore any competing restart request until your own timer fires, avoiding the restart being pushed back by an operator command.
Diagnose restart storms
Temporarily return a non-null value while testing to confirm whether a plugin or RCON script is repeatedly cancelling your restart countdown.
Pitfalls
Only fires on interruption, not the first restart
A first-time
restartcommand does not invoke this hook. Do not rely on it to track every restart request; useOnServerRestartfor that.Returning a value does not reschedule anything
A non-null return only prevents the cancellation. The original restart coroutine is still the one that will fire, so its timing is unaffected.
Blocking indefinitely can make the server unmanageable
If you gate interruption behind a config flag, give admins a console command or config edit path to disable it without restarting the server.
Build a plugin with OnServerRestartInterrupt
Describe what should happen and get a compiled plugin that uses this hook.
Edit the prompt on the next screen. 2 free plugins a month, no card.
Last updated Oct 26, 2026. Found a mistake? Email support@rustplugingenerator.com.
Build a plugin with OnServerRestartInterrupt
Generate