Perl mp2 翻訳 サーバの制御と監視 (d213)

セラ (perlackline)

2021年10月12日 14:01

目次 - Perl Index


Theme



Perl について、復習を兼ねて断片的な情報を掲載して行く連載その d213 回。

今回は、mod_perl「 Documentation / General Documentation / Part IV: Server Administration / Controlling and Monitoring the Server 」を翻訳して確認します。

正確な内容は 原文 を確認してください。誤解や誤訳がある場合はご指摘ください。




説明 : Description



Covers techniques to restart mod_perl enabled Apache, SUID scripts, monitoring, and other maintenance chores, as well as some specific setups.

mod_perl が有効化された Apache のリスタート, SUID スクリプト, モニタリング, それから他のメンテナンス作業, およびいくつか特定のセットアップのテクニックをカバーします.


リスタートのテクニック : Restarting Techniques



All of these techniques require that you know the server process id (PID). The easiest way to find the PID is to look it up in the httpd.pid file. It's easy to discover where to look, by looking in the httpd.conf file. Open the file and locate the entry PidFile. Here is the line from one of my own httpd.conf files:

これらのテクニックはすべてあなたがサーバプロセス id (PID) を知っていることを要求します. PID を見つけるもっとも簡単な方法は httpd.pid ファイルを検索することです. httpd.conf を確認することで, どこを見ればよいかを簡単に発見できます. そのファイル (# httpd.conf) を開いてエントリ PidFile を見つけます. こちらは私独自の httpd.conf ファイルからの行です:

PidFile /usr/local/var/httpd_perl/run/httpd.pid

As you see, with my configuration the file is /usr/local/var/httpd_perl/run/httpd.pid.

あなたがご覧の通り, 私の構成でそのファイルは /usr/local/var/httpd_perl/run/httpd.pid です.
Another way is to use the ps and grep utilities. Assuming that the binary is called httpd_perl, we would do:

他の方法は ps と grep ユーティリティを使うことです. そのバイナリが httpd_perl と呼ばれると想定すると, 私たちはこれを行います:

% ps auxc | grep httpd_perl

or maybe:

またはおそらく:

% ps -ef | grep httpd_perl

This will produce a list of all the httpd_perl (parent and children) processes. You are looking for the parent process. If you run your server as root, you will easily locate it since it belongs to root. If you run the server as some other user (when you don't have root access, the processes will belong to that user unless defined differently in httpd.conf. It's still easy to find which is the parent--usually it's the process with the smallest PID.

これはすべての httpd_perl (parent (# 親) と children (# 子)) プロセスのリストを作成します. あなたは parent プロセスを探します. もしあなたがあなたのサーバを root として実行している場合, それは root に属しているのであなたは簡単にそれを見つけることができます. もしあなたが他のユーザとしてサーバを実行している (あなたが root アクセスをもっていない) なら, そのプロセスは httpd.conf で別に定義されていない限りはそのユーザに属します. どれが parent かを見つけるのはまだ簡単です - 通常そのプロセスは最も小さい PID です.
You will see several httpd processes running on your system, but you should never need to send signals to any of them except the parent, whose pid is in the PidFile. There are three signals that you can send to the parent: SIGTERM, SIGHUP, and SIGUSR1.

あなたはあなたのシステム上でいくつかの httpd プロセスが走っているのを見るでしょうが, あなたは PidFile に pid がある, parent を除いたそれらのいずれにもシグナルを送る必要はありません. あなたが parent に送ることができる 3 つのシグナルがあります: SIGTERM, SIGHUP, それと SIGUSR1 です.
Some folks prefer to specify signals using numerical values, rather than using symbols. If you are looking for these, check out your kill(1) man page. My page points to /usr/include/linux/signal.h, the relevant entries are:

ある人々はシンボルを使うよりも, 数値を使ったシグナルの指定を好みます. あなたがそれらを探しているなら, あなたの kill(1) man ページをチェックしてください. 私のページは /usr/include/linux/signal.h を指していて, 関連するエントリはこれです:

#define SIGHUP 1 /* hangup, generated when terminal disconnects */
#define SIGKILL 9 /* last resort */
#define SIGTERM 15 /* software termination signal */
#define SIGUSR1 30 /* user defined signal 1 */

Note that to send these signals from the command line the SIG prefix must be omitted and under some operating systems they will need to be preceded by a minus sign, e.g. kill -15 or kill -TERM followed by the PID.

コマンドラインからこれらのシグナルを送信するためには SIG プレフィクスは省略しなければならず一部オペレーティングシステムのもとではマイナスサインによって先行される必要があることに注意してください, e.g. kill -15 や kill -TERM に続けて PID です.


サーバのストップとリスタート : Server Stopping and Restarting



We will concentrate here on the implications of sending TERM, HUP, and USR1 signals (as arguments to kill(1)) to a mod_perl enabled server. See http://www.apache.org/docs/stopping.html for documentation on the implications of sending these signals to a plain Apache server.

私たちはここで TERM, HUP, それから USR1 シグナルを (kill(1) への引数として) mod_perl が有効化されたサーバに送信する意味に集中します. プレーンな Apache サーバにこれらのシグナルを送る意味についてのドキュメンテーションは http://www.apache.org/docs/stopping.html を参照してください.

By default, if a server is restarted (using kill -USR1 `cat logs/httpd.pid` or with the HUP signal), Perl scripts and modules are not reloaded. To reload PerlRequires, PerlModules, other use()'d modules and flush the Apache::Registry cache, use this directive in httpd.conf:

デフォルトでは, サーバがリスタートされた場合 (kill -USR1 `cat logs/httpd.pid` や HUP シグナルで), Perl スクリプトやモジュールはリロードされません. PerlRequires, PerlModules, その他 use() されたモジュールを読込んで Apache::Registry キャッシュをフラッシュするには, httpd.conf でこのディレクティブを使います:

PerlFreshRestart On

Make sure you read Evil things might happen when using PerlFreshRestart.

あなたは Evil things might happen when using PerlFreshRestart (PerlFreshRestart を使用すると邪悪なことが発生するかもしれない) を必ず読んでください.


Apache の終了と再起動のスピードアップ : Speeding up the Apache Termination and Restart



We've already mentioned that restart or termination can sometimes take quite a long time, (e.g. tens of seconds), for a mod_perl server. The reason for that is a call to the perl_destruct() Perl API function during the child exit phase. This will cause proper execution of END blocks found during server startup and will invoke the DESTROY method on global objects which are still alive.

私たちはすでに mod_perl サーバのリスタートや終了はかなり長い時間, (e.g. 数十秒), かかる場合があることを言及しました. その理由は child の終了フェーズの間に perl_destruct() Perl API 関数がコールされるためです. これによってサーバスタートアップ時に見つけられた END ブロックが適切に実行されてまだ生きているグローバルオブジェクトで DESTROY メソッドを呼びだします.
It is also possible that this operation may take a long time to finish, causing a long delay during a restart. Sometimes this will be followed by a series of messages appearing in the server error_log file, warning that certain child processes did not exit as expected. This happens when after a few attempts advising the child process to quit, the child is still in the middle of perl_destruct(), and a lethal KILL signal is sent, aborting any operation the child has happened to execute and brutally killing it.

このオペレーションがフィニッシュするために長い時間がかかり, リスタートの間に長い遅延が発生する可能性もあります. ときおりこれに続いてそのサーバの error_log ファイルで一連のメッセージが表示され, 特定の child プロセスが期待どおりに終了しなかったことを警告します. これは child プロセスに終了するように何度かアドバイスを試みた後で, まだその child が perl_destruct() の途中にあって, 致命的な KILL が送信され, child がたまたま実行していた操作を中断してそれを容赦なく kill したときに発生します.
If your code does not contain any END blocks or DESTROY methods which need to be run during child server shutdown, or may have these, but it's insignificant to execute them, this destruction can be avoided by setting the PERL_DESTRUCT_LEVEL environment variable to -1. For example add this setting to the httpd.conf file:

あなたのコードが child サーバがシャットダウンする間に実行する必要のある END ブロックや DESTROY メソッドを含んでいなかったり, それらを持っているが, それらの実行が重要ではない場合, このデストラクション (# 破壊) は PERL_DESTRUCT_LEVEL 環境変数を -1 にすることで回避できます. 例えばこの設定を httpd.conf ファイルに追加します:

PerlSetEnv PERL_DESTRUCT_LEVEL -1

What constitutes a significant cleanup? Any change of state outside of the current process that would not be handled by the operating system itself. So committing database transactions and removing the lock on some resource are significant operations, but closing an ordinary file isn't.

クリーンアップで重要なもの何でしょうか ? オペレーティングシステム自身では処理できないであろう現在のプロセスの外側の状態の変化です. ですからデータベーストランザクションのコミットや何らかのリソースでのロックの解除は重要な操作ですが, 普通のファイルを閉じることはそうではありません.


サーバの制御に apachectl を使う : Using apachectl to Control the Server



The Apache distribution comes with a script to control the server. It's called apachectl and it is installed into the same location as the httpd executable. We will assume for the sake of our examples that it's in /usr/local/sbin/httpd_perl/apachectl:

Apache ディストリビューションはサーバをコントロールするためのスクリプトがついてきます. それは apachectl と呼ばれそれは httpd 実行ファイルとおなじロケーションにインストールされます. 私たちは私たちの例のためにそれが /usr/local/sbin/httpd_perl/apachectl だと仮定します:
To start httpd_perl:

httpd_perl をスタートするには:

% /usr/local/sbin/httpd_perl/apachectl start

To stop httpd_perl:

httpd_perl をストップするには:

% /usr/local/sbin/httpd_perl/apachectl stop

To restart httpd_perl (if it is running, send SIGHUP; if it is not already running just start it):

httpd_perl をリスタートするには (もしそれが実行中なら, SIGHUP を送信します; それがまだ実行していないならそれをスタートするだけです):

% /usr/local/sbin/httpd_perl/apachectl restart

Do a graceful restart by sending a SIGUSR1, or start if not running:

SIGUSR1 を送信してグレイスフルリスタート, またはそれが実行されていなければスタートするには:

% /usr/local/sbin/httpd_perl/apachectl graceful

To do a configuration test:

構成テストを行うには:

% /usr/local/sbin/httpd_perl/apachectl configtest

Replace httpd_perl with httpd_docs in the above calls to control the httpd_docs server.

httpd_docs サーバをコントロールするには上記コールでの httpd_perl を httpd_docs でリプレイスしてください.
There are other options for apachectl, use the help option to see them all.

apachectl のための他のオプションがあります, それらすべてをみるには help オプションを使ってください.
It's important to remember that apachectl uses the PID file, which is specified by the PIDFILE directive in httpd.conf. If you delete the PID file by hand while the server is running, apachectl will be unable to stop or restart the server.

apachectl が PID ファイルを使うことを覚えておくことは重要です, それは httpd.conf の PIDFILE ディレクティブによって指定されます. もしあなたがサーバを実行している間に手動で PID ファイルを削除すると, apachectl はそのサーバのストップやリスタートができなくなります.


ライブプロダクションサーバ上での安全なコードのアップデート : Safe Code Updates on a Live Production Server



You have prepared a new version of code, uploaded it into a production server, restarted it and it doesn't work. What could be worse than that? You also cannot go back, because you have overwritten the good working code.

あなたは準備された新しいバージョンのコードをもち, それをプロダクションサーバにアップロードして, 再起動しましたがそれが機能しません. それよりも悪いことって何でしょう ? あなたは戻ることもできません, なぜならあなたがそのグッドに機能するコードの上書きをしたからです.
It's quite easy to prevent it, just don't overwrite the previous working files!

これを防ぐのはとても簡単で, 前に機能していたファイルを上書きしないだけです !
Personally I do all updates on the live server with the following sequence. Assume that the server root directory is /home/httpd/perl/rel. When I'm about to update the files I create a new directory /home/httpd/perl/beta, copy the old files from /home/httpd/perl/rel and update it with the new files. Then I do some last sanity checks (check file permissions are [read+executable], and run perl -c on the new modules to make sure there no errors in them). When I think I'm ready I do:

個人的に私はライブサーバでのすべてアップデートは次の順番で行います. そのサーバの root ディレクトリは /home/httpd/perl/rel だと仮定します. 私がそのファイルをアップデートしようとするとき私は新しいディレクトリ /home/httpd/perl/beta を作成し, /home/httpd/perl/rel からその古いファイルをコピーしてそれを新しいファイルでアップデートします. それから私は最後のサニティーチェック (# まともかどうかのチェック) をいくつか行います (ファイルのパーミッションが [read+executable] かをチェックし, 新しいモジュールでエラーがないことを確認するためにそれらで perl -c を実行します). 私が行う準備を私ができたと私がと思えたら:

% cd /home/httpd/perl
% mv rel old && mv beta rel && stop && sleep 3 && restart && err

Let me explain what this does.

これが何を行うのかを私に説明させてください.
Firstly, note that I put all the commands on one line, separated by &&, and only then press the Enter key. As I am working remotely, this ensures that if I suddenly lose my connection (sadly this happens sometimes) I won't leave the server down if only the stop command squeezed in. && also ensures that if any command fails, the rest won't be executed. I am using aliases (which I have already defined) to make the typing easier:

最初に, 私がすべてのコマンドを 1 行において, && で分割し, それから Enter キーを押しただけであることに注目してください. 私はリモートで作業しているので, もし私が突然私の接続を失った場合 (悲しいことにこれはときどき発生します) でも私が stop コマンドをねじ込んだがためにサーバがダウンしたままにならないことをこれが保証します. && はいずれかのコマンドが失敗した場合に, その残りが実行されないことも保証します. 私はそのタイピングを簡単にするためにエイリアス (私はそれをすでに定義してもっています) を使います:

% alias | grep apachectl
graceful /usr/local/apache/bin/apachectl graceful
rehup /usr/local/apache/sbin/apachectl restart
restart /usr/local/apache/bin/apachectl restart
start /usr/local/apache/bin/apachectl start
stop /usr/local/apache/bin/apachectl stop

% alias err
tail -f /usr/local/apache/logs/error_log

Taking the line apart piece by piece:

この行をひとつずつ分けてとります:

mv rel old &&

back up working directory to old

ワーキングディレクトリを old にバックアップします

mv beta rel &&

put the new one in its place

新しいものをその場所におきます

stop &&

stop the server

サーバをストップします

sleep 3 &&

give it a few seconds to shut down (it might take even longer)

シャットダウンのために数秒与えます (もっと長くかかるかもしれません)

restart &&

restart the server

サーバを restart します

err

view of the tail of the error_log file in order to see that everything is OK

すべてが OK であることをみるための error_log ファイルの末尾を眺める
apachectl generates the status messages a little too early (e.g. when you issue apachectl stop it says the server has been stopped, while in fact it's still running) so don't rely on it, rely on the error_log file instead.

apachectl はステータスメッセージの生成が少し早すぎるので (e.g. あなたが apachectl stop を発行したときそれはサーバがストップされたといいますが, 実際にはそれはまだ走っています) それに頼らず, 代わりに error_log ファイルを頼ります.
Also notice that I use restart and not just start. I do this because of Apache's potentially long stopping times (it depends on what you do with it of course!). If you use start and Apache hasn't yet released the port it's listening to, the start would fail and error_log would tell you that the port is in use, e.g.:

また私が start だけでなく restart を使っていることも注目してください. Apache が長い停止時間になる可能性があるので私はこれを行います (もちろんあなたがそれで何をするかによります!). もしあなたが start を使って Apache がリッスンしているポートをまだリリースしていなかった場合, その start は失敗し error_log がそのポートが使用中であることをあなたに伝えるはずです, e.g.:

Address already in use: make_sock: could not bind to port 8080

But if you use restart, it will wait for the server to quit and then will cleanly restart it.

しかしもしあなたが restart を使った場合, それはサーバが終了するの待ってクリーンにそれをリスタートするでしょう.
Now what happens if the new modules are broken? First of all, I see immediately an indication of the problems reported in the error_log file, which I tail -f immediately after a restart command. If there's a problem, I just put everything back as it was before:

これでもし新しいモジュールが壊れていたら何が起こりますか ? まず最初に, 私は restart コマンドの直後に tail -f をしているので, 私はすぐに error_log ファイルでリポートされた問題の兆候をみます. もし問題があれば, 私はすべてをこのようにして前のものに戻すだけです:

% mv rel bad && mv old rel && stop && sleep 3 && restart && err

Usually everything will be fine, and I have had only about 10 seconds of downtime, which is pretty good!

通常はすべてが正常になります, そして私がもつダウンタイムは 10 秒程度でしかありませんでした, それはかなりグッドです!


ライブスクリプトの意図的な無効化 : An Intentional Disabling of Live Scripts



What happens if you really must take down the server or disable the scripts? This situation might happen when you need to do some maintenance work on your database server. If you have to take your database down then any scripts that use it will fail.

もしあなたが本当にサーバをテイクダウンしたりスクリプトを無効にしなければならない場合は何が起こりますか ? このシチュエーションはあなたがあなたのデータベースサーバ上で何らかのメンテナンス作業を行う必要があるときに発生するかもしれません. あなたがあなたのデータベースをダウンさせなければならない場合はそれを使うスクリプトはすべてフェイル (# 失敗) するでしょう.
If you do nothing, the user will see either the grey An Error has happened message or perhaps a customized error message if you have added code to trap and customize the errors. See Redirecting Errors to the Client instead of to the error_logfor the latter case.

あなたが何もしないなら, ユーザはグレーの An Error has happened メッセージやあなたがトラップするための追加されたコードをもっていてエラーをカスタマイズしているならおそらくカスタマイズされたエラーメッセージのどちらかを見るでしょう. 後者のケースは Redirecting Errors to the Client instead of to the error_log (# error_log の代わりにクライアントにエラーをリダイレクトする) を参照してください.
A much friendlier approach is to confess to your users that you are doing some maintenance work and plead for patience, promising (keep the promise!) that the service will become fully functional in X minutes. There are a few ways to do this:

とても友好的なアプローチはあなたが何らかのメンテナンス作業をしていることをあなたのユーザに告白して辛抱をお願いし, そのサービスが X 分で完全に機能するようになることを約束する (約束は守って !) ことです. これを行うためにいくつかの方法があります:
The first doesn't require messing with the server. It works when you have to disable a script running under Apache::Registry and relies on the fact that it checks whether the file was modified before using the cached version. Obviously it won't work under other handlers because these serve the compiled version of the code and don't check to see if there was a change in the code on the disk.

1 つ目はサーバをいじくることを必要としません. あなたが Apache::Registry のもとで走っているスクリプトを無効化しなければならないときにそれは機能しそのファイルがキャッシュされたバージョンを使う前に修正されたかどうかをチェックするという事実に依存します. 他のハンドラはコンパイルされたコードのバージョンをサーブしディスク上のコードが変更されたかを確認しないので明らかにそれらの元では機能しません.
So if you want to disable an Apache::Registry script, prepare a little script like this:

ですからもしあなたが Apache::Registry スクリプトを無効化したい場合は, このような小さなスクリプトを準備してください:

/home/http/perl/maintenance.pl
#!/usr/bin/perl -Tw

use strict;
use CGI;
my $q = new CGI;
print $q->header, $q->p(
"Sorry, the service is temporarily down for maintenance.
It will be back in ten to fifteen minutes.
Please, bear with us.
Thank you!");

So if you now have to disable a script for example /home/http/perl/chat.pl, just do this:

そして今あなたが例えばスクリプト /home/http/perl/chat.pl を無効化しなければならない場合は, これを行うだけです:

% mv /home/http/perl/chat.pl /home/http/perl/chat.pl.orig
% ln -s /home/http/perl/maintenance.pl /home/http/perl/chat.pl

Of course you server configuration should allow symbolic links for this trick to work. Make sure you have the directive

もちろんこのトリックが機能するためにはあなたのサーバ構成がシンボリックリンクを許可していなければなりません. あなたがあなたの httpd.conf 内の <Location> または <Directory> 内にこのディレクティブ

Options FollowSymLinks

in the <Location> or <Directory> section of your httpd.conf.

をもっていることを確認してください.
When you're done, it's easy to restore the previous setup. Just do this:

あなたが完了したら, 以前のセットアップを簡単にリストアできます. これを行うだけです:

% mv /home/http/perl/chat.pl.orig /home/http/perl/chat.pl

wichi overwrites the symbolic link.

これはシンボリックリンクをオーバーライドします.
Now make sure that the script will have the current timestamp:

そしてそのスクリプトが現在のタイムスタンプをもっていることを確認します:

% touch /home/httpd/perl/chat.pl

Apache will automatically detect the change and will use the moved script instead.

Apache はその変更を自動的に検知してその移動されたスクリプトを代わりに使うようになります.
The second approach is to change the server configuration and configure a whole directory to be handled by a My::Maintenance handler (which you must write). For example if you write something like this:

2 番目のアプローチはサーバ構成を変更して My::Maintenance ハンドラ (これはあなたが書かねばなりません) によってディレクトリ全体が処理されるように構成します. 例えばあなたがこのようなものを書いた場合:

My/Maintenace.pm
----------------
use strict;
use Apache::Constants qw(:common);
sub handler {
my $r = shift;
print $r->send_http_header("text/plain");
print qq{
We apologize, but this service is temporarily stopped for
maintenance. It will be back in ten to fifteen minutes.
Please, bear with us. Thank you!
};
return OK;
}
1;

and put it in a directory that is in the server's @INC, to disable all the scripts in Location /perl you would replace:

それをそのサーバの @INC 内のディレクトリにおいて, Location /perl 内のすべてのスクリプトを無効化するためにあなたはリプレイスします:

<Location /perl>
SetHandler perl-script
PerlHandler My::Handler
[snip]
</Location>

with

をこれで

<Location /perl>
SetHandler perl-script
PerlHandler My::Maintenance
[snip]
</Location>

Now restart the server. Your users will be happy to go and read http://slashdot.org for ten minutes, knowing that you are working on a much better version of the service.

次にそのサーバをリスタートします. あなたのユーザはあなたがサービスのよりベターなバージョンに取り組んでいることを知ることで, ハッピーな気分で http://slashdot.org にいって 10 分間読むでしょう.
If you need to disable a location handled by some module, the second approach would work just as well.

あなたが何らかのモジュールにより処理されるロケーションを無効化する必要があるなら, 2 番目のアプローチがちょうどよく機能するでしょう.


SUID スタートアップスクリプト : SUID Start-up Scripts



If you want to allow a few people in your team to start and stop the server you will have to give them the root password, which is not a good thing to do. The less people know the password, the less problems are likely to be encountered. But there is an easy solution for this problem available on UNIX platforms. It's called a setuid executable.

あなたがあなたのチームの何人かの人にサーバのスタートとストップをできるようにしたいならあなたは彼らにその root パスワードを与えなければなりませんが, それはグッドな行為ではありません. パスワードを知る人が少ないほど, 問題に遭遇する可能性は少なくなります. しかし UNIX プラットフォームで利用可能なこの問題のための簡単なソリューションがあります. それは setuid executable (# setuid 実行可能ファイル) と呼ばれます.


SUID 実行ファイルの紹介 : Introduction to SUID Executables



The setuid executable has a setuid permissions bit set. This sets the process's effective user ID to that of the file upon execution. You perform this setting with the following command:

setuid executable は setuid パーミッションビットの設定をもっています. これはそのファイルの実行に際してプロセスの実効ユーザ ID をそれにセットします. あなたは次のコマンドでこのセッティングを実行します.

% chmod u+s filename

You probably have used setuid executables before without even knowing about it. For example when you change your password you execute the passwd utility, which among other things modifies the /etc/passwd file. In order to change this file you need root permissions, the passwd utility has the setuid bit set, therefore when you execute this utility, its effective ID is the same of the root user ID.

あなたはおそらく setuid executables について知ることなくそれを使ったことがあります. 例えばあなたが passwd ユーティリティを実行してあなたのパスワードを変更するとき, それはとりわけ /etc/passwd ファイルを変更します. このファイルを変更するためにあなたは root パーミッションが必要で, passwd ユーティリティは setuid ビットセットを持っています, したがってあなたがこのユーティリティを実行するとき, その実効 ID は root ユーザ ID と同じです.
You should avoid using setuid executables as a general practice. The less setuid executables you have the less likely that someone will find a way to break into your system, by exploiting some bug you didn't know about.

あなたは一般的なプラクティスとして setuid executables を使うことは避けなければなりません. あなたがもつ setuid executables が少ないほど誰かがあなたが知らないバグを利用して, あなたのシステムへの侵入方法をみつける可能性が少なくなります.
When the executable is setuid to root, you have to make sure that it doesn't have the group and world read and write permissions. If we take a look at the passwd utility we will see:

executable が root に setuid されているとき, あなたはそれが group と world (# あるいは other) の読込みと書込みパーミッションをもっていないことを確認しなければなりません. 私たちが passwd ユーティリティをみれば私たちはこれをみるでしょう:

% ls -l /usr/bin/passwd
-r-s--x--x 1 root root 12244 Feb 8 00:20 /usr/bin/passwd

You achieve this with the following command:

あなたは次のコマンドでこれを成すことができます:

% chmod 4511 filename

The first digit (4) stands for setuid bit, the second digit (5) is a compound of read (4) and executable (1) permissions for the user, and the third and the fourth digits are setting the executable permissions for the group and the world.

1 桁目の (4) は setuid ビットを表し, 2 桁目の (5) はユーザの読込み (4) と実行可能 (1) の複合で, 3 桁目と 4 桁目は group と world (# あるいは other) の実行可能パーミッションをセットします.


Apache スタートアップ SUID スクリプトのセキュリティ : Apache Startup SUID Script's Security



In our case, we want to allow setuid access only to a specific group of users, who all belong to the same group. For the sake of our example we will use the group named apache. It's important that users who aren't root or who don't belong to the apache group will not be able to execute this script. Therefore we perform the following commands:

このケースで, 私たちは特定のユーザグループにのみ setuid アクセスを許可したいと思います, その人たちはみな同じグループに属します. 私たちは私たちの例のために apache と名付けられたグループを使います. root でなかったり apache グループに属さないユーザはこのスクリプトを実行できないことは重要です. したがって私たちは次のコマンドを実行します:

% chgrp apache apachectl
% chmod 4510 apachectl

The execution order is important. If you swap the command execution order you will lose the setuid bit.

この実行順序は重要です. もしあなたがこのコマンドの実行順序を入れ換えるとあなたは setuid ビットを失います.
Now if we look at the file we see:

いま私たちがこのファイルを見ると私たちはこれを見ます:

% ls -l apachectl
-r-s--x--- 1 root apache 32 May 13 21:52 apachectl

Now we are all set... Almost...

これで私たちは準備万端です... ほとんど...
When you start Apache, Apache and Perl modules are being loaded, code can be executed. Since all this happens with root effective ID, any code executed as if the root user was doing that. You should be very careful because while you didn't gave anyone the root password, all the users in the apache group have an indirect root access. Which means that if Apache loads some module or executes some code that is writable by some of these users, users can plant code that will allow them to gain a shell access to root account and become a real root.

あなたの Apache をスタートすると, Apache と Perl モジュールがロードされ, コードが実行できるようになります. これはすべて root 実効 ID で起きるので, root ユーザがそれを行っているかのようにすべてのコードは実行されます. あなたが誰にも root パスワードを与えていなくても, apache グループのすべてのユーザは間接的な root アクセスをもっているのであなたはとても注意しなければなりません. つまり Apache がそれらのユーザの一部が書込める何らかのモジュールをロードしたり何かのコードを実行した場合, ユーザは root アカウントへのシェルアクセスをそれらに与えるコードを植え付けてリアルな root になることができます.
Of course if you don't trust your team you shouldn't use this solution in first place. You can try to check that all the files Apache loads aren't writable by anyone but root, but there are too many of them, especially in the mod_perl case, where many Perl modules are loaded at the server startup.

もちろんあなたがあなたのチームを信頼していないならあなたはそもそもこのソリューションを使うべきではありません. あなたは Apache がロードするすべてのファイルが root ではない誰かによって書込みができないことのチェックを試みることができますが, それらは多すぎます, 特に mod_perl のケースでは, サーバのスタート時に多くの Perl モジュールが読込まれます.
By the way, don't let all this setuid stuff to confuse you -- when the parent process is loaded, the children processes are spawned as non-root processes. This section has presented a way to allow non-root users to start the server as root user, the rest is exactly the same as if you were executing the script as root in first place.

ところで, この setuid というものに混乱しないようにしてください -- parent (# 親) プロセスがロードされたとき, その children (# 子) プロセスは非 root プロセスとして生み出されます. このセクションは非 root ユーザが root ユーザとしてサーバをスタートさせられるための方法を提示しましたが, 残り (# の処理) はあなたが最初から root としてスクリプトを実行した場合と全く同じです.


サンプル Apache スタートアップ SUID スクリプト : Sample Apache Startup SUID Script



Now if you are still with us, here is an example of the setuid Apache startup script.

さてまだあなたが私たちとともにあるならば, こちらが setuid Apache スタートアップスクリプトの例です.
Note the line marked WORKAROUND, which fixes an obscure error when starting mod_perl enabled Apache by setting the real UID to the effective UID. Without this workaround, a mismatch between the real and the effective UID causes Perl to croak on the -e switch.

WORKAROUND とマークされた行に注目してください, これは実効 UID にリアル UID を設定することによって mod_perl が有効化された Apache がスタートするときに曖昧なエラーをフィックスします. このワークアラウンド (# 回避策) がないと, リアルと実効 UID とのミスマッチに起因して -e スイッチで Perl が鳴きます (# croak).
Note that you must be using a version of Perl that recognizes and emulates the suid bits in order for this to work. This script will do different things depending on whether it is named start_httpd, stop_httpd or restart_httpd. You can use symbolic links for this purpose.

あなたはこれが機能するようにするために suid ビットを認識してエミュレートする Perl のバージョンを使わなければならないことに注意してください. このスクリプトはそれが start_httpd, stop_httpd または restart_httpd のどの名前が付けられているかによって違うことを行います. あなたはこの目的のためにシンボリックリンクを使えます.

suid_apache_ctl
---------------
#!/usr/bin/perl -T

# These constants will need to be adjusted.
# これらの定数は調整される必要あり
$PID_FILE = '/home/www/logs/httpd.pid';
$HTTPD = '/home/www/httpd -d /home/www';

# These prevent taint warnings while running suid
# これらは suid 実行中に汚染警告を防止する
$ENV{PATH} = '/bin:/usr/bin';
$ENV{IFS} = '';

# This sets the real to the effective ID, and prevents
# an obscure error when starting apache/mod_perl
# これは実効 ID にリアルをセットして, apache/mod_perl のスタート時に
# 曖昧なエラーを防止する
$< = $>; # WORKAROUND
$( = $) = 0; # set the group to root too (グループも root に)

# Do different things depending on our name
# 名前により違うことをする
($name) = $0 =~ m|([^/]+)$|;

if ($name eq 'start_httpd') {
system $HTTPD and die "Unable to start HTTP";
print "HTTP started.\n";
extit 0;
}

# extract the process id and confirm that it is numeric
# プロセス ID を抽出しそれが数字であることを確認
$pid = `cat $PID_FILE`;
$pid =~ /(\d+)/ or die "PID $pid not numeric";
$pid = $1;

if ($name eq 'stop_httpd') {
kill 'TERM',$pid or die "Unable to signal HTTP";
print "HTTP stopped.\n";
exit 0;
}

if ($name eq 'restart_httpd') {
kill 'HUP',$pid or die "Unable to signal HTTP";
print "HTTP restarted.\n";
exit 0;
}

die "Script must be named start_httpd, stop_httpd, or restart_httpd.\n";



マシンリブートの準備 : Preparing for Machine Reboot



When you run your own development box, it's okay to start the webserver by hand when you need to. On a production system it is possible that the machine the server is running on will have to be rebooted. When the reboot is completed, who is going to remember to start the server? It's easy to forget this task, and what happens if you aren't around when the machine is rebooted?

あなたがあなた独自の開発ボックスを実行するとき, あなたが必要な時に手動でウェブサーバをスタートして OK です. プロダクションシステム (# 本番環境) ではサーバが走っているマシンをリブートしなければならない可能性があります. そのリブートが完了したとき, 誰がサーバをスタートすることを覚えているでしょうか ? このタスクは簡単に忘れます, そしてもしあなたがそのマシンがリブートしたとき周囲にいなかった場合何が起きるでしょうか ?
After the server installation is complete, it's important not to forget that you need to put a script to perform the server startup and shutdown into the standard system location, for example /etc/rc.d under RedHat Linux, or /etc/init.d/apache under Debian Slink Linux.

サーバのインストールが完了した後, 標準のシステムロケーションにサーバのスタートアップとシャットダウンを実行するためのスクリプトをおくことをあなたが忘れないことは重要です, 例えば RedHat Linux では /etc/rc.d, また Slink Linux では /etc/init.d/apache です.
This is the directory which contains scripts to start and stop all the other daemons. The directory and file names vary from one Operating System (OS) to another, and even between different distributions of the same OS.

これはすべての他のデーモンをスタートとストップするためのスクリプトを含むディレクトリです. このディレクトリとファイル名はオペレーティングシステム (OS) によって, また同じ OS の違うディストリビューション間ででも異なります.
Generally the simplest solution is to copy the apachectl script to your startup directory or create a symbolic link from the startup directory to the apachectl script. You will find apachectl in the same directory as the httpd executable after Apache installation. If you have more than one Apache server you will need a separate script for each one, and of course you will have to rename them so that they can co-exist in the same directories.

一般的に最もシンプルなソリューションは apachectl スクリプトをあなたのスタートアップディレクトリにコピーするかスタートアップディレクトリから apachectl スクリプトへのシンボリックリンクを作成することです. あなたは Apache のインストールをした後に httpd 実行ファイル (# executable) と同じディレクトリで apachectl を見つけるでしょう. あなたが複数の Apache サーバを持っている場合あなたは個別にスクリプトを分ける必要があり, もちろんあなたはそれらが同じディレクトリで共存できるようにするためにそれらをリネームしなければなりません.
For example on a RedHat Linux machine with two servers, I have the following setup:

例えば 2 つのサーバをもつ RedHat Linux マシンで, 私は次のようなセットアップをもっています:

/etc/rc.d/init.d/httpd_docs
/etc/rc.d/init.d/httpd_perl
/etc/rc.d/rc3.d/S91httpd_docs -> ../init.d/httpd_docs
/etc/rc.d/rc3.d/S91httpd_perl -> ../init.d/httpd_perl
/etc/rc.d/rc6.d/K16httpd_docs -> ../init.d/httpd_docs
/etc/rc.d/rc6.d/K16httpd_perl -> ../init.d/httpd_perl

The scripts themselves reside in the /etc/rc.d/init.d directory. There are symbolic links to these scripts in other directories. The names are the same as the script names but they have numerical prefixes, which are used for executing the scripts in a particular order: the lower numbers are executed earlier.

スクリプトそれ自身は /etc/rc.d/init.d ディレクトリにあります. 他のディレクトリにはそれらへのシンボリックリンクがあります. その名前はそのスクリプト名とを同じですがそれらは数値のプレフィクスを持っています, これは特定の順序スクリプトを実行するために使われます: 小さい数が先に実効されます.
When the system starts (level 3) we want the Apache to be started when almost all of the services are running already, therefore I've used S91. For example if the mod_perl enabled Apache issues a connect_on_init() the SQL server should be started before Apache.

システムがスタートするとき (level 3) 私たちはサービスのほぼすべてがすでに走っている Apache をスタートさせたいと思います, ですから私たちは S91 を使います. 例えばもし mod_perl が有効化された Apache が connect_on_init() を発行する場合は SQL サーバは Apache の前にスタートされるべきです.
When the system shuts down (level 6), Apache should be stopped as one of the first processes, therefore I've used K16. Again if the server does some cleanup processing during the shutdown event and requires third party services to be running (e.g. SQL server) it should be stopped before these services.

システムがシャットダウンするとき (level 6), Apache は最初のプロセスの 1 つとしてストップされるべきです, ですから私たちは K16 を使います. 再びもしサーバがそのシャットダウンイベント中に何らかのクリーンアップ処理をしてサードパーティのサービスの実行 (e.g. SQL サーバ) を要求する場合それはそうしたサービスの前に停止されるべきです.
Notice that it's normal for more than one symbolic link to have the same sequence number.

複数のシンボリックリンクが同じシーケンス番号をもつのが普通であることに注目してください.
Under RedHat Linux and similar systems, when a machine is booted and its runlevel set to 3 (multiuser + network), Linux goes into /etc/rc.d/rc3.d/ and executes the scripts the symbolic links point to with the start argument. When it sees S91httpd_perl, it executes:

RedHat や同様のシステムのもとでは, マシンがブートされランレベルが 3 にセット (マルチユーザ + ネットワーク) されていると, Linux は /etc/rc.d/rc3.d/ にいってシンボリックリンクが start 引数で指し示す (# プレフィクスが S) スクリプトを実行します. それが S91httpd_perl をみると, それはこれを実行します:

/etc/rc.d/init.d/httpd_perl start

When the machine is shut down, the scripts are executed through links from the /etc/rc.d/rc6.d/ directory. This time the scripts are called with the stop argument, like this:

マシンがシャットダウンされると, /etc/rc.d/rc6.d ディレクトリからの (# プレフィクスが K の) リンクを通じてスクリプトが実行されます. このときスクリプトは stop 引数で呼ばれます, このように:

/etc/rc.d/init.d/httpd_perl stop

Most systems have GUI utilities to automate the creation of symbolic links. For example RedHat Linux includes the control-panel utility, which amongst other things includes the RunLevel Manager. (which can be invoked directly as either ntsysv(8) or tksysv(8)). This will help you to create the proper symbolic links. Of course before you use it, you should put apachectl or similar scripts into the init.d or equivalent directory. Or you can have a symbolic link to some other location instead.

ほとんどのシステムはシンボリックリンクの作成を自動化する GUI ユーティリティをもっています. 例えば RedHat Linux は control-panel ユーティリティを含んでいます, とりわけそれは RunLevel Manager を含みます. (これは ntsysv(8) または tksysv(8) として直接呼びだされることができます). これはあなたが適切なシンボリックリンクを作成することを助けます. もちろんあなたがそれを使う前に, あなたは apachectl や同様のスクリプトを init.d や同等のディレクトリに配置しなければなりません. あるいはあなたは代わりに他の場所へのシンボリックリンクを持つこともできます.
The simplest approach is to use the chkconfig(8) utility which adds and removes the services for you. The following example shows how to add an httpd_perl startup script to the system.

最もシンプルなアプローチはあなたのためにサービスを追加したり削除したりする chkconfig(8) ユーティリティを使うことです. 次の例はどのようにして httpd_perl スタートアップスクリプトをシステムに追加するを示します.
First move or copy the file into the directory /etc/rc.d/init.d:

最初にファイルを /etc/rc.d/init.d にファイルを移動またはコピーします:

% mv httpd_perl /etc/rc.d/init.d

Now open the script in your favorite editor and add the following lines after the main header of the script:

ここであなたのお気に入りのエディタでスクリプトをオープンしてそのスクリプトのメインヘッダの後に次の行を追加します:

# Comments to support chkconfig on RedHat Linux
# (RedHat Linux で chkconfig をサポートするためのコメント)
# chkconfig: 2345 91 16
# description: mod_perl enabled Apache Server
# (説明: mod_perl が有効化された Apache Server)

So now the beginning of the script looks like:

そしてそのスクリプトの始まりはこのようになります:

#!/bin/sh
#
# Apache control script designed to allow an easy command line
# interface to controlling Apache. Written by Marc Slemko,
# 1997/08/23
# (Apache のコントロールを簡単なコマンドラインインターフェイスで
# できるように設計された Apache コントロールスクリプト. Marc Slemko により書かれた,
# 1997/08/23)

# Comments to support chkconfig on RedHat Linux
# chkconfig: 2345 91 16
# description: mod_perl enabled Apache Server

#
# The exit codes retuned are:
# ...

Adjust the line:

行を調整します

# chkconfig: 2345 91 16

to your needs. The above setting says to says that the script should be started in levels 2, 3, 4, and 5, that its start priority should be 91, and that its stop priority should be 16.

あなたのニーズで. 上記セッティングはそのスクリプトがレベル 2, 3, 4 と 5 でスタートされるべきで, そのスタート優先度は 91 であり, そしてストップ優先度は 16 とするようにいっています.
Now all you have to do is to ask chkconfig to configure the startup scripts. Before we do that let's look at what we have:

これによってあなたがしなければならないことはそのスタートアップスクリプトを構成するために chkconfig に依頼をすることだけです. 私たちがそれを行う前に私たちが何をもっているのかを見てみましょう:

% find /etc/rc.d | grep httpd_perl

/etc/rc.d/init.d/httpd_perl

Which means that we only have the startup script itself. Now we execute:

これは私たちがスタートアップスクリプトそれ自体のみをもっていることを意味します. いま私たちはこれを実行して:

% chkconfig --add httpd_perl

and see waht has changed:

何が変わったかをみます:

% find /etc/rc.d | grep httpd_perl

/etc/rc.d/init.d/httpd_perl
/etc/rc.d/rc0.d/K16httpd_perl
/etc/rc.d/rc1.d/K16httpd_perl
/etc/rc.d/rc2.d/S91httpd_perl
/etc/rc.d/rc3.d/S91httpd_perl
/etc/rc.d/rc4.d/S91httpd_perl
/etc/rc.d/rc5.d/S91httpd_perl
/etc/rc.d/rc6.d/K16httpd_perl

As you can see chkconfig created all the symbolic links for us, using the startup and shutdown priorities as specified in the line:

あなたが見たとおり chkconfig はこの行で指定されたスタートアップとシャットダウンの優先度を使って, 私たちのためにすべてのシンボリックリンクを作成しました:

# chkconfig: 234 91 16

If for some reason you want to remove the service from the startup scripts, all you have to do is to tell chkconfig to remove the links:

もしあなたが何かの理由でスタートアップスクリプトからサービスを削除したいなら, あなたが行うべきことはそのリンクの削除を chkconfig に伝えることだけです:

% chkconfig --del httpd_perl

Now if we look at the files under the directory /etc/rc.d/ we see again only the script itself.

ここで私たちが /etc/rc.d/ ディレクトリの下のファイルを見ると私たちは再びそのスクリプトそれ自身だけを見ます.

% find /etc/rc.d | grep httpd_perl

/etc/rc.d/init.d/httpd_perl

Of course you may keep the startup script in any other directory as long as you can link to it. For example if you want to keep this file with all the Apache binaries in /usr/local/apache/bin, all you have to do is to provide a symbolic link to this file:

もちろんあなたがそれにリンクできる限りあなたはそのスタートアップスクリプトを他のディレクトリにキープすることもできます. 例えばあなたがこのファイルをすべての Apache バイナリと共に /usr/loca/apache/bin でキープしたいなら, あなたがやるべきなのはこのファイルへのシンボリックリンクの提供を行うことだけです:

% ln -s /usr/local/apache/bin/apachectl /etc/rc.d/init.d/httpd_perl

and then:

それから:

% chkconfig --add httpd_perl

Note that in case of using symlinks the link name in /etc/rc.d/init.d is what matters and not the name of the script the link points to.

シンボリックリンクを使うケースでは /etc/rc.d/init.d でのリンク名が大事であってリンクが指すスクリプトの名前ではないことに注意してください.


サーバを監視する. watchdog (# 番犬) : Monitoring the Server. A watchdog.



With mod_perl many things can happen to your server. It is possible that the server might die when you are not around. As with any other critical service you need to run some kind of watchdog.

mod_perl ではあなたのサーバに多くのことが起こりますえます. あなたがそばにいないときにサーバが die することもありえます. 他のクリティカルなサービスと同様にあなたは何らかの watchdog (# 監視プログラム) を実行する必要があります.
One simple solution is to use a slightly modified apachectl script, which I've named apache.watchdog. Call it from the crontab every 30 minutes -- or even every minute -- to make sure the server is up all the time.

シンプルなソリューションのひとつは少しだけ修正された apachectl スクリプトを使うことで, それを私は apache.watchdog と名付けました. サーバが常にアップしているかを確認するために crontab から 30 分ごと -- または毎分ごと -- にそれをコールしします.
The crontab entry for 30 minutes intervals:

その 30 分間隔のための crontab のエントリです:

0,30 * * * * /path/to/the/apache.watchdog >/dev/null 2>&1

The script:

そのスクリプト:

#!/bin/sh

# this script is a watchdog to see wheter the server is online
# It tries to restart the server, and if it's
# down it sends an email alert to admin
# このスクリプトはサーバがオンラインかどうかを見るための watchdog
# サーバのリスタートを試みて, それがダウンしているなら
# admin に email アラートを送信する

# admin's email
EMAIL=webmaster@example.com

# the path to your PID file
PIDFILE=/usr/local/var/httpd_perl/run/httpd.pid

# the path to your httpd binary, including options if necessary
HTTPD=/usr/local/sbin/httpd_perl/httpd_perl

# check for pidfile
if [ -f $PIDFILE ] ; then
PID=`cat $PIDFILE`

if kill -0 $PID; then
STATUS="httpd (pid $PID) running"
RUNNING=1
else
STATUS="httpd (pid $PID?) not running"
RUNNING=0
fi
else
STATUS="httpd (no pid file) not running"
RUNNING=0
fi

if [ $RUNNING -eq 0 ]; then
echo "$0 $ARG: httpd not running, trying to start"
if $HTTPD ; then
echo "$0 $ARG: http started"
mail $EMAIL -s "$0 $ARG: httpd started" > /dev/null 2>&1
else
echo "$0 $ARG: httpd could not be started"
mail $EMAIL -s \
"$0 $ARG: httpd could not be started" > /dev/null 2>&1
fi
fi

Another approach, probably even more practical, is to use the cool LWP Perl package to test the server by trying to fetch some document (script) served by the server. Why is it more practical? Because while the server can be up as a process, it can be stuck and not working. Failing to get the document will trigger restart, and "probably" the problem will go away.

他のアプローチ, おそらくよりいっそう実践的な, はそのサーバによりサーブされている何らかのドキュメント (スクリプト) を取得することをトライすることでサーバをテストするためにクールな LWP Perl パッケージを使うことです. それがより実践的なのはなぜでしょうか ? そのサーバがプロセスとしてアップできていても, それがスタックして機能しないことがあるからです. ドキュメントのゲットに失敗するとリスタートがトリガーされて, "おそらく" その問題はなくなるでしょう.
Like before we set a cronjob to call this script every few minutes to fetch some very light script. The best thing of course is to call it every minute. Why so often? If your server starts to spin and trash your disk space with multiple error messages filling the error_log, in five minutes you might run out of free disk space which might bring your system to its knees. Chances are that no other child will be able to serve requests, since the system will be too busy writing to the error_log file. Think big--if you are running a heavy service (which is very fast since you are running under mod_perl) adding one more request every minute will not be felt by the server at all.

前と同様に私たちはあるとても軽量なスクリプトをフェッチするために数分ごとにこのスクリプトをコールするように cronjob をセットしました. なぜそれほど頻繁に ? もしあなたのサーバがスピンし始めて複数のエラーメッセージが error_log を満たしてあなたのディスクスペースがめちゃくちゃにななると, 5 分以内であなたはフリーのディスクスペースを使い切ってあなたのシステムを屈服させるかもしれません. 他の child はリクエストをサーブすることができないでしょう, そのシステムは error_log ファイルへの書込みでとてもビジーになるからです. 大きく考えてください - あなたがヘビーなサービス (それはあなたが mod_perl のもとで実行しているのでとても高速です) を実行しているなら毎分のリクエストを 1 つ余分に追加してもサーバは何も感じないでしょう.
So we end up with a crontab entry like this:

ですから私たちは crontab エントリをこのようにします:

* * * * * /path/to/the/watchdog.pl >/dev/null 2>&1

And the watchdog itself:

そして watchdog それ自体がこれです:

#!/usr/bin/perl -wT

# untaint
# 非汚染
$ENV{'PATH'} = '/bin:/usr/bin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};

use strict;
use diagnostics;
use URI::URL;
use LWP::MediaTypes

my $VERSION = '0.01';
use vars qw($ua $proxy);
$proxy = '';

require LWP::UserAgent;
use HTTP::Status;

###### Config #########
my $test_script_url = 'http://www.example.com:81/perl/test.pl';
my $monitor_email = 'root@localhost';
my $restart_command = '/usr/local/sbin/httpd_perl/apachectl restart';
my $mail_program = '/usr/lib/sendmail -t -n';
######################

$ua = new LWP::UserAgent;
$ua->agent("$0/watchdog " . $ua->agent);
# Uncomment the proxy if you access a machine from behind a firewall
# あなたがファイアウォールの背後からマシンにアクセスする場合はこのプロクシをアンコメント
# $proxy = "http://www-proxy.com";
$ua->proxy('http', $proxy) if $proxy;

# If it returns '1' it means we are alive
# '1' をリターンした場合は私たちが生存していることを意味する
exit 1 if checkurl($test_script_url);

# Houston, we have a problem.
# The server seems to be down, try to restart it.
# ヒューストン, 問題が発生した.
# サーバがダウンしているようだ, リスタートを試みる.
my $status = system $restart_command;

my $message = ($status == 0)
? "Server was down and successfully restarted!"
: "Server is donw. Can't restart.";

my $subject = ($status == 0)
? "Attention! Webserver restarted"
: "Attention! Webserver is down. can't restart";

# email the monitoring person
# モニタリング担当者に email
my $to = $monitor_email;
my $from = $monitor_email;
send_mail($from,$to,$subject,$message);

# input: URL to check
# output: 1 for success, 0 for failure
#######################
sub checkurl{
my ($url) = @_;

# Fetch document
# ドキュメントの取得
my $res = $ua->request(HTTP::Request->new(GET => $url));

# Check the result status
# 結果ステータスのチェック
return 1 if is_success($res->code);

# failed
# 失敗した
return 0;
} # end of sub checkurl
# サブルーチン checkurl の終わり

# send email about the problem
# 問題についての email を送信
#######################
sub send_mail{
my ($from,$to,$subject,$messagebody) = @_;

open MAIL, "|$mail_program"
or die "Can't open a pipe to a $mail_program :$!\n";

print MAIL
関連記事