Difference between revisions of "Limit Service's Disk Space"
Line 122: | Line 122: | ||
Script.WriteToConsole(String.Format("Available: {0}MB ({1}%)", quotainfo.AvailableKB/1024, Math.Round(Double.Parse(quotainfo.AvailableKB.ToString())/quotainfo.LimitKB * 100,2))); | Script.WriteToConsole(String.Format("Available: {0}MB ({1}%)", quotainfo.AvailableKB/1024, Math.Round(Double.Parse(quotainfo.AvailableKB.ToString())/quotainfo.LimitKB * 100,2))); | ||
else: | else: | ||
− | + | Script.WriteToConsole(String.Format("{0} does not have a disk quota on {1}", serviceuser, mountpoint)); |
Revision as of 19:59, 24 February 2015
Configure disk quotas in your drive
Linux
- Follow these instructions to configure disk quotas on Linux: Linux_Quotas
Windows
- Enable quotas on the drive where the services will be created. The configuration shown in the screenshot is recommended.
Configure the game
- Configure the game with Run As = User per Service. Go to Settings > Games > select the game > Select the "Run As" tab. Set Run As = User per service and save. This will create one Windows/Linux user for each service. The disk quota will be created for this user.
If you have existing services of this type go to Settings > Game Tools and run the Verify/Repair tool on your server with "Update run as user" checked.
- Configure a variable for the quota value. Click on the Variables icon. Click on new and enter these values:
- Name: DiskQuota
- Default value: 0
- Is numeric: Checked
- Preserve value: Checked
- Select the Variable Options tab and configure these values:
- Script parameter: Checked
- Save script parameter value: Checked
- Admin access: Checked
- Value is required: Checked
- Item Type: Numeric textbox
- Label: Disk Quota (MB)
- Description: Specify the disk quota in MB. Set to 0 for unlimited space.
- Decimal Digits: 0
- Configure the scripts. Go back to the game's main settings. Click on the Custom Scripts icon. Configure the following scripts.
Operating System: Any Description: Create disk quota when game server is created Script Engine: IronPython Event: After created Script:
import clr; import System; from System import UInt64, String, Exception; diskquotamb = ThisService.Variables["DiskQuota"]; serviceuser = ThisService.GetServiceCredentials().User; mountpoint = ThisServer.FileSystemService.GetMountPoint(ThisService.RootDirectory); if not ThisServer.FileSystemService.QuotasEnabled(ThisService.RootDirectory) : raise Exception(String.Format("Disk quotas are not enabled on {0}", mountpoint)); Script.WriteToConsole(String.Format("Creating {0}MB disk quota on {1} for {2}", diskquotamb, mountpoint, serviceuser)); ThisServer.FileSystemService.SetQuota(serviceuser, mountpoint, UInt64.Parse(diskquotamb) * 1024 * 1024);
Operating System: Any Description: Delete disk quota when the game server is deleted Script Engine: IronPython Event: Before deleted Script:
import clr; import System; from System import UInt64, String, Exception; serviceuser = ThisService.GetServiceCredentials().User; mountpoint = ThisServer.FileSystemService.GetMountPoint(ThisService.RootDirectory); if not ThisServer.FileSystemService.QuotasEnabled(ThisService.RootDirectory) : raise Exception(String.Format("Disk quotas are not enabled on {0}", mountpoint)); Script.WriteToConsole(String.Format("Deleting disk quota on {0} for {1}", mountpoint, serviceuser)); ThisServer.FileSystemService.SetQuota(serviceuser, mountpoint, 0);
Operating System: Any Description: Configure the game server's disk quota Script Engine: IronPython Event: Custom action Prompt for variable values: Checked Name: Set Disk Quota Script:
import clr; import System; from System import UInt64, String, Exception; diskquotamb = ThisService.Variables["DiskQuota"]; serviceuser = ThisService.GetServiceCredentials().User; mountpoint = ThisServer.FileSystemService.GetMountPoint(ThisService.RootDirectory); if not ThisServer.FileSystemService.QuotasEnabled(ThisService.RootDirectory) : raise Exception(String.Format("Disk quotas are not enabled on {0}", mountpoint)); Script.WriteToConsole(String.Format("Creating {0}MB disk quota on {1} for {2}", diskquotamb, mountpoint, serviceuser)); ThisServer.FileSystemService.SetQuota(serviceuser, mountpoint, UInt64.Parse(diskquotamb) * 1024 * 1024);
Operating System: Any Description: Check the disk quota assigned to this game server Script Engine: IronPython Event: Custom action Name: Check Disk Quota Script:
import clr; import System; clr.AddReference("TCAdmin.Helper"); from TCAdmin.Helper.Quotas import LinuxCuota; from System import Double, String, Exception, Math; serviceuser = ThisService.GetServiceCredentials().User; mountpoint = ThisServer.FileSystemService.GetMountPoint(ThisService.RootDirectory); if not ThisServer.FileSystemService.QuotasEnabled(ThisService.RootDirectory) : raise Exception(String.Format("Disk quotas are not enabled on {0}", mountpoint)); quotainfo = LinuxCuota.getQuota(mountpoint, serviceuser); if quotainfo.HasQuota : Script.WriteToConsole(String.Format("Disk Quota: {0}MB", quotainfo.LimitKB/1024)); Script.WriteToConsole(String.Format("Used: {0}MB ({1}%)", quotainfo.CurrentUsageKB/1024, Math.Round(Double.Parse(quotainfo.CurrentUsageKB.ToString())/quotainfo.LimitKB * 100,2))); Script.WriteToConsole(String.Format("Available: {0}MB ({1}%)", quotainfo.AvailableKB/1024, Math.Round(Double.Parse(quotainfo.AvailableKB.ToString())/quotainfo.LimitKB * 100,2))); else: Script.WriteToConsole(String.Format("{0} does not have a disk quota on {1}", serviceuser, mountpoint));