Add to Favourites Add to Favourites    Print this Article Print this Article

Actively testing a DirectAdmin connection to ensure it is running

By default, the dataskq will make sure that the "directadmin" process is running.
You can take it a step further if you'd like to confirm that DA is responding and a user/pass is working correctly.
  1. First, create a login key for a sample DirectAdmin account.
    Set:
    • Key Name: curltest
    • Key Value: Random
    • Expires On: Never
    • Uses: 0
    • Commands: Allow: CMD_API_LOGIN_TEST
    • Allowed IPs: 127.0.0.1
    and enter your current password to create the key.  The long string on the next page will be the password you'll use below.
  2. Type in your and here.
  3. Edit the script:

    /home/username/da_test.sh

    and paste in the code

    #!/bin/sh

    #DEBUG=0 normal running after settings confirmed
    #DEBUG=1 basic output during testing to confirm settings
    #DEBUG=2 raw output to see what's going on

    DEBUG=0

    USER=username
    PASSWORD=password

    CONFIG=curl_config.txt
    echo -n '' > ${CONFIG}
    echo "user = \"${USER}:${PASSWORD}\"" >> ${CONFIG}

    RUN="curl --config ${CONFIG} --silent --show-error http://127.0.0.1:2222/CMD_API_LOGIN_TEST"

    if [ "${DEBUG}" -ge 2 ]; then
           eval $RUN
    else
           #stderr to cron output
           RESULT=`eval $RUN 2>&1`
           RET=$?
           COUNT=`echo "$RESULT" | grep -c 'error=0'`
           if [ "${COUNT}" -gt 0 ]; then
                   if [ "${DEBUG}" -ge 1 ]; then
                           echo "all is well";
                   fi
                   exit 0;
           else
                   if [ "${RET}" -eq 0 ]; then
                           echo "Unable to verify login. Try DEBUG=2";
                           echo "curl returned code 0, so is likely a user/pass issue";
                           exit 1;
                   else
                           echo "$RESULT";
                           echo "curl returned code ${RET}";
                           exit ${RET}
                   fi
           fi
    fi

    and chmod to 700

    chmod 700 /home/username/da_test.sh

    If you're running DA with https, change http to https in the RUN variable.  Same applies if you're not using port 2222, adjust the port there.
  4. Manually run the script to see if it work:

    /home/username/da_test.sh; echo $?

    If you see '0' as the output, that's a good thing.  Set DEBUG to 1 or 2 to help sort out any issues.

  5. Once you're happy it's working, create a cronjob under the username account:

    User Level -> CronJobs

    Leave all time values as *, but set the command to be:

    /home/username/da_test.sh

    and do not press the "Prevent E-Mail", or else you won't get any notices.
  6. On the same Cronjobs page, type in your E-Mail in the "Send all Cron output to E-Mail" section.
    Check that account for any emails containing output if DA isn't running.

Was this answer helpful?

Also Read