Plugins/Essentials/Auto-Restart & Cleanup

From Torch Wiki
Jump to navigation Jump to search

CAUTION: Hosting providers

Some hosting providers are incompatible with Essentials !restart commands, as it will create a new torch process with new process id. Website based management tools, may no longer be able to control the server after such restart.

Check first if the hosting solution you have chosen is compatible.

Recommendations for Auto-Restart

Generally it is recommended to restart your torch server every now and then to fix bugged out grids, free up stuck memory and overall improve the performance, as over time things can get a bit annoying to deal with.

Restarts also allow for an opportunity to perform some server maintenance such as cleanups that can be done fully automatic. Some of them require server restarts afterwards.

There are two major ways of setting up a restart which are described below.

Dynamic / Interval based

A dynamic or interval based server restart is easier to set up, and it only really requires one command. However the restart times are unpredictable, and players usually love it, if they are able to predict when a restart will happen.

Considering you want to run a restart every 4 hours. The server starts counting from the moment the session is loaded.

This means if the restart triggers at exactly 10pm, it takes about 5 minutes to save and go down, 5 more minutes to boot up again and starts counting down at 10:10pm. The next restart will therefore be at 2:10am. Additionally, if your server crashes in between, or you perform a manual restart after some config changes the 4h interval is completely out of the window.

However it also makes sure that if a server just restarted after crash, it will not do so again within the next 4 hours.

Config Example

[...]
  <AutoCommands>
[...]
    <AutoCommand>
      <CommandTrigger>Timed</CommandTrigger>
      <Name>Restart</Name>
      <Interval>04:00:00</Interval>
      <Steps>
        <CommandStep>
          <Delay>00:00:00</Delay>
          <Command>!restart 300</Command>
        </CommandStep>
      </Steps>
    </AutoCommand>
[...]
  </AutoCommands>
[...]

This will begin the countdown to a restart 5 minutes before it actually happens, automatically saves the world and restarts the server. It's enough time for players to stop whatever they are doing, and secure their grids.

The time behind the !restart is in seconds. So you can easily increase or decrease them as needed. The Interval is a time in the 24h time format. 04:00:00 means 4 hours. The CommandTrigger tells you it interval based.

Unneeded XML Tags were removed. After saving the config with essentials they will be added back again.

Fixed / Scheduled

A more widespread solution for restarting the server is scheduled at fixed times. With that you can make sure that your server always starts at the exact same time, or at fixed intervals.

This allows players to predict restart times, even if they are not ingame, and you can add additional commands only on specific restarts. Such as only doing a cleanup at midnight.

However, if your server happens to crash at 11pm, and your next scheduled restart is at midnight, the server will just run an hour before restarting again. This however is not a bad thing, if you bundle world cleanups together with a restart, since this would not have happened on a crash.

Config Example

Commonly a server restart of every 4 hours is used, but for the sake of simplicity the example below uses 12 hours.

[...]
  <AutoCommands>
[...]
    <AutoCommand>
      <CommandTrigger>Scheduled</CommandTrigger>
      <Name>Restart</Name>
      <Interval>23:55:00</Interval>
      <Steps>
        <CommandStep>
          <Delay>00:00:00</Delay>
          <Command>!restart 300</Command>
        </CommandStep>
      </Steps>
    </AutoCommand>
    <AutoCommand>
      <CommandTrigger>Scheduled</CommandTrigger>
      <Name>Restart</Name>
      <Interval>11:55:00</Interval>
      <Steps>
        <CommandStep>
          <Delay>00:00:00</Delay>
          <Command>!restart 300</Command>
        </CommandStep>
      </Steps>
    </AutoCommand>
[...]
  </AutoCommands>
[...]

As you can see here, you add 2 commands, which are scheduled for execution at 11:55am and pm respectively. But run the restart command with a delay of 5 minutes, meaning the server will restart exactly at 12. (+ time it takes to save)

The Interval is a time in the 24h time format. 04:00:00 means 4am 16:00:00 4pm. The CommandTrigger tells you it fixed.

Unneeded XML Tags were removed. After saving the config with essentials they will be added back again.

Don't repeat yourself

If you for example have 6 scheduled restarts (1 every 4 hours) it can be a tedious task to make changes to the restart itself. Things like changing the countdown, adding player notifications, or cleanup would all have to done be 6 times.

The solution to that is: DON'T

Instead use yet an other task. Essentials offers the "!admin runauto" command, which allows you to execute any other task you wish.

