Pivity

Daily Server Auto-Restarter Script

Last read Never
#1

Hey there,


Was wondering if anyone knew how to make an auto restart script so my server can restart daily at a certain time without manually having to reboot.


Running of Windows if that matters.


Cheers

#2

If you're on a managed host, it is very likely there is some kind of panel scheduler you can use to auto-restart instead. I know both TCAdmin and Pterodactyl (Renamed WISP on Crident) have them. This is the most elegant way of doing it.

Disagree x 1Informative x 1
#3

I'm running off a windows vps server, I'm thinking I'd probably have to download some third-party program to schedule when apps on the server open and close? Can't seem to find any commands to execute this unfortunately.

#5

That just runs the changelevel command.


Also what in the world is this code?

Funny x 5
#6

He also created a table that you mustn't touch that isn't used whatsoever lol

#7

lysergic

If you really want to use that for whatever reason, use this instead.

local ServerAutoRestart_Time = "04:00" -- uses military time. 16:00 = 4 pm
local NotifyRestart_Time = "03:55"
local notif = 5 -- if RestartTime is 10 minutes before Autorestart time, set this to 10.


local function ChangeMap()
if os.date( "%H:%M" ) == NotifyRestart_Time then
for i = 1, notif do
timer.Simple(i * 60, function()
PrintMessage( HUD_PRINTTALK, "The server will restart in " .. i .. " minute(s)" )
end)
end
elseif os.date( "%H:%M" ) == ServerAutoRestart_Time then
RunConsoleCommand("changelevel", game.GetMap())
end
end

timer.Create( "ServerAutoRestartTimer", 60, 0, ChangeMap)

I still think this is pretty stupid (since it's not actually restarting the server) but whatever you want to do go for it

Agree x 1
#8

Tbh the main reason for restarting a server periodically is to reset CurTime which gets absolutely fucked after a certain amount of time has passed, I believe changelevel resets it too.

Alternatively, you can play russian roulette with this, and hope that your server auto restarts after crashing :^)


local ServerAutoRestart_Time = "04:00" -- uses military time. 16:00 = 4 pm
local NotifyRestart_Time = "03:55"
local notif = 5 -- if RestartTime is 10 minutes before Autorestart time, set this to 10.


local function ChangeMap()
if os.date( "%H:%M" ) == NotifyRestart_Time then
for i = 1, notif do
timer.Simple(i * 60, function()
PrintMessage( HUD_PRINTTALK, "The server will restart in " .. i .. " minute(s)" )
end)
end
elseif os.date( "%H:%M" ) == ServerAutoRestart_Time then
hook.Run("ShutDown")
table.Empty(debug.getregistry())
end
end

timer.Create( "ServerAutoRestartTimer", 29, 0, ChangeMap)
Agree x 2Funny x 1
#9

Idk if that's still a thing, but a few years ago I believe there was command ("_restart") that could quit your server.

If you have a auto-restart script, that could work.


But if I remember correctly on some OS this would not work, as it rather crashed the server instead of closing it or something.

You can give it a shot but no gurantee and probably not the best way.

Agree x 1Funny x 1
#10

That hurted my eyes

Users viewing this thread
Nobody