Live Blog

Place All Sites on a GridPane Server into Maintenace Mode

Questions

Is there a command to activate/deactivate all sites on a single server into maintenance mode?

Something like

gp all-sites wp maintenance-mode activate

Solution

There isn’t anything natively within GridPane’s CLI that will do this. However, this might help you.

I created a function to list all sites on a server, excluding staging, canary and the default gridpanevps. Here is the code snippet.

ls -ld /var/www/*/ | grep -v -e 'canary' -e 'staging' -e 'gridpanevps' -e '22222' | awk '{print $9}' | sed 's|/var/www/||' | sed 's|/$||'

You can pipe this into xargs and run any command you’d like against each domain. In this case we will run gp wp domain.com maintenance-mode activate

ls -ld /var/www/*/ | grep -v -e 'canary' -e 'staging' -e 'gridpanevps' -e '22222' | awk '{print $9}' | sed 's|/var/www/||' | sed 's|/$||' | xargs -I {} gp wp {} maintenance-mode

Wrapping in a Function

If you use bash or zsh you can wrap this into a function and add it to your bash/zsh scripts. The following is for zsh, and if you pass -u you will get the sites username. I’ve tested this on bash and it seems to work fine.

gp-listsites () {
        if [[ $1 == "-u" ]]
        then
                ls -ld /var/www/*/ | grep -v -e 'canary' -e 'staging' -e 'gridpanevps' -e '22222' | awk '{print $8"\t"$3}' | sed 's|/var/www/||' | sed 's|/$||' | column -t
        elif [[ $1 == "-h" ]]
        then
                echo "Usage: ./gplistsites"
                echo "   -u   list users"
        else
                \ls -ld /var/www/*/ | grep -v -e 'canary' -e 'staging' -e 'gridpanevps' -e '22222' | awk '{print $9}' | sed 's|/var/www/||' | sed 's|/$||'
        fi
}
0 Shares: