Automatic Restart of Crashed Services with Systemd

On Linux distributions that use the systemd init system (Debian 8, Debian 9, CentOS/RedHat 7, Ubuntu 16, and Ubuntu 18), Plesk instructs systemd to restart certain services if they crash:

  • Plesk services (sw-cp-server, sw-engine)
  • Hosting services (PHP-FMP, nginx)
  • Certain other services (Dovecot, MariaDB, and so on)

The systemd restart has the following settings, which you can customize via panel.ini file:

  • The respawn setting controls whether crashed services are restarted automatically. The setting is enabled by default. To turn it off, change the respawn setting value to off.

  • The Service.RestartSec setting specifies the downtime in seconds after which systemd restarts a crashed service (5 seconds by default).

  • The Service.Restart setting specifies under which conditions services must be restarted. The default value of the settings is on-failure. It means that a service will be restarted when it exits with a non-zero exit code.

    The Service.Restart setting accepts the following values: no|always|on-success|on-failure|on-abnormal|on-abort|on-watchdog. See the meaning of the values.

To customize the automatic restart of the crashed services with systemd:

  1. Add the systemd settings that you want to change to the panel.ini file under the [systemd] section. For example:

    [systemd]
    Service.RestartSec = 7
    Service.Restart = always
    
  2. For the customized settings to take effect, run the command of the following pattern:

    /usr/local/psa/admin/sbin/register_service --enable <service>
    

    where <service> is any service from this list.

    For example,

    /usr/local/psa/admin/sbin/register_service --enable sw-engine
    

Then the customized settings will be applied.

Note

Certain services (for example, Fail2ban, PostgreSQL, and some others) have their own systemd restart settings, which can be different from the default ones. The restart settings customized via panel.ini will not be applied to these services.