• The APS Catalog has been deprecated and removed from all Plesk Obsidian versions.
    Applications already installed from the APS Catalog will continue working. However, Plesk will no longer provide support for APS applications.
  • Please be aware: with the Plesk Obsidian 18.0.78 release, the support for the ngx_pagespeed.so module will be deprecated and removed from the sw-nginx package.

Question Disable domains when running CRON

ruben_0129

New Pleskian
Hello,

I have Plesk Onyx on Ubuntu 16

I run a CRON to optimize and repair the database every day.

I wish that when this CRON is run the domains will be deactivated.

Is there any way to do it?

A greeting.
 
You could run command like:

# for i in `mysql -uadmin -p\`cat /etc/psa/.psa.shadow\` psa -Ns -e "select name from domains"`; do /usr/local/psa/bin/domain --off $i; done

at the beginning of your cron script and:

# for i in `mysql -uadmin -p\`cat /etc/psa/.psa.shadow\` psa -Ns -e "select name from domains"`; do /usr/local/psa/bin/domain --on $i; done

at the end of script.
 
That's not enough.
You need to also "remember" these domains that were disabled before starting the job or else you're gonna enable those afterward as well.
 
You could run command like:

# for i in `mysql -uadmin -p\`cat /etc/psa/.psa.shadow\` psa -Ns -e "select name from domains"`; do /usr/local/psa/bin/domain --off $i; done

at the beginning of your cron script and:

# for i in `mysql -uadmin -p\`cat /etc/psa/.psa.shadow\` psa -Ns -e "select name from domains"`; do /usr/local/psa/bin/domain --on $i; done

at the end of script.

Could this command be executed with a -all?

It would be all domains. (29)

Thanks!
 
Yes, these commands will disable/enable ALL domains. But you can use appropriate mysql select for necessary conditions there.
 
This approach would not enable all the domains of your server and preserve the ones that were already set inactive.

It would only act upon the domains that are active.
It therefore preserves the state of your server before it executed the script.

Code:
#!/bin/bash

TMPDIR=`mktemp -t -d ${0//*\/}.XXXXXXXXXX`

mysql -uadmin -p`cat /etc/psa/.psa.shadow` psa -Ns -e "select name from domains where status=0" 2>/dev/null >${TMPDIR}/domains

while read DOMAIN ; do
  /usr/local/psa/bin/domain --off ${DOMAIN}
done <${TMPDIR}/domains

echo "Do your thing"

while read DOMAIN ; do
  /usr/local/psa/bin/domain --on ${DOMAIN}
done <${TMPDIR}/domains

rm -r ${TMPDIR}
 
Back
Top