So instead of calling !restart and what other commands you want to have executed, you just call an other task that will do that for you.

[...]
  <AutoCommands>
[...]
    <AutoCommand>
      <CommandTrigger>Scheduled</CommandTrigger>
      <Name>Restart 0</Name>
      <Interval>23:55:00</Interval>
      <Steps>
        <CommandStep>
          <Delay>00:00:00</Delay>
          <Command>!admin runauto "Restart Procedure"</Command>
        </CommandStep>
      </Steps>
    </AutoCommand>
    <AutoCommand>
      <CommandTrigger>Scheduled</CommandTrigger>
      <Name>Restart 12</Name>
      <Interval>11:55:00</Interval>
      <Steps>
        <CommandStep>
          <Delay>00:00:00</Delay>
          <Command>!admin runauto "Restart Procedure"</Command>
        </CommandStep>
      </Steps>
    </AutoCommand>
    <AutoCommand>
      <CommandTrigger>Disabled</CommandTrigger>
      <Name>Restart Procedure</Name>
      <Steps>
        <CommandStep>
          <Delay>00:00:00</Delay>
          <Command>!restart 300</Command>
        </CommandStep>
      </Steps>
    </AutoCommand>
[...]
  </AutoCommands>
[...]

As you can see the 2 individual scheduled tasks only do one thing, and that's calling the "Restart Procedure", and that's calling !restart.

If you want to change the restart countdown now, or do some cleanup before or after, you can do that now on one central location. The CommandTrigger "disabled" tell you, that this command will never run on it own and can only be manually executed using !admin runauto command.

Unneeded XML Tags were removed. After saving the config with essentials they will be added back again.

Recommendations for Cleanup

Over time on a server there can be a lot of junk that is being created, and needs cleaning up.

Among those are bugged NPC-Ships, Asteroids, abandoned player girds, or just improving functionality by turning certain behavior off.

When to cleanup?

Depending on the type of cleanup you are running the times can vary, but the community found a consensus to perform some cleanup at least once a day.

When a cleanup is performed, it should be right before a restart. This is due:

  • What's been cleaned up does not need to be saved.
  • What's not there does not need to be leaded in.
  • Depending on what being cleaned up a restart is recommended anyway.

What to clean up?

Grids

  • Many servers delete grids without beacon
    • !cleanup delete notype beacon playerdistancegreaterthan 1000
  • NPC Grids (careful not to delete NPC Trade station)
    • !cleanup delete hasownertype npc hasgridtype ship playerdistancegreaterthan 1000
  • Grids owned by nobody
    • !cleanup delete ownedby nobody playerdistancegreaterthan 1000
  • Inactive players
  • Grids without power etc.

Basic cleanup settings of Keen may apply. Things like grids which have <20 blocks and no power or spawn point, are generally considered to be trash, and can safely be removed. This is nothing you have to do with essentials. Keen base game does that well enough.

Voxels

As of now Torch does not have any functionality to partially reset planets. It can only remove asteroids where no player is close by. Unless you wont allow players to build inside planets on your server, then you can fully restore them with the commands essentials provides.

Its recommended to use

  • !voxels cleanup asteroids
    • removes asteroids 500m from any player or grid
  • !voxels cleanup distance 2000
    • removes asteroids 2000m from any player or grid
  • !voxels cleanup planets
    • resets all planets (CAUTION: GRIDS MAY BE BURIED)

Resetting the asteroids like that, will just undo all damage done to them. However it will not remove the vx2 file from your world save. Over time those can add up to 50k+, slowing down saving and loading of the world as well as the simulation speed.

Its is recommended to use:

  • !voxels cleanup asteroids true
    • removes asteroids 500m from any player or grid
  • !voxels cleanup distance 2000 true
    • removes asteroids 2000m from any player or grid

the true in the end stands for delete storage, which removes these files on world save.

CAUTION: removing asteroids like that will prevent them from being regenerated after a server restart. They will just be gone gone.

to workaround that ALE PCU Transferrer Plugin has a command

  • !seedcleanup all

which will thoroughly remove the asteroids so they will be regenerated normally after restart.

Blocks

Some blocks are more expensive than others, often players forget to for example, turn off their ship welders, projectors, drills and what not when not used.

