「コマンドラインによる管理」の版間の差分

提供:MoodleDocs
移動先:案内検索
51行目: 51行目:
===コマンドライン経由でのアップグレードの問題===
===コマンドライン経由でのアップグレードの問題===


if your config.php contains information about several moodle instances (distinct moodle websites and databases sharing the same codebase), then this script will silently fail
あなたのconfig.phpが複数のMoodleインスタンスの情報を含んでいる場合 (同じコードを共有している異なるMoodleウェブサイトおよびデータベース)、このスクリプトは静かに実行失敗となります。


The solution is to temporarily eliminate from config.php all but the one instance you want to upgrade  
The solution is to temporarily eliminate from config.php all but the one instance you want to upgrade  

2012年6月6日 (水) 16:00時点における版

作成中です - Mitsuhiro Yoshida

あなたのウェブサーバにシェルアクセスできる場合、Moodle管理に有用な様々なCLI (command line interface コマンドライン・インターフェース) を見つけることができるでしょう。すべてのコマンドラインツールは admin/cli/* ディレクトリ内にあります。アクセスコントロールの問題を避けるには、ウェブサーバプロセスのオーナーとして実行してください。CLIによるインストールおよびアップグレード時に新しいファイルをmoodledataディレクトリに作成するため、ウェブサーバにディレクトリへの書き込み権限が与えてあることは特に重要です。Linuxディストリビューションでは、通常ウェブサーバを実行するユーザは「apache」または「wwrun」または「httpd」のようになっています。rootとして、恐らく、あなたは次のようにMoodle CLIスクリプトを実行したいことでしょう:

   $ cd /path/to/your/moodle/dir
   $ sudo -u apache /usr/bin/php admin/cli/somescript.php --params

使用方法の詳細説明を表示するため、ほとんどのスクリプトでは一般的な --help (または -h) パラメータを使うことができます。例えば下記のように使います:

   $ sudo -u apache /usr/bin/php admin/cli/install.php --help


コマンドライン経由のインストール

バージョン2.0以降、Moodleではコマンドラインを使ってインストールすることができます。インストールには2つのモードがあります。インタラクティブモードでは、インストールスクリプトが新しいMoodleサイトをセットアップするために必要なデータすべてに関して、あなたに尋ねます。非インタラクティブモードでは、あなたはスクリプトパラメータとして、すべての必須データを提供することにより、新しいサイトが静かにインストールされます。インタラクティブモードでもパラメータを渡すことができます。渡された値はインタラクティブセッション中、デフォルト値として使用されます。

   $ sudo -u apache /usr/bin/php admin/cli/install.php --lang=cs

メンテナンスモード

あなたのサイトをCLI経由でメンテナンスモードにスイッチするには、下記コマンドを実行してください。

   $ sudo -u apache /usr/bin/php admin/cli/maintenance.php --enable

メンテナンスモードをOFFにするには、同様のスクリプトを --disable parameter オプションを付けて実行してください。

オフラインモード

場合によってはウェブ経由でアクセスできないよう、あなたのMoodleサイトオフラインモードにスイッチしたいこともあるでしょう。しかし、ウェブサーバを完全に停止することはできません (一般的に他のページが存在しているか、他のアプリケーションが動作しているからです)。moodledataディレクトリのルートフォルダ内に「climaintenance.html」というファイル名のファイルが存在する場合、Moodleはこのファイルのコンテンツを他のページの代わりに表示します。

   $ cd /var/www/sites/moodle/moodledata/
   $ echo '<h1>Sorry, maintenance in progress</h1>' > climaintenance.html

あなたのユーザにサーバ停止を知らせるため、moodledataディレクトリ内にHTMLフォーマットで作成したclimaintenance.offのような名称のファイルを準備することができるでしょう。そして、必要に応じて、そのファイルをclimaintenance.htmlにリネームすることができます。

コマンドラインを使ったアップグレード

Moodleはコマンドラインからアップグレードすることができます。インストールスクリプトと同じように、アップグレードにはインタラクティブおよび非インタラクティブモードがあります。スクリプト自体はサイトをメンテナンスモードにしないため、あなた自身でスイッチする必要があります。また、このスクリプトはデータをバックアップしません (恐らく、このドキュメントを読んでいるあなたは、恐らくmoodledataおよびデータベースをバックアップする独自スクリプトをお持ちですよね?)。

   $ sudo -u apache /usr/bin/php admin/cli/upgrade.php --non-interactive

あなたがMoodleコードの取得にCVSまたはgitを使用している場合、コマンドライン経由でのアップグレードは非常に快適な方法です。以下の手順では、最終的なローカルのカスタマイズを保持したままgitリポジトリでトラック (追跡 track) して、あなたのサイトを数秒で最新バージョンにアップグレードする方法を記します:

   $ cd /var/www/sites/moodle/htdocs/
   $ git fetch
   $ sudo -u apache /usr/bin/php admin/cli/maintenance.php --enable
   $ git merge origin/cvshead
   $ sudo -u apache /usr/bin/php admin/cli/upgrade.php
   $ sudo -u apache /usr/bin/php admin/cli/maintenance.php --disable

コマンドライン経由でのアップグレードの問題

あなたのconfig.phpが複数のMoodleインスタンスの情報を含んでいる場合 (同じコードを共有している異なるMoodleウェブサイトおよびデータベース)、このスクリプトは静かに実行失敗となります。

The solution is to temporarily eliminate from config.php all but the one instance you want to upgrade

If this is a problem for the other instances (production sites), then modify the cli script to point to a copy of config.php (which will be the one edited to contain only one moodle instance at a time)

Custom site defaults

During the install and upgrade via CLI, Moodle sets the administration variables to the default values. You can use different defaults. See MDL-17850 for details. Shortly, all you need to do is to add a file local/defaults.php into your Moodle installation. The format of the file is like

<?php $defaults['pluginname']['settingname'] = 'settingvalue'; // for plugins $defaults['moodle']['settingname'] = 'settingvalue'; // for core settings

These defaults are used during install, upgrade and are also displayed as defaults at the Site administration pages.

Reset user password

If you happen to forget your admin password (or you want to set a password for any other user of your Moodle system), you can use reset_password.php script. The script sets the correctly salted password for the given user.

   $ sudo -u apache /usr/bin/php admin/cli/reset_password.php

MySQL storage engine conversion

If you run your Moodle site with MySQL database backend and use the default MyISAM as the storage engine for your tables, you may want to convert them to use some more reliable engine like InnoDB (actually, you should want to switch to PostgreSQL ;-) anyway).

   $ sudo -u apache /usr/bin/php admin/cli/mysql_engine.php --engine=InnoDB

Running cron via command line

In versions 1.x, you could execute admin/cron.php either from command line or via the web. Since Moodle 2.0, only admin/cli/cron.php script can be run via command line.