Drupal 7 メンテナンス

Nid: 1222
  • Posted on: 15 February 2019
  • By: admin

全サイトで drush st コマンドを実行して、Drupal バージョンを確認

drush alias を使用すると、aliasを設定していないサイトの確認もれが生じるので、for 文で存在しているサイトをすべてチェック。ディレクトリ名が、サイト名のDNSと一致していることが前提。CMSの判定はしていないので、wordpressなど、drupal以外のサイトはエラーが発生して特に処理しない。

$ for website in `ls -d /var/www/html/*/ | xargs -l basename` ; do cd /var/www/html/$website;echo -n $PWD && drush -y st --fields=drupal-version 2>/dev/null | sed 's/[a-zA-Z:]//g'; done | grep --color=never .
/var/www/html/octaviadata.com       7.63
/var/www/html/tech.octaviadata.com       7.61
...

特定モジュールのバージョンをチェック。Views モジュールの例

$ for website in `ls -d /var/www/html/*/ | xargs -l basename` ; do cd /var/www/html/$website;echo -n $PWD && drush -y pmi views --fields=version 2>/dev/null | sed 's/[a-zA-Z:]//g'; done | grep --color=never .
/var/www/html/octaviadata.com       7.-3.21
/var/www/html/tech.octaviadata.com       7.-3.21
...

メンテナンス用にサイト名文字列を作成

$ ls -d /var/www/html/*/ | xargs -l basename | xargs
octaviadata.com tech.octaviadata.com ...

メンテナンスの必要なサイトを指定して、アップデート、cron実行、キャッシュクリア、ディレクトリパーミッション設定を一括実行

エラー時には、後続処理を実行しない。

$ for website in octaviadata.com tech.octaviadata.com ... ; do cd /var/www/html/$website;sudo sh -c "drush pm-updatestatus 2>/dev/null && drush -y l10n-update; drush -y pm-update && drush -y updatedb && drush cron -d && drush cc all && chown -R www-data:www-data . && find . -type f -exec chmod 444 '{}' \; && find . -type d -exec chmod 555 '{}' \; && chmod a+w sites/default/files && chmod 444 sites/default/settings.php && find sites/default/files -type d -print0 | xargs -0 chmod 755"; done

全ディレクトリに対してメンテナンスを実行する場合。

$ for website in `ls -d /var/www/html/*/ | xargs -l basename` ; do cd /var/www/html/$website; sudo sh -c "drush pm-updatestatus 2>/dev/null && drush -y l10n-update; drush -y pm-update && drush -y updatedb && drush cron -d && drush cc all && chown -R www-data:www-data . && find . -type f -exec chmod 444 '{}' \; && find . -type d -exec chmod 555 '{}' \; && chmod a+w sites/default/files && chmod 444 sites/default/settings.php && find sites/default/files -type d -print0 | xargs -0 chmod 755"; done

module をアンインストール。

$ dpmunused='views_bulk_operations admin_views optimizedb matomo amazon' && sudo sh -c "drush dis $dpmunused -y && drush pm-uninstall $dpmunused -y"
views_bulk_operations is already disabled.                                                      [ok]
admin_views is already disabled.                                                                [ok]
optimizedb is already disabled.                                                                 [ok]
There were no extensions that could be disabled.                                                [ok]
views_bulk_operations is already uninstalled.                                                   [ok]
admin_views is already uninstalled.                                                             [ok]
optimizedb is already uninstalled.                                                              [ok]
Module matomo was not found and will not be uninstalled.                                        [warning]
Module amazon was not found and will not be uninstalled.                                        [warning]
There were no modules that could be uninstalled.                                                [ok]

" is already uninstalled. "は、アンインストールしたがディレクトリの残っている状態。
" was not found and will not be uninstalled. "は、完全にアンインストールできている状態。 以下のコマンドは、アンインストールされているモジュールについて残っているディレクトリを表示させる。必要に応じてディレクトリを削除。

$ drush pm-list --type=Module --pipe --no-core --status="Not installed" | while read -r module; do  find sites/all/modules -type d  -name "$module"; done
sites/all/modules/admin_views
...
sites/all/modules/optimizedb
...

DrupalサイトのDB最適化

$ cd /var/www/html/$website
$ drush sql-query "SELECT DATABASE();" | grep -v 'DATABASE()' #データベース名確認
db_octaviadata.com
$ sudo mysqlcheck -u root --optimize db_octaviadata.com