Especially gravity drives with their mass blocks together with active gravity generators can cause huge spikes in simulation speed. So you may want to consider turning some blocks off to avoid problems.

  • Ship Welders
    • !blocks off type ShipWelder
  • Ship Grinders
    • !blocks off type ShipGrinder
  • Drills
    • !blocks off type Drill
  • Projectors
    • !blocks off type Projector
  • ProjectorTable DLC Block
    • !blocks off type LargeBlockConsole

Some also like to turn off Timers, Programmable Blocks, Sensors, etc. But those can impact gameplay and functionality of player creativity more. So unless its unavoidable its not advised to be doing so.

Best to use HaE PBLimiter Plugin to deal with performance problems caused by programmable blocks.

How to cleanup?

Similar to Restarts you can just create an auto command to do so:

[...]
  <AutoCommands>
[...]
    <AutoCommand>
      <CommandTrigger>Scheduled</CommandTrigger>
      <Name>Cleanup</Name>
      <Interval>00:00:00</Interval>
      <Steps>
        <CommandStep>
          <Delay>00:00:00</Delay>
          <Command>!cleanup delete notype beacon playerdistancegreaterthan 1000</Command>
        </CommandStep>
        <CommandStep>
          <Delay>00:00:00</Delay>
          <Command>!cleanup delete ownedby nobody playerdistancegreaterthan 1000</Command>
        </CommandStep>
        <CommandStep>
          <Delay>00:00:00</Delay>
          <Command>!voxels cleanup asteroids</Command>
        </CommandStep>
      </Steps>
    </AutoCommand>
[...]
  </AutoCommands>
[...]

This would just run a cleanup every day at midnight. Be careful with time schedules that it does not interfere with your restarts, and preferably runs together with them, for example you can just run your cleanup before calling the restart command.

[...]
  <AutoCommands>
[...]
    <AutoCommand>
      <CommandTrigger>Scheduled</CommandTrigger>
      <Name>Cleanup</Name>
      <Interval>00:00:00</Interval>
      <Steps>
        <CommandStep>
          <Delay>00:00:00</Delay>
          <Command>!cleanup delete notype beacon playerdistancegreaterthan 1000</Command>
        </CommandStep>
        <CommandStep>
          <Delay>00:00:00</Delay>
          <Command>!cleanup delete ownedby nobody playerdistancegreaterthan 1000</Command>
        </CommandStep>
        <CommandStep>
          <Delay>00:00:00</Delay>
          <Command>!voxels cleanup asteroids</Command>
        </CommandStep>
        <CommandStep>
          <Delay>00:00:00</Delay>
          <Command>!restart 300</Command>
        </CommandStep>
      </Steps>
    </AutoCommand>
[...]
  </AutoCommands>
[...]

Unneeded XML Tags were removed. After saving the config with essentials they will be added back again.

Sample-Config

This Sample-Config can be used as is without the need to actually change anything to it. But it is recommended still alter it to match the concept your own server is going for.

It features:

  • Automated Restarts at
    • 12am
    • 4am
    • 8am
    • 12pm
    • 4pm
    • 8pm
  • Restart Countdown
    • 1h in advance
    • 30 min in advance
    • 15 min in advance
    • 5 min in advance
    • 1 min in advance
    • and then from 10 down to 1s
  • Server-Cleanup with feedback to the players
    • Deletes all grids whose owners are inactive for more than 14 days.
      • On shared grids the ownership will be transferred to the player with majority of ownership.
      • If the player with the majority if inactive, its gonna be deleted.
    • Deletes all grids owned by nobody (and distance > 1km from any player)
    • Deletes ships owned by npcs (and distance > 1km from any player) (stations are fine)
    • Deletes all grids without beacon (and distance > 1km from any player) (CAUTION: You may want to change that)
    • Turns off the following blocks (You may want to add other blocks as well)
      • LargeBlockConsole (Projector Tables (DLC))
      • Projectors
      • ShipWelders (including Modded ones)
      • ShipGrinders (including Modded ones)
      • Drills (including Modded ones)
    • Resets Asteroids (500m from any grid or player)
  • A restart vote command
    • Triggers if 51% of the online players vote with !yes
    • Vote duration is 2:30 minutes
    • Cleans up the server before it restarts
    • Vote can be started with !vote restart
  • A manual restart task with cleanup
    • Can be executed with !admin runauto "Restart Manual"

Required Plugins

