=encoding euc-jp =head1 NAME =begin original Net::Server::Daemonize - bdpf Safe fork and daemonization utilities =end original Net::Server::Daemonize - bdpf 安全なforkとデーモン化のためのユーティリティ =head1 概要 use Net::Server::Daemonize qw(daemonize); daemonize( 'nobody', # User 'nobody', # Group '/var/state/mydaemon.pid' # PIDファイルへのパス ); =head1 説明 =begin original This module is intended to let you simply and safely daemonize your server on systems supporting the POSIX module. This means that your Perl script runs in the background, and it's process ID is stored in a file so you can easily stop it later. =end original このモジュールはPOSIXモジュールをサポートしているシステム上で 簡単かつ安全にサーバをデーモン化する。つまり、あなたのPerl スクリプトがバックグラウンドで実行される。プロセスIDはファイルに 保存されるので、後で簡単にプロセスを止めることができる。 =head1 エクスポートされる関数 =over 4 =item daemonize =begin original Main routine. Arguments are user (or userid), group (or group id or space delimited list of groups), and pid_file (path to file). This routine will check on the pid file, safely fork, create the pid file (storing the pid in the file), become another user and group, close STDIN, STDOUT and STDERR, separate from the process group (become session leader), and install $SIG{INT} to remove the pid file. In otherwords - daemonize. All errors result in a die. =end original メインルーチン。引数はuser(もしくはuserid)、group(もしくは group id、ないしはスペースで区切ったgroupのリスト)。 このルーチンはpidファイルをチェックし、安全にforkし、pidファイルを 作成し(ファイルにpidを保存する)、別のuserとgroupになり、 STDIN、STDOUT、STDERRを閉じ、プロセスグループから分離し(セッション リーダーになる)、そしてpidファイルを削除するために$SIG{INT}を 設定する。つまり、デーモンになる(daemonize)。エラーが発生すると 全てdieする。 =item safe_fork =begin original Block SIGINT during fork. No arguments. Returns pid of forked child. All errors result in a die. =end original fork中にSIGINTをブロックする。引数なし。forkされた子プロセスの pidを返す。エラーが発生すると全てdieする。 =item set_user =begin original Become another user and group. Arguments are user (or userid) and group (or group id or space delimited list of groups). =end original 別のuserとgroupになる。引数はuser(あるいはuserid)とgroup (あるいはgroup idないしはスペースで区切ったgroupのリスト)。 =item set_uid =begin original Become another user. Argument is user (or userid). All errors die. =end original 別のuserになる。引数はusre(あるいはuserid)。エラーは全てdieする。 =item set_gid =begin original Become another group. Arguments are groups (or group ids or space delimited list of groups or group ids). All errors die. =end original 別のgroupになる。引数はgroup(あるいはgroup idないしはスペースで 区切ったgroup、group idのリスト)。エラーは全てdieする。 =item get_uid =begin original Find the uid. Argument is user (userid returns userid). Returns userid. All errors die. =end original uidを見つける。引数はuser(useridはuseridを返す)。useridを 返す。エラーは全てdieする。 =item get_gid =begin original Find the gids. Arguments are groups or space delimited list of groups. All errors die. =end original gidを見つける。引数はgroupかスペースで区切ったgroupのリスト。 エラーは全てdieする。 =item is_root_user =begin original Determine if the process is running as root. Returns 1 or undef. =end original そのプロセスがrootで実行されているか判定する。1かundefを返す。 =item check_pid_file =begin original Arguments are pid_file (full path to pid_file). Checks for existance of pid_file. If file exists, open it and determine if the process that created it is still running. This is done first by checking for a /proc file system and second using a "ps" command (BSD syntax). (If neither of these options exist it assumed that the process has ended) If the process is still running, it aborts. Otherwise, returns true. All errors die. =end original 引数はpid_file(pid fileへのフルパス)。pid_fileが存在するかどうか チェックする。ファイルが存在すればそのファイルを開き、そのプロセスが まだ実行されているかどうかを調べる。これは最初に/procファイル システムを調べ、次にpsコマンド(BSD構文)を使って実行される (もしどちらの選択肢も存在しないなら、そのプロセスは終了したと 仮定される)。 そのプロセスがまだ実行されているなら破棄する。そうでなければ 真を返す。エラーは全てdieする。 =item create_pid_file. =begin original Arguments are pid_file (full path to pid_file). Calls check_pid_file. If it is successful (no pid_file exists), creates a pid file and stores $$ in the file. =end original 引数はpid_file(pid fileへのフルパス)。check_pid_fileを呼び出す。 呼び出しが成功すれば(pid_fileが存在しなければ)pidファイルを作成し、 $$をファイルに保存する。 =item unlink_pid_file =begin original Does just that. =end original 読んで字のとおり[訳補足:pidファイルを削除する]。 =back =head1 参考 L. L, The Perl Cookbook Recipe 17.15. =head1 作者 Jeremy Howard =begin original Program flow, concepts and initial work. =end original プログラムの流れ、概念、そして最初の作業を行なった。 Paul Seamons =begin original Code rework and componentization. Ongoing maintainer. =end original コードの手直しをし、コンポーネント化した。 現在の保守管理者。 =head1 LICENSE Copyright (C) 2001, Jeremy Howard j+daemonize@howard.fm Paul T Seamons perl@seamons.com http://seamons.com/ This package may be distributed under the terms of either the GNU General Public License or the Perl Artistic License All rights reserved.