How to increase domain limits (space, traffic/bandwidth) from the command line with Plesk

Tuesday, November 17, 2009

How to increase domain limits (space, traffic/bandwidth) from the command line with Plesk

Plesk allows you to use a template with /usr/local/psa/bin/domain binary however changing domain's limits has to be done using another binary called domain_pref.

/usr/local/psa/bin/domain_pref --update example.com  -disk_space 500M  -max_traffic 5G


With the application that I am working I needed to read the limits of a given template.
The one that the client's domain will be upgraded to.
I had to read and parse the output of domain_template binary to get the current limits.

My reasons:
I try hard to keep any configuration settings in one place.
Currently the domain limits are set through a domain template.
If they were read from a config file and from a domain template in case of a change I would have to update the change in two or more places.

/usr/local/psa/bin/domain_template --xml-info Your_Domain_Template_2

Its output looks like that:

<domain-template name="Your_Domain_Template_2">
<template-item name="asp">false</template-item>
<template-item name="cgi">false</template-item>
<template-item name="coldfusion">false</template-item>
<template-item name="disk_space">1048576000</template-item>
<template-item name="dns_type">master</template-item>
<template-item name="errdocs">false</template-item>
<template-item name="expiration">-1</template-item>
<template-item name="fp"></template-item>
<template-item name="fp_auth"></template-item>
<template-item name="fp_ssl"></template-item>
<template-item name="maillists">false</template-item>
<template-item name="max_box">-1</template-item>
<template-item name="max_db">-1</template-item>
<template-item name="max_maillists">-1</template-item>
<template-item name="max_mg">-1</template-item>
<template-item name="max_redir">-1</template-item>
<template-item name="max_resp">-1</template-item>
<template-item name="max_subdom">25</template-item>
<template-item name="max_dom_aliases">25</template-item>
<template-item name="max_traffic">1572864000</template-item>
<template-item name="max_webapps">-1</template-item>
<template-item name="max_wu">-1</template-item>
<template-item name="mbox_quota">-1</template-item>
<template-item name="nonexist_mail">reject</template-item>
<template-item name="pdir_plesk_stat">false</template-item>
<template-item name="perl">false</template-item>
<template-item name="php">false</template-item>
<template-item name="python">false</template-item>
<template-item name="fastcgi">false</template-item>
<template-item name="quota">0</template-item>
<template-item name="same_ssl">false</template-item>
<template-item name="shell">/bin/false</template-item>
<template-item name="ssi">false</template-item>
<template-item name="ssl">false</template-item>
<template-item name="stat_ttl">0</template-item>
<template-item name="vh_type"></template-item>
<template-item name="webmail">true</template-item>
<template-item name="webstat">none</template-item>
<template-item name="wu_script">false</template-item>
<template-item name="hosting">false</template-item>
</domain-template>


Here is function that parses the output above (disk space and traffic are currently extracted. For OOP fans: Yes, I know I could've used some XML objects)

    /**
    * Parses the XML output of domain_template. The sizes are in bytes.
    * /usr/local/psa/bin/domain_template --xml-info Your_Domain_Template_2
    *
    * @param string $buffer
    * @return array
    */
    public static function parseTemplateStats($buffer = '') {
        $stats = array();

        // defaults
        $stats['disk_space']    = 50 * 1024 * 1024;      // 50MB
        $stats['traffic_limit'] = 50 * 1024 * 1024 * 10; // 500MB

        // matches: <template-item name="disk_space">1048576000</template-item>
        if (preg_match('#<template-item.*?disk_space[^>]*>([\d\.]*)</template-item>#si', $buffer, $matches)) {
            $stats['disk_space'] = $matches[1];
        }

        // matches: <template-item name="max_traffic">1572864000</template-item>
        if (preg_match('#<template-item.*?max_traffic[^>]*>([\d\.]*)</template-item>#si', $buffer, $matches)) {
            $stats['traffic_limit'] = $matches[1];
        }

        return $stats;
    }

 Digg  Del.icio.us  Reddit  SlashDot

0 comments: