Jump to content

Automatically create a scheduled restart task after the service is created


LFA

Recommended Posts

Go to the game's settings. Click on the Custom Scripts icon. Add a new script. Set these values:

Operating System: Any

Script Engine: Iron Python

Event: After Created

Script Contents:

 

import clr;
import System;

clr.AddReference("TCAdmin.SDK");
clr.AddReference("TCAdmin.TaskScheduler.SDK");

from System import DateTime, DateTimeKind, Array;
from TCAdmin.TaskScheduler.SDK.Objects import RecurringTask, RecurringStep, Trigger, TriggerType, TriggerDaily;
from TCAdmin.SDK.Database import XmlField;

rtask = RecurringTask();
rtask.UserId = ThisService.UserId;
rtask.Name = [b]"Restart Service"[/b];
rtask.Enabled = True;
rtask.Source = ThisService.GetType().ToString()
rtask.SourceId = ThisService.ServiceId.ToString()
rtask.UserId = ThisService.UserId;
rtask.Notes = "Created automatically."

trigger = Trigger();
trigger.TriggerType = TriggerType.Daily
trigger.Daily = TriggerDaily()
trigger.Daily.StartTimeUtc = DateTime.SpecifyKind(DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, [b]6, 0, 0[/b]), DateTimeKind.Utc);
trigger.Daily.RecurDays = 1;
rtask.Triggers = Array[Trigger]([trigger]);

step = RecurringStep();
step.ModuleId = "d3b2aa93-7e2b-4e0d-8080-67d14b2fa8a9";
step.ProcessId = 11;
step.ServerId = ThisService.ServerId;
args = XmlField();
args["ScheduledRestart.ServiceId"] = ThisService.ServiceId;
args["ScheduledRestart.CommandLine"] = "";
args["ScheduledRestart.ForceRestart"] = True;
args["ScheduledRestart.WaitEmpty"] = False;
args["ScheduledRestart.SkipRestart"] = False;
step.Arguments = args.ToString();
rtask.Steps = Array[RecurringStep]([step]);

rtask.GenerateKey();
rtask.Save();
rtask.ScheduleNextTask();

Things you might want to change:

"Restart Service" : The name of the task

6, 0, 0 : The scheduled time for the restart. This is in GMT time zone.

Link to comment
Share on other sites

  • 11 months later...
  • 1 month later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Who's Online   0 Members, 0 Anonymous, 20 Guests (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Terms of Use