• The new Python extension is now available. It allows customers to deploy and manage WSGI-based Python applications on their websites directly from Plesk.
  • The Plesk Mobile apps for iOS and Android and the Plesk Mobile Center extension have been deprecated, and are no longer available for new installations. In Plesk Obsidian 18.0.84, the Plesk Mobile Center extension will be removed from servers during the upgrade, and the Plesk Mobile apps will lose their server management features.
  • The Social Login extension has been deprecated and will be removed in Plesk Obsidian 18.0.84. After that, it will no longer be possible to log in to Plesk with a Google, Facebook, GitHub account, or with a passkey. Plesk usernames and passwords, as well as logging in with a WebPros Account, are not affected.

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