Apart from essentials itself this sample config makes use of the ALE PCU Transferrer, for the following commands

  • !gridcleanup 14
    • This command is similar to !identity purge of essentials, but it doesn't delete Identities.
    • Deleting identities has proven to cause issues with blocklimits and duplicate player IDs, when paired with other commands such as !sandbox clean (which is also not recommended to be used).
    • !gridcleanup is a safe alternative, that only takes care of grids, and removing players from factions etc.
  • !seedcleanup all
    • When using !voxel cleanup asteroids true, the "true" means delete storage, as in delete the vx2 file as well. This means the asteroid is gone and will never be generated again.
    • !seedcleanup all addresses this problem and ensures everything is generated correctly again.
    • This command requires a restart to not cause any issues, so its best used when the server is about to restart anyway.
    • Not deleting the voxel storage means you will keep thousands of asteroid files in your world save, which increases save and load times of the server.

Config

<?xml version="1.0" encoding="utf-8"?>
<EssentialsConfig xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <_enableRanks>false</_enableRanks>
  <_defaultRank>Default</_defaultRank>
  <_overridePerms>false</_overridePerms>
  <_enableHomes>false</_enableHomes>
  <AutoCommands>
    <AutoCommand>
      <CommandTrigger>Scheduled</CommandTrigger>
      <Name>Scheduled Restart 0</Name>
      <Interval>23:00:00</Interval>
      <Steps>
        <CommandStep>
          <Delay>00:00:00</Delay>
          <Command>!admin runauto "Restart Timer"</Command>
        </CommandStep>
      </Steps>
    </AutoCommand>
    <AutoCommand>
      <CommandTrigger>Scheduled</CommandTrigger>
      <Name>Scheduled Restart 4</Name>
      <Interval>03:00:00</Interval>
      <Steps>
        <CommandStep>
          <Delay>00:00:00</Delay>
          <Command>!admin runauto "Restart Timer"</Command>
        </CommandStep>
      </Steps>
    </AutoCommand>
    <AutoCommand>
      <CommandTrigger>Scheduled</CommandTrigger>
      <Name>Scheduled Restart 8</Name>
      <Interval>07:00:00</Interval>
      <Steps>
        <CommandStep>
          <Delay>00:00:00</Delay>
          <Command>!admin runauto "Restart Timer"</Command>
        </CommandStep>
      </Steps>
    </AutoCommand>
    <AutoCommand>
      <CommandTrigger>Scheduled</CommandTrigger>
      <Name>Scheduled Restart 12</Name>
      <Interval>11:00:00</Interval>
      <Steps>
        <CommandStep>
          <Delay>00:00:00</Delay>
          <Command>!admin runauto "Restart Timer"</Command>
        </CommandStep>
      </Steps>
    </AutoCommand>
    <AutoCommand>
      <CommandTrigger>Scheduled</CommandTrigger>
      <Name>Scheduled Restart 16</Name>
      <Interval>15:00:00</Interval>
      <Steps>
        <CommandStep>
          <Delay>00:00:00</Delay>
          <Command>!admin runauto "Restart Timer"</Command>
        </CommandStep>
      </Steps>
    </AutoCommand>
    <AutoCommand>
      <CommandTrigger>Scheduled</CommandTrigger>
      <Name>Scheduled Restart 20</Name>
      <Interval>19:00:00</Interval>
      <Steps>
        <CommandStep>
          <Delay>00:00:00</Delay>
          <Command>!admin runauto "Restart Timer"</Command>
        </CommandStep>
      </Steps>
    </AutoCommand>
    <AutoCommand>
      <CommandTrigger>Disabled</CommandTrigger>
      <Name>Restart Manual</Name>
      <Steps>
        <CommandStep>
          <Delay>00:00:05</Delay>
          <Command>!restart 60</Command>
        </CommandStep>
        <CommandStep>
          <Delay>00:00:25</Delay>
          <Command>!admin runauto "Restart Procedure"</Command>
        </CommandStep>
      </Steps>
    </AutoCommand>
    <AutoCommand>
      <CommandTrigger>Disabled</CommandTrigger>
      <Name>Restart Timer</Name>
      <Steps>
        <CommandStep>
          <Delay>00:30:00</Delay>
          <Command>!say Restart in 1 hour!</Command>
        </CommandStep>
        <CommandStep>
          <Delay>00:15:00</Delay>
          <Command>!say Restart in 30 minutes!</Command>
        </CommandStep>
        <CommandStep>
          <Delay>00:10:00</Delay>
          <Command>!say Restart in 15 minutes!</Command>
        </CommandStep>
        <CommandStep>
          <Delay>00:04:00</Delay>
          <Command>!say Restart in 5 minutes!</Command>
        </CommandStep>
        <CommandStep>
          <Delay>00:00:05</Delay>
          <Command>!restart 60</Command>
        </CommandStep>
        <CommandStep>
          <Delay>00:00:25</Delay>
          <Command>!admin runauto "Restart Procedure"</Command>
        </CommandStep>
      </Steps>
    </AutoCommand>
    <AutoCommand>
      <CommandTrigger>Disabled</CommandTrigger>
      <Name>Restart Procedure</Name>
      <Steps>
        <CommandStep>
          <Delay>00:00:03</Delay>
          <Command>!say Cleaning up the server...</Command>
        </CommandStep>
        <CommandStep>
          <Delay>00:00:00</Delay>
          <Command>!say Deleting grids of players offline for more than 14 days...</Command>
        </CommandStep>
        <CommandStep>
          <Delay>00:00:03</Delay>
          <Command>!gridcleanup 14</Command>
        </CommandStep>
        <CommandStep>
          <Delay>00:00:00</Delay>
          <Command>!say Deleting nobody grids and grids without beacon...</Command>
        </CommandStep>
        <CommandStep>
          <Delay>00:00:00</Delay>
          <Command>!cleanup delete ownedby nobody playerdistancegreaterthan 1000</Command>
        </CommandStep>
        <CommandStep>
          <Delay>00:00:00</Delay>
          <Command>!cleanup delete notype beacon playerdistancegreaterthan 1000</Command>
        </CommandStep>
        <CommandStep>
          <Delay>00:00:03</Delay>
          <Command>!cleanup delete hasownertype npc hasgridtype ship playerdistancegreaterthan 1000</Command>
        </CommandStep>
        <CommandStep>
          <Delay>00:00:00</Delay>
          <Command>!say Turning off projectors and ship tools...</Command>
        </CommandStep>
        <CommandStep>
          <Delay>00:00:00</Delay>
          <Command>!blocks off type LargeBlockConsole</Command>
        </CommandStep>
        <CommandStep>
          <Delay>00:00:00</Delay>
          <Command>!blocks off type Projector</Command>
        </CommandStep>
        <CommandStep>
          <Delay>00:00:00</Delay>
          <Command>!blocks off type ShipWelder</Command>
        </CommandStep>
        <CommandStep>
          <Delay>00:00:00</Delay>
          <Command>!blocks off type ShipGrinder</Command>
        </CommandStep>
        <CommandStep>
          <Delay>00:00:03</Delay>
          <Command>!blocks off type Drill</Command>
        </CommandStep>
        <CommandStep>
          <Delay>00:00:00</Delay>
          <Command>!say Resetting asteroids...</Command>
        </CommandStep>
        <CommandStep>
          <Delay>00:00:00</Delay>
          <Command>!voxels cleanup asteroids true</Command>
        </CommandStep>
        <CommandStep>
          <Delay>00:00:03</Delay>
          <Command>!seedcleanup all</Command>
        </CommandStep>
        <CommandStep>
          <Delay>00:00:00</Delay>
          <Command>!say Awaiting restart...</Command>
        </CommandStep>
      </Steps>
    </AutoCommand>
    <AutoCommand>
      <CommandTrigger>Vote</CommandTrigger>
      <Name>restart</Name>
      <Interval>00:02:30</Interval>
      <TriggerRatio>0.51</TriggerRatio>
      <TriggerCount>0</TriggerCount>
      <Steps>
        <CommandStep>
          <Delay>00:00:00</Delay>
          <Command>!admin runauto "Restart Manual"</Command>
        </CommandStep>
      </Steps>
    </AutoCommand>
  </AutoCommands>
  <InfoCommands />
  <EnableRanks>false</EnableRanks>
  <DefaultRank>Default</DefaultRank>
  <OverrideVanillaPerms>false</OverrideVanillaPerms>
  <EnableHomes>false</EnableHomes>
  <MotdUrl />
  <NewUserMotdUrl>true</NewUserMotdUrl>
  <StopShipsOnStart>true</StopShipsOnStart>
  <UtilityShowPosition>true</UtilityShowPosition>
  <MarkerShowPosition>true</MarkerShowPosition>
  <BackpackLimit>1</BackpackLimit>
  <KnownSteamIds />
  <CutGameTags>false</CutGameTags>
</EssentialsConfig>

Unneeded XML Tags were removed. After saving the config with essentials they will be added back again.