• Debian 11 is approaching its end-of-life (vendor EOL date - August 31, 2026). Plesk Obsidian 18.0.80 will be the last release to support it.
    If you are running Plesk Obsidian on Debian 11, we recommend you upgrade those servers to Debian 12 using our dist-upgrade tool.
  • We plan to deprecate and remove the support for XML RPC protocol versions earlier than 1.6.9.1 in Plesk Obsidian 18.0.82. We strongly recommend that you update all existing integrations using earlier versions of the XML RPC protocol to comply with the version 1.6.9.1 specification.

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