1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Weekly Server Restarts? Has anyone released code for this?

Discussion in 'Script Support' started by WarFace, Dec 16, 2013.

  1. WarFace
    Offline

    WarFace Member

    Joined:
    Nov 25, 2013
    Messages:
    27
    Likes Received:
    5
    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 (C#):
    1. using System;
    2. using Server.Commands;
    3.  
    4.  
    5.  
    6.  
    7. namespace Server.Misc
    8. {
    9.     public class AutoRestart : Timer
    10.     {
    11.         public static bool Enabled = false;// is the script enabled?
    12.         private static readonly TimeSpan RestartTime = TimeSpan.FromHours(2.0);// time of day at which to restart
    13.         private static readonly TimeSpan RestartDelay = TimeSpan.Zero;// how long the server should remain active before restart (period of 'server wars')
    14.         private static readonly TimeSpan WarningDelay = TimeSpan.FromMinutes(1.0);// at what interval should the shutdown message be displayed?
    15.         private static bool m_Restarting;
    16.         private static DateTime m_RestartTime;
    17.         public AutoRestart()
    18.             : base(TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(1.0))
    19.         {
    20.             this.Priority = TimerPriority.FiveSeconds;
    21.  
    22.  
    23.  
    24.  
    25.             m_RestartTime = DateTime.UtcNow.Date + RestartTime;
    26.  
    27.  
    28.  
    29.  
    30.             if (m_RestartTime < DateTime.UtcNow)
    31.                 m_RestartTime += TimeSpan.FromDays(1.0);
    32.         }
    33.  
    34.  
    35.  
    36.  
    37.         public static bool Restarting
    38.         {
    39.             get
    40.             {
    41.                 return m_Restarting;
    42.             }
    43.         }
    44.         public static void Initialize()
    45.         {
    46.             CommandSystem.Register("Restart", AccessLevel.Administrator, new CommandEventHandler(Restart_OnCommand));
    47.             new AutoRestart().Start();
    48.         }
    49.  
    50.  
    51.  
    52.  
    53.         public static void Restart_OnCommand(CommandEventArgs e)
    54.         {
    55.             if (m_Restarting)
    56.             {
    57.                 e.Mobile.SendMessage("The server is already restarting.");
    58.             }
    59.             else
    60.             {
    61.                 e.Mobile.SendMessage("You have initiated server shutdown.");
    62.                 Enabled = true;
    63.                 m_RestartTime = DateTime.UtcNow;
    64.             }
    65.         }
    66.  
    67.  
    68.  
    69.  
    70.         protected override void OnTick()
    71.         {
    72.             if (m_Restarting || !Enabled)
    73.                 return;
    74.  
    75.  
    76.  
    77.  
    78.             if (DateTime.UtcNow < m_RestartTime)
    79.                 return;
    80.  
    81.  
    82.  
    83.  
    84.             if (WarningDelay > TimeSpan.Zero)
    85.             {
    86.                 this.Warning_Callback();
    87.                 Timer.DelayCall(WarningDelay, WarningDelay, new TimerCallback(Warning_Callback));
    88.             }
    89.  
    90.  
    91.  
    92.  
    93.             AutoSave.Save();
    94.  
    95.  
    96.  
    97.  
    98.             m_Restarting = true;
    99.  
    100.  
    101.  
    102.  
    103.             Timer.DelayCall(RestartDelay, new TimerCallback(Restart_Callback));
    104.         }
    105.  
    106.  
    107.  
    108.  
    109.         private void Warning_Callback()
    110.         {
    111.             World.Broadcast(0x22, true, "The server is going down shortly.");
    112.         }
    113.  
    114.  
    115.  
    116.  
    117.         private void Restart_Callback()
    118.         {
    119.             Core.Kill(true);
    120.         }
    121.     }
    122. }
     
  2. Milva
    Offline

    Admin Moderator

    Joined:
    Mar 3, 2013
    Messages:
    3,795
    Likes Received:
    417
    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" :)
     
  3. Insanity
    Offline

    Insanity Active Member

    Joined:
    Mar 2, 2013
    Messages:
    276
    Likes Received:
    62
    A weekly restart wouldn't effect backups. Backups are performed with every save if unaltered.
     
  4. WarFace
    Offline

    WarFace Member

    Joined:
    Nov 25, 2013
    Messages:
    27
    Likes Received:
    5
    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
     
  5. Milva
    Offline

    Admin Moderator

    Joined:
    Mar 3, 2013
    Messages:
    3,795
    Likes Received:
    417
    :) 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 :)
     
  6. Insanity
    Offline

    Insanity Active Member

    Joined:
    Mar 2, 2013
    Messages:
    276
    Likes Received:
    62
    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.

    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.
     
Similar Threads: Weekly Server
Forum Title Date
Archived Bug Reports Bag of Bulk Order Covers bug after server restart Thursday at 6:05 PM
Script Support Enable elf and gargoyle on PREAOS server Jul 9, 2018
Archived Bug Reports Server Crash Jul 4, 2018
Looking For Help looking for people to help with my server Jun 20, 2018
Mono Support Server dont restart when i make a restart or when server crash Jun 19, 2018
Script Support Trying to add the following 2 scripts to RunUO Server 2.6 . . . Jun 17, 2018
Windows Support Saves freeze server Jun 14, 2018