Mgrctl utility


Mgrctl is a utility that is used for performing operations with a control panel and calling its functions from the command line. The default location of the utility is /usr/local/mgr5/sbin/mgrctl.

Syntax



/usr/local/mgr5/sbin/mgrctl [-m <manager>] [-u | -i [lang=<language>] | -l | [[-o <output format>] [-R | <funcname> [[<param>=<value>] ...]] [[-e ‘<param>=$<ENV_NAME>’] ...]]] 

-m - a short name of a control panel associated with the command. Enter a short name after the key: 

  • ispmgr — ispmanager;

-i — brief information about the functions of the control panel.  If the function  is specified, brief information about all its parameters will be displayed. If the parameter lang is specified, the information on a selected language  will be displayed. Possible values:ru, en. The default value is ru.

-o — information output format. Possible values: text,xml, devel,json. The default value is text.

-l — suspend a control panel. The panel is suspended with the function exit. It cannot be restarted. 

Suspending COREmanager will also suspend all the control panels on the server. Activating COREmanager will activate all the panels as well.

-u — resume the control panel that has been suspended with the -l key. 

The control panels won't be activated if:
  1. The command mgrctl -m -l was executed to suspend several control panels on the server including COREmanager.
  2. COREmanager was activated with the command mgrctl -m core -u.

-R — restart the control panel before the function is executed. 

—a function name. 

= — function parameter and its value. 

-e ‘=$’  — parameters conveyed via environment variables.

Conveying parameters via environment variables


Note
The feature is available in COREmanager version 5.325 and higher.

To convey secret data in mrgctl parameters, you can use environment variables. Run the utility with the parameter

 -e ‘<param>=$<ENV_NAME>’
Comments
— parameter name — environment variable name
Note
Put a $ sign in front of the variable name and escape the =$ argument.

Example of conveying a password

  1.   Set the password value in the SECRET_PASSWORD environment variable: 
    export SECRET_PASSWORD=secret
  2.   Create an FTP user in ISPmanager:
    /usr/local/mgr5/sbin/mgrctl -m ispmgr ftp.user.edit name=ftpuser home=/ owner=www-root -e 'passwd=$SECRET_PASSWORD' sok=ok

Examples

General examples 

Terminate the control panel

/usr/local/mgr5/sbin/mgrctl -m <manager> exit

Retrieve a list of all the mgrctl functions for the control panel

/usr/local/mgr5/sbin/mgrctl -m <manager> -i

Retrieve a list of parameters of a certain function

/usr/local/mgr5/sbin/mgrctl -m <manager> -i funcname lang=ru

Examples for ispmanager

Retrieve a list of all sites

/usr/local/mgr5/sbin/mgrctl -m ispmgr webdomain  | sed 's/=/ /' | awk '{print $2}'

A list of all sites that belong to the certain user

/usr/local/mgr5/sbin/mgrctl -m ispmgr webdomain  su=<user>  | sed 's/=/ /' | awk '{print $2}'
Details
— a User name in ispmanager.

Update all domains on external name servers

for i in $(/usr/local/mgr5/sbin/mgrctl -m ispmgr webdomain | awk '{print $1}' | awk -F = '{print $2}'); do /usr/local/mgr5/sbin/mgrctl -m ispmgr domain.fix elid=$i; done

Disable PHP for all sites

for i in $(/usr/local/mgr5/sbin/mgrctl -m ispmgr webdomain | awk '{print $1}' | awk -F = '{print $2}'); do /usr/local/mgr5/sbin/mgrctl -m ispmgr webdomain.edit php=off elid=$i sok=ok; done