Net-Server-0.85 > Net::Server::Daemonize

名前

Net::Server::Daemonize - bdpf Safe fork and daemonization utilities

Net::Server::Daemonize - bdpf 安全なforkとデーモン化のためのユーティリティ

概要

  use Net::Server::Daemonize qw(daemonize);

  daemonize(
    'nobody',                 # User
    'nobody',                 # Group 
    '/var/state/mydaemon.pid' # PIDファイルへのパス
  );

説明

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.

このモジュールはPOSIXモジュールをサポートしているシステム上で 簡単かつ安全にサーバをデーモン化する。つまり、あなたのPerl スクリプトがバックグラウンドで実行される。プロセスIDはファイルに 保存されるので、後で簡単にプロセスを止めることができる。

エクスポートされる関数

daemonize

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.

メインルーチン。引数はuser(もしくはuserid)、group(もしくは group id、ないしはスペースで区切ったgroupのリスト)。 このルーチンはpidファイルをチェックし、安全にforkし、pidファイルを 作成し(ファイルにpidを保存する)、別のuserとgroupになり、 STDIN、STDOUT、STDERRを閉じ、プロセスグループから分離し(セッション リーダーになる)、そしてpidファイルを削除するために$SIG{INT}を 設定する。つまり、デーモンになる(daemonize)。エラーが発生すると 全てdieする。

safe_fork

Block SIGINT during fork. No arguments. Returns pid of forked child. All errors result in a die.

fork中にSIGINTをブロックする。引数なし。forkされた子プロセスの pidを返す。エラーが発生すると全てdieする。

set_user

Become another user and group. Arguments are user (or userid) and group (or group id or space delimited list of groups).

別のuserとgroupになる。引数はuser(あるいはuserid)とgroup (あるいはgroup idないしはスペースで区切ったgroupのリスト)。

set_uid

Become another user. Argument is user (or userid). All errors die.

別のuserになる。引数はusre(あるいはuserid)。エラーは全てdieする。

set_gid

Become another group. Arguments are groups (or group ids or space delimited list of groups or group ids). All errors die.

別のgroupになる。引数はgroup(あるいはgroup idないしはスペースで 区切ったgroup、group idのリスト)。エラーは全てdieする。

get_uid

Find the uid. Argument is user (userid returns userid). Returns userid. All errors die.

uidを見つける。引数はuser(useridはuseridを返す)。useridを 返す。エラーは全てdieする。

get_gid

Find the gids. Arguments are groups or space delimited list of groups. All errors die.

gidを見つける。引数はgroupかスペースで区切ったgroupのリスト。 エラーは全てdieする。

is_root_user

Determine if the process is running as root. Returns 1 or undef.

そのプロセスがrootで実行されているか判定する。1かundefを返す。

check_pid_file

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.

引数はpid_file(pid fileへのフルパス)。pid_fileが存在するかどうか チェックする。ファイルが存在すればそのファイルを開き、そのプロセスが まだ実行されているかどうかを調べる。これは最初に/procファイル システムを調べ、次にpsコマンド(BSD構文)を使って実行される (もしどちらの選択肢も存在しないなら、そのプロセスは終了したと 仮定される)。 そのプロセスがまだ実行されているなら破棄する。そうでなければ 真を返す。エラーは全てdieする。

create_pid_file.

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.

引数はpid_file(pid fileへのフルパス)。check_pid_fileを呼び出す。 呼び出しが成功すれば(pid_fileが存在しなければ)pidファイルを作成し、 $$をファイルに保存する。

unlink_pid_file

Does just that.

読んで字のとおり[訳補足:pidファイルを削除する]。

参考

Net::Server. Net::Daemon, The Perl Cookbook Recipe 17.15.

作者

Jeremy Howard <j+daemonize@howard.fm>

Program flow, concepts and initial work.

プログラムの流れ、概念、そして最初の作業を行なった。

Paul Seamons <perl@seamons.com>

Code rework and componentization. Ongoing maintainer.

コードの手直しをし、コンポーネント化した。 現在の保守管理者。

ライセンス

  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.