'Failed to obtain current webserver certificate ID' error when trying to use "create-backup.sh" script in custom shell script that is invoked using crontab in VMware Cloud Director
search cancel

'Failed to obtain current webserver certificate ID' error when trying to use "create-backup.sh" script in custom shell script that is invoked using crontab in VMware Cloud Director

book

Article ID: 378440

calendar_today

Updated On:

Products

VMware Cloud Director

Issue/Introduction

  • When running the custom script that uses default "create-backup.sh" script using crotab, we see below errors in the cron log:  /var/log/cron

    (sudo: psql: command not found)
    (Failed to obtain current webserver certificate ID.)

    or

    (sudo: psql: command not found)
    (Failed to obtain current JMX certificate ID.)

Environment

VMware Cloud Director 10.x

Cause

This issue occurs because the sudo command throws an error when attempting to access the root user's home directory while running as the postgres user. As a result, the certificate ID variable ends up containing an error message instead of the expected UUID. The problem becomes apparent when a sanity check is performed on the variable's contents and fails to detect a valid UUID.

Resolution

To resolve this issue modify the way sudo is invoked, follow the below steps:

  1. ssh as root to the primary VCD cell.
  2. cd /opt/vmware/appliance/bin
  3. Take a backup of the create-backup.sh by copping it to another file 

    # cp create-backup.sh create-backup.bak

  4. vi create-backup.s
  5. Change the following lines, by adding the Hiu option to the sudo command:
    1. HTTP_CERT_ID=$(sudo -u postgres psql -d vcloud -A -t -c "$HTTP_CERT_ID_SQL")
    2. JMX_CERT_ID=$(sudo -u postgres psql -d vcloud -A -t -c "$JMX_CERT_ID_SQL")

      TO:
    1. HTTP_CERT_ID=$(sudo -Hiu postgres psql -d vcloud -A -t -c "$HTTP_CERT_ID_SQL")
    2. JMX_CERT_ID=$(sudo -Hiu postgres psql -d vcloud -A -t -c "$JMX_CERT_ID_SQL")

     5. Write changes and exit the file.
           :wq

Try to run the crontab again and the backup should now work.