Could not update domain vhost structure: "ERROR: Cannot relink logs"

Refers to:

  • Plesk for Linux

Created:

2016-11-16 12:48:30 UTC

Modified:

2016-12-21 19:15:50 UTC

0

Was this article helpful?


Have more questions?

Submit a request

Could not update domain vhost structure: "ERROR: Cannot relink logs"

Symptoms

  1. During an upgrade to Plesk 11.5, the following errors occur:

    ERR (3)  [util_exec]: proc_close() failed
    Error: mkdir: cannot create directory './example.com/logs': File exists
    ERROR: Cannot relink logs. Target directory '/var/www/vhosts/example.com/logs' is in invalid state.
  2. When attempting to add a new domain, this error occurs:

    Error: mkdir: cannot create directory './example.com/logs': File exists
    ERROR: Cannot relink logs. Target directory '/var/www/vhosts/example.com/logs' is in invalid state.
  3. Statistics calculation fails with error:

    # /usr/local/psa/admin/bin/statistics --calculate-one --domain-name=example.com
    WARNING during statistics_collector execution: : './example.com/logs' already exists, but has wrong access rights. Specify --force to override.
    statistics_collector: /opt/psa/admin/sbin/relink-vhost-logs execution failed:
    ERROR: Cannot relink logs. Target directory '/var/www/vhosts/example.com/logs' is in invalid state.
  4. The following error appears when trying to change webstatistics tool from Webalizer to Awstats and vice versa:

    WARNING during statistics_collector execution: : statistics_collector[1153]: Relinking of virtual host logs `/opt/psa/admin/sbin/relink-vhost-logs --domain-name example.com --sys-user-login domain' failed with code 3.
    Stdout:'./example.com/logs' already exists, but has wrong access rights. Specify --force to override.
    Stderr:ERROR: Cannot relink logs. Target directory '/var/www/vhosts/example.com/logs' is in invalid state.

Cause

There are two possible causes of the issues described above:

  1. Incorrect permissions/ownership set for the logs directory '/var/www/vhosts/example.com/logs ' and files in that directory.

  2. Domain system users are being placed in the wrong order in the '/etc/passwd' file. A domain System user should be placed higher than Web users of the same domain.

Resolution

  1. Check the permissions for '/var/www/vhosts/example.com/logs' . If it exists, the owner of this directory should be a FTP user. You may see the file or directory has the wrong user (not FTP) as below:

    # ls -la /var/www/vhosts/example.com/logs
    drwx------ 2 ftp_user root 4096 6. Feb 02:12 .
    drwx--x--- 11 wrong_user psaserv 4096 6. Feb 02:27 ..
    -rw-r--r-- 2 root root 0 5. Feb 07:09 access_log
    -rw-r--r-- 2 root root 0 5. Feb 07:09 access_ssl_log
  2. Make sure that microupdate #46 has been installed.

  3. Run the following command with superuser privileges:
    # /usr/local/psa/bin/repair --restore-vhosts-permissions

If the issue persists and the owner is not changed, this means that domain system users are being placed in the wrong order in the /etc/passwd file. In this case:

  1. Back up your current /etc/passwd file.

    # cp -a /etc/passwd /etc/passwd.backup
  2. Find all the system users of the affected domain:

    ~# grep example.com /etc/passwd
    web_user:x:10007:503::/var/www/vhosts/example.com/web_users/webuser:/bin/false
    ftp_user:x:10007:503::/var/www/vhosts/example.com:/bin/false
  3. Users who have the /web_users/ folder in their home directory path are Web users .

  4. Place them below users who have a home directory such as /var/www/vhosts/example.com . The correct order should be FTP user then Web user, as below:

    ftp_user:x:10007:503::/var/www/vhosts/example.com:/bin/false
    web_user:x:10007:503::/var/www/vhosts/example.com/web_users/webuser:/bin/false
  5. Update the vhost structure:

    /usr/local/psa/bin/repair --update-vhosts-structure

5.1 If executing of /usr/local/psa/bin/repair --update-vhosts-structure fails with message below

    Error: mkdir: cannot create directory './example.com/logs': File exists

Rename logs directory and run such command again:

    # mv /home/httpd/vhosts/example.com/logs /var/www/vhosts/example.com/logs.saved
# /usr/local/psa/bin/repair --update-vhosts-structure

Note: The issue may be caused by the nscd service. Plesk creates all users in one subscription with the same UID:

# grep -n 10618 /etc/passwd
342:main_user:x:10618:504::/var/www/vhosts/example.com:/bin/bash
569:ftp_user:x:10618:504::/var/www/vhosts/example.com/ovizo:/bin/false

In this case, when you request the username by its UID, it returns the username that is located on the higher line in the /etc/passwd file:

# getent passwd 10618
main_user:x:10618:504::/var/www/vhosts/example.com:/bin/bash

But if the nscd service is running, the command above could show another user because it also checks the nscd password cache located in the /var/db/nscd/passwd file:

# getent passwd 10618
569:ftp_user:x:10618:504::/var/www/vhosts/example.com/ovizo:/bin/false

As a result, you see the following error:

ERROR: Cannot relink logs. Target directory '/var/www/vhosts/example.com/logs' is in invalid state.

To avoid this behavior:

  1. Clear the nscd daemon passwd cache using the following command:

    nscd --invalidate=passwd
  2. Stop the nscd service prior to the upgrade process.

Have more questions? Submit a request
Please sign in to leave a comment.