WarFace

Member
Looking to get weekly server restarts going but its in hours could i not just replace FromHours = FromDays. Or can someone release there weekly restart code in AutoRestart.cs

Heres the code

Code:
using System;
using Server.Commands;
 
 
 
 
namespace Server.Misc
{
	public class AutoRestart : Timer
	{
		public static bool Enabled = false;// is the script enabled?
		private static readonly TimeSpan RestartTime = TimeSpan.FromHours(2.0);// time of day at which to restart
		private static readonly TimeSpan RestartDelay = TimeSpan.Zero;// how long the server should remain active before restart (period of 'server wars')
		private static readonly TimeSpan WarningDelay = TimeSpan.FromMinutes(1.0);// at what interval should the shutdown message be displayed?
		private static bool m_Restarting;
		private static DateTime m_RestartTime;
		public AutoRestart()
			: base(TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(1.0))
		{
			this.Priority = TimerPriority.FiveSeconds;
 
 
 
 
			m_RestartTime = DateTime.UtcNow.Date + RestartTime;
 
 
 
 
			if (m_RestartTime < DateTime.UtcNow)
				m_RestartTime += TimeSpan.FromDays(1.0);
		}
 
 
 
 
		public static bool Restarting
		{
			get
			{
				return m_Restarting;
			}
		}
		public static void Initialize()
		{
			CommandSystem.Register("Restart", AccessLevel.Administrator, new CommandEventHandler(Restart_OnCommand));
			new AutoRestart().Start();
		}
 
 
 
 
		public static void Restart_OnCommand(CommandEventArgs e)
		{
			if (m_Restarting)
			{
				e.Mobile.SendMessage("The server is already restarting.");
			}
			else
			{
				e.Mobile.SendMessage("You have initiated server shutdown.");
				Enabled = true;
				m_RestartTime = DateTime.UtcNow;
			}
		}
 
 
 
 
		protected override void OnTick()
		{
			if (m_Restarting || !Enabled)
				return;
 
 
 
 
			if (DateTime.UtcNow < m_RestartTime)
				return;
 
 
 
 
			if (WarningDelay > TimeSpan.Zero)
			{
				this.Warning_Callback();
				Timer.DelayCall(WarningDelay, WarningDelay, new TimerCallback(Warning_Callback));
			}
 
 
 
 
			AutoSave.Save();
 
 
 
 
			m_Restarting = true;
 
 
 
 
			Timer.DelayCall(RestartDelay, new TimerCallback(Restart_Callback));
		}
 
 
 
 
		private void Warning_Callback()
		{
			World.Broadcast(0x22, true, "The server is going down shortly.");
		}
 
 
 
 
		private void Restart_Callback()
		{
			Core.Kill(true);
		}
	}
}
 
Just a thought but you might consider doing something like every 2 days server restart with the reason being. You just never know what can happen with a crash and the server will not reload "with out a backup to replace". With having more recent backups this will prevent having to go to far back and having players complain about "what they have lost" :)
 
I didnt think it would effect backups ether, We are wanting to do weekly restarts Like OSI does. So would i not have to change that from FromHours to FromDays
 
:) I didn't mean it would effect saves, what I was getting to is this- you only get so many saves folders per day. So say you restart your server and it crashes( restarted 7 days) with a problem you check your saves folder (use the ones from the past 2-3 days and none work because the problem came about before this time. Just a thought :)
 
I didnt think it would effect backups ether, We are wanting to do weekly restarts Like OSI does. So would i not have to change that from FromHours to FromDays

If you change it to FromHours to FromDays, your server would restart every time a save is processed during the day you do your restart (every hour if saves are set to every hour.) What you should do is check to see if the day and specific hour are correct. For example, you should check to see that the day is Sunday and if it's past 1am. This would make your server only restart once a week, and only once during that day.

I didn't mean it would effect saves, what I was getting to is this- you only get so many saves folders per day. So say you restart your server and it crashes( restarted 7 days) with a problem you check your saves folder (use the ones from the past 2-3 days and none work because the problem came about before this time. Just a thought

That is what emergency backups are for. Plus the only thing that would cause the saves file from not loading after a crash, is a faulty save or harddrive issues (corrupted save file.) It's completely possible to dig through a save file that was only partially saved and find/fix any issues. Just isn't exactly a cake walk.
 

Active Shards

Donations

Total amount
$0.00
Goal
$1,000.00
Back