Articles in this section

How to change log rotation settings in Plesk for all domains at once?

Plesk for Windows kb: how-to Plesk for Linux ABT: Group B

Applicable to:

  • Plesk for Linux
  • Plesk for Windows

Question

How to change log rotation settings in Plesk for all domains at once?

Answer

It can be performed using Plesk command line utility or Plesk API-XML request:

Command line utility for Linux:

Connect to the server via SSH and use the following command change log rotation setting for all domains:

# plesk bin domain -l| while read dom_name; do plesk bin domain -u $dom_name -log-bytime weekly; done

This command is switching log rotation condition to By time and sets log rotation period as 1 week.

To disable sending email about rotated log for all domains at once:

  • Create list of all domains on the server:

    plesk bin site --list > /root/domains.txt

  • Run the command to disable sending notifications:

    cat /root/domains.txt | while read i; do plesk bin site -u $i -log-email ""; done

Get an additional information about the plesk bin domain utility options by the following command:

# plesk bin domain --help

Also, it is possible to use CLI commands to update rotation settings on a service plan level, or on a domain/subscription level. For example, to enable log rotation on the domain example.com once the current log file reaches the 200 KB size (by-size rotation), use the following command:

# plesk bin subscription -u example.com -log-bysize 200K

To enable weekly log rotation (by-time rotation) on the domain example.com:

# plesk bin subscription -u example.com -log-bytime weekly

To enable log rotation once the current log file reaches the 20 KB size on websites created by users of the plan Plan 1:

# plesk bin service_plan -u "Plan 1" -log_bysize 20K

To set weekly log rotation for subscriptions created by the plan Plan 1:

# plesk bin service_plan -u "Plan 1" -log-bytime weekly

Visit Reference for Command-Line Utilities for Linux guide for additional details about 'plesk bin service_plan -u' and 'plesk bin subscription -u' commands options.

Command line utility for Windows

Connect to the server via RDP and use the attached file in order to change log rotation setting for all or several websites.

Unzip the .bat file, run it as Administrator and follow the instructions inside.

Using Plesk API request

Modify log rotation settings using Plesk API request.

Send the API request to Plesk website. In the following example, XML API request changes log rotation setting for all domains of admin account

CONFIG_TEXT: <packet version="1.6.3.0">
<log-rotation>
<set>
<filter>
<owner-id>1</owner-id>
</filter>
<settings>
<log-condition>
<log-bytime>Weekly</log-bytime>
</log-condition>
</settings>
</set>
</log-rotation>
</packet>

This API request switch log rotation condition to By time and sets log rotation period as 1 week.

For Plesk Multi-Server:

The command line utility usage in Plesk Multi Server is different from standalone Plesk. Therefore, there's no way to use the command line utilities as on the standalone server. To update Log Rotation settings, use GUI instead.

Alternatively, use API requests from the command line to manage the domains:

  1. Connect to the management node via SSH
  2. Download the script attached and unpack it.
  3. Open the script for editing in any text file and define values:

    CONFIG_TEXT: snhost=""
    user="admin"
    password=""

    Specify service node IP address and admin's password in snhost and password parameters.

    Also define log rotation settings. In the script there is an example of:

    CONFIG_TEXT: <log-bysize>2097152</log-bysize>
    <log-max-num-files>10</log-max-num-files>
    <log-compress>true</log-compress>

    It will set log rotation by size in bytes, will keep maximum 10 log files and will compress logs.

    The script will connect to the required service node (the one that will be specified in snhost), take the list of all domains and generate the API requests to enable and configure the rotation according to settings defined in <log-bysize>, <log-max-num-files> and <log-compress>.

  4. Use the script:

    # sh ./api-request.sh

Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.