erlsrv

Section: USER COMMANDS (1)
Updated: erts 5.7
Index Return to Main Contents
 

名前

erlsrv - Erlang エミュレータをWindows NT(R)のサービスとして動作させる  

説明

このユーティリティはWindows NT/2000/XP(R)固有のものです。erlsrvを用いることで、Erlang エミュレータをサービスとして動作させることができます。よって、ユーザが再起動の度にログインをして、Erlangエミュレータを立ち上げる必要がなくなります。この方法で起動されたエミュレータは、Windows(R) サービスアプレットによって、その他のサービスと同様に管理されます。

実際のサービスと同様に、erlsrv は、サービス登録、変更、開始、停止のためのコマンドラインインターフェースを提供します。 As well as being the actual service, erlsrv also provides a command line interface for registering, changing, starting and stopping services.

サービスを管理するには、Administrator 権限でマシンにログインする必要があります。Erlang マシン自体は、デフォルトでローカル特権で動作します。起動時の特権レベルは、Windows(R)のサービスアプレットで変更することができます。

サービスから起動されたプロセスは、タスクマネージャにより"殺され"る可能性がありますます。サービスから起動されたエミュレータが殺されると、"OnFail"アクションが起動し、再起動することになるでしょう。

The following parameters may be specified for each Erlang service: Erlang サービスのパラメータとして、以下のものを指定することができます:

*
StopAction: これは erlsrv に Erlang エミュレータの停止方法を教えるためのパラメータです。デフォルトではWin32 TerminateProcessによりエミュレータを"殺し"ますが、このアクションをErlangのシェルコマンドで置換することができます。停止コマンドが発行されてから30秒以内で、エミュレータを停止させてください。もしエミュレータが停止していなければ、サービスマネージャに対して「動作中」として報告されます。 StopAction: This tells erlsrv how to stop the Erlang emulator. Default is to kill it (Win32 TerminateProcess), but this action can specify any Erlang shell command that will be executed in the emulator to make it stop. The emulator is expected to stop within 30 seconds after the command is issued in the shell. If the emulator is not stopped, it will report a running state to the service manager.
*
OnFail: このパラメータに対する値として、reboot, restart, restart_always ignore をとることができます。. reboot の場合, エミュレータが停止したことを関知すると、NTシステムが再起動します。一種の簡単なwatch dog timerのようなものです。クリティカルではないシステムに有用です。サービス停止時にパラメータが全て保持され、再起動からの復帰後Erlang エミュレータを復元します。エミュレータが10秒以内に停止するようであれば、再起動のループに陥ってしまうことを防ぐために、再起動は行われなくなります。restart_always は再起動に似ていますが、再起動のループ検知を行いません。つまり、他の方法を用いてこの問題を回避する必要があります。デフォルトでは、サービスが停止したことをサービスマネージャにレポートします。この場合は、手動でエミュレータを再起動する必要があります。

release handling が使用されているようであれば、常にignoreがセットされているのが望ましいです。 サービス停止時に再度サービスを起動するには、 heart を使用してください。

*
Machine: Erlang エミュレータの場所です。デフォルトでは、erl.exe はerlsrv.exeと同じディレクトリにあります。 エミュレータとして werl.exe を指定しないでください。起動しません。

システムが release handling を使用しているようであれば、start_erl.exe のようなプログラムがセットされるべきです。

*
Env: エミュレータに対して、 追加の 環境を設定します。 ここで指定された環境変数は、サービス立ち上がり時にシステムワイド環境ブロック(system wide environment block)に追加されます。変数はシステムワイド環境ブロックとサービス環境の両方に存在する値は、サービス内で指定された値がセットされます。 Env: Specifies an additional environment for the emulator. The environment variables specified here are added to the system wide environment block that is normally present when a service starts up. Variables present in both the system wide environment and in the service environment specification will be set to the value specified in the service.
*
WorkDir: Erlang エミュレータのワーキングディレクトリです。ローカルドライブに設定する必要があります。これは、サービス開始時にネットワークドライブが有効になっていないためです。デフォルトのワーキングディレクトリは、 %SystemDrive%%SystemPath% です。デバッグログがこのディレクトリにはき出されます。
*
Priority: エミュレータのプロセス優先度で、realtime, high, low もしくは default (デフォルト値です)のという値をとることができます。 優先度が realtime に設定されると、Erlang エミュレータのスケジューリングが最優先されます。端末を操作しているユーザへのレスポンスが低下し、操作不能になる可能性があるため、推奨されません。優先度 high は、2つのErlangノードが1台の専用システムに存在していて、その2つで優先順位をつけたいときに使用します。low は、ユーザとのやりとりのパフォーマンスを下げたくないときに使用すると良いでしょう.
*
SName or Name: Erlangエミュレータの名前を設定します。ロングネームでもショートネームでも構いません。Erlang サービスは常に分散されており(FIXME:?)、デフォルトでサービス名はショートノードネームが使用されます。 Specifies the short or long node-name of the Erlang emulator. The Erlang services are always distributed, default is to use the service name as (short) node-name.
*
DebugType: none (これがデフォルト値です), new, reuseconsole の中から選択します。 Erlang シェルから出力されるの"デバッグログ"についての設定を行います。ログ名は <servicename>. .debug <servicename>.debug.<N>,で、<N>Tは1から99までの整数です。ログファイルはWorkDirで設定したワーキングディレクトリです。reuse オプションは、常に同じログファイルを使い回します。よって、ファイル名は常に<servicename>. .debugとなります。 new オプションは、サービスが起動する毎に別のログファイルを作成します。よって、ファイル名は<servicename>.debug.<N>となります。 console オプションは、サービス毎にErlang シェル用の インタラクティブWindows(R) コンソールウインドウを開きます。 console オプションを設定すると、 StopAction 、 が自動的に無効になり、サービス開始時に起動されるコンソールウインドウは、ログアウトと同時に終了します。 また、OnFail アクションも無効化されます。もし DebugType が指定されていない場合(none)、出力は全て破棄されます。

consoleDebugType は、どんな理由であれ、production に使用するべきではありません。このオプションは、開発中のErlang サービスのデバッグを便利にするオプションに すぎませんnewreuse オプションは製品用のシステムに便利なオプションように見えます。しかし、システム管理者は、サービス稼働中、ログが無制限に増え続けることを考慮に入れておく必要があり、再起動中をのぞいて、ログを削除することはできません。まとめると、DebugType はあくまでも「デバッグ用のオプション」だということです。製品用のログを見るには、Erlangに搭載されている標準のログ機能を使用してください。 The consoleDebugType is not in any way intended for production. It is only a convenient way to debug Erlang services during development. The new and reuse options might seem convenient to have in a production system, but one has to take into account that the logs will grow indefinitely during the systems lifetime and there is no way, short of restarting the service, to truncate those logs. In short, the DebugType is intended for debugging only. Logs during production are better produced with the standard Erlang logging facilities.

*
Args: エミュレータを立ち上げるためのプログラム erl.exe に、追加オプションを渡します。ここで指定できないオプションは、-noinput (StopActions が動作しないため), -name , -sname (必ず指定する必要があるため)です。最も一般的な使い方は、 init:boot() に渡すためのクッキーとフラグを指定することです。(-s) Args: Additional arguments passed to the emulator startup program erl.exe (or start_erl.exe). Arguments that cannot be specified here are -noinput (StopActions would not work), -name and -sname (they are specified in any way. The most common use is for specifying cookies and flags to be passed to init:boot() (-s).

release handling を使用するサービス名は、 NodeName_Release という規則に従う必要があります。ここで、 NodeName は、@を含めない Erlang ノード名で、 Release はアプリケーションの現在のバージョンです。
 The naming of the service in a system that uses release handling has to follow the convention NodeName_Release, where NodeName is the first part of the Erlang nodename (up to, but not including the "@") and Release is the current release of the application.

 

使い方

erlsrv {set | add} <service-name> [<service options>]

set と add コマンドは、 それぞれErlang サービスを追加/修正します。add コマンドの最も単純な例は、全てデフォルト値を利用して、オプションを全くつけないというものです。サービス名はシステムから自動的に命名されます(mandatory)。 The set and add commands adds or modifies a Erlang service respectively. The simplest form of an add command would be completely without options in which case all default values (described above) apply. The service name is mandatory.

全てのオプションは、オプションに値なしでコマンドに渡すことができます。 この場合、値はデフォルト値が使用されます。オプションに値を与えるときは、 デフォルト値を利用しないときのみ です。erlsrv set myservice -prio -arg は優先度にデフォルト値を設定して、全ての引数を取り除きます。 Every option can be given without parameters, in which case the default value is applied. Values to the options are supplied only when the default should not be used (i.e. erlsrv set myservice -prio -arg sets the default priority and removes all arguments).

以下のオプションを利用することができます:

-st[opaction] [<erlang shell command>]:
StopAction を定義します。与えたコマンドは、サービスが停止されたときにErlangのシェルに渡されます。デフォルト値はnoneです。
-on[fail] [{reboot | restart | restart_always}]:
エミュレータが予期せず止まったときのアクションを設定します。デフォルト値は ignore に設定されています。
-m[achine] [<erl-command>]:
Erlang エミュレータへの絶対パスです。プログラム werl がこの値を利用することはありません。 デフォルト値は erlsrv.exe と同じディレクトリにある erl.exe です。release handling を利用するときに、start_erl.exe 同様このオプションが設定されている必要があります。 The complete path to the Erlang emulator, never use the werl program for this. Default is the erl.exe in the same directory as erlsrv.exe. When release handling is used, this should be set to a program similar to start_erl.exe.
-e[nv] [<variable>[=<value>]] ...:
サービス用の環境ブロックを編集します。指定された全ての環境変数は、システム環境ブロックに追加されます。もしここで指定された環境変数と同じ名前の環境変数が既に存在した場合、指定された値がシステムワイドの値を上書きします。環境変数は <variable>=<value> という風に設定することでリストに追加でき、 <variable> 単体で与えることでリストから削除することができます。環境ブロックは自動でソートされます。 1つのコマンド内で、いくつでも -env コマンドを指定することができます。 デフォルトでは、システム環境ブロックに変更を加えません(ただし、例外が2つだけあります。以下をご覧ください)。
-w[orkdir] [<directory>]:
Erlang エミュレータのワーキングディレクトリです。デフォルトではシステムディレクトリです。 The initial working directory of the Erlang emulator. Default is the system directory.
-p[riority] [{low|high|realtime}]:
Erlang エミュレータの優先度です。デフォルトでは Windows(R) のデフォルト優先度に設定されています。
{-sn[ame] | -n[ame]} [<node-name>]:
Erlang マシンのノード名で、分散環境では必須です(FIXME:アヤシイ)。デフォルトでは -sname <service name> です。 The node-name of the Erlang machine, distribution is mandatory. Default is -sname <service name>.
-d[ebugtype] [{new|reuse|console}]:
シェルの出力先を設定します。デフォルトではシェルの出力は破棄されます。このオプションはデバッグ用です。
-ar[gs] [<limited erl arguments>]:
Erlang に対して追加引数を与えます。 -noinput, -noshell , -sname/-name は与えないように気をつけてください。デフォルトでは追加引数は与えられません。サービスのクッキーファイルが捜査中のユーザと同様に必須ではないことを思い出してください。サービスはローカル管理者権限で動作します。全ての引数は1つの文字列で与えてください。もし文字列に空白を含む場合は、ダブルクオート(")でくくってください。クオートを入力したい場合は、quoted quotes(\")を使用してください(FIXME:quoted quotes?)。 Additional arguments to the Erlang emulator, avoid -noinput, -noshell and -sname/-name. Default is no additional arguments. Remember that the services cookie file is not necessarily the same as the interactive users. The service runs as the local administrator. All arguments should be given together in one string, use double quotes (") to give an argument string containing spaces and use quoted quotes (\") to give an quote within the argument string if necessary.

erlsrv {start | stop | disable | enable} <service-name>

ここでコマンドを利用する理由は、「便利だから」という理由だけです。 通常、サービスの状態を管理するにはコントロールパネルのサービスアプレットを利用します。 startstop コマンドはサービスを開始/停止するためにサービスマネージャとやりとりを行います。コマンドはサービスが実際に停止/開始するまで待ちます。サービスが無効化された上で、停止していない場合は、サービスが実際に停止するまで「無効の状態になった」と見なしません。サービスが自動モード(automatic mode)でこのコマンドが使用されると、ブート時にサービスが開始します。このコマンドはサービスをマニュアルに設定することができません。 These commands are only added for convenience, the normal way to manipulate the state of a service is through the control panels services applet. The start and stop commands communicates with the service manager for stopping and starting a service. The commands wait until the service is actually stopped or started. When disabling a service, it is not stopped, the disabled state will not take effect until the service actually is stopped. Enabling a service sets it in automatic mode, that is started at boot. This command cannot set the service to manual.

erlsrv remove <service-name>

このコマンドは登録されているオプションとともに、サービスを完全に削除します。remove コマンドを使用する前には、サービスは停止している必要があります。 This command removes the service completely with all its registered options. It will be stopped before it is removed.

erlsrv list [<service-name>]

サービス名(<service-name>)が指定されていない場合、Erlangサービス名の一覧が表示されます。もしサービス名が指定されると、サービスに与えられているオプションが全て表示されます。

erlsrv help
 

ENVIRONMENT

Erlangマシンの環境は、2つの特殊な変数によって管理されています。ERLSRV_SERVICE_名前はマシンが起動したサービスの名前です。 ERLSRV_EXECUTABLE はサービスを開始するのに使用する erlsrv.exe への完全パスです。この2つの変数は、サービスを立ち上げるための核となるユーザ定義のコマンドを作成するのに、とても便利です。サービスの再起動に利用するコマンドファイルは、以下のように簡単に記述することができます:
 The environment of an Erlang machine started as a service will contain two special variables, ERLSRV_SERVICE_名前, which is the name of the service that started the machine and ERLSRV_EXECUTABLE which is the full path to the erlsrv.exe that can be used to manipulate the service. This will come in handy when defining a heart command for your service. A command file for restarting a service will simply look like this:

@echo off
%ERLSRV_EXECUTABLE% stop %ERLSRV_SERVICE_名前%
%ERLSRV_EXECUTABLE% start %ERLSRV_SERVICE_名前%    

これで、このコマンドファイルは、核となるコマンドとして設定されたことになります。 This command file is then set as heart command.

この2つの環境変数は、起動中のサービスを検知したり、ポートプログラム(何らかのイベントを待ち受けしているプログラム)に、ログアウト時に発生する制御イベントに対する挙動を定義したい場合にも利用可能です。  

PORT PROGRAMS

プログラムがサービスのコンテキストで動作しており、端末を操作しているユーザがログオフしたとき、サービスは全てのプログラムに対して送信される制御イベントをハンドルする必要があります。コンソールサブシステム内で動作しているアプリケーション(通常はポートプログラム)は、win32 API の SetConsoleCtrlHandlr を制御ハンドラとして利用しており、このハンドラが CTRL_LOGOFF_EVENT のイベントに対して TRUE を返します。その他のアプリケーションは、 WM_ENDSESSIONWM_QUERYENDSESSION をデフォルトのウインドウプロシージャに渡します。以下に、Cで書かれた簡単なコンソール制御ハンドラの例を示します:

#include <windows.h>
/* 
** A Console control handler that ignores the log off events,
** and lets the default handler take care of other events.
*/   
BOOL WINAPI service_aware_handler(DWORD ctrl){
    if(ctrl == CTRL_LOGOFF_EVENT)
        return TRUE;
    return FALSE;
}

void initialize_handler(void){
    char buffer[2];
    /* 
     * We assume we are running as a service if this  
     * environment variable is defined
     */
    if(GetEnvironmentVariable("ERLSRV_SERVICE_名前",buffer,
                              (DWORD) 2)){
        /*
        ** Actually set the control handler
        */
        SetConsoleCtrlHandler(&service_aware_handler, TRUE);
    }
}    
 

NOTES

オプションは Unixライクなフォーマットで与えられますが、オプションやコマンドの大文字/小文字は関係ありません。また、オプションを利用するのに "-" だけでなく "/" も利用することができます。 Even though the options are described in a Unix-like format, the case of the options or commands is not relevant, and the "/" character for options can be used as well as the "-" character.

プログラムが、エミュレータの binディレクトリの中にあることに注意してください。 Erlang のルートディレクトリ直下の binディレクトリではありません。この理由は、起動中のシステム上のエミュレータをアップグレードする際に、微妙な問題が生じるためです。 新しいバージョンのランタイムシステムで既に存在する(、恐らく使用中の)実行ファイルを上書きするべきではありません。 Note that the program resides in the emulators bin-directory, not in the bin-directory directly under the Erlang root. The reasons for this are the subtle problem of upgrading the emulator on a running system, where a new version of the runtime system should not need to overwrite existing (and probably used) executables.

Erlang サービスをより簡単に操作するには、 erlsrvのバイナリを<erlang_root\bin から <erlang_root>\erts-<version>\bin ディレクトリへ移動してください。 ^fIos:find_executable/1 という Erlang の関数を利用することで、 erlsrv プログラムが Erlang 内部から利用可能になります。

To easily manipulate the Erlang services, put the <erlang_root>\erts-<version>\bin directory in the path instead of <erlang_root>\bin. The erlsrv program can be found from inside Erlang by using the os:find_executable/1 Erlang function.

release handling を有効化するには、 Erlang マシンの start_erl を使用してください。ここでもサービス名が非常に重要であることは、上記で述べた通りです。 For release handling to work, use start_erl as the Erlang machine. It is also worth mentioning again that the name of the service is significant (see above).  

関連項目

start_erl(1), release_handler(3)


 

Index

名前
説明
使い方
ENVIRONMENT
PORT PROGRAMS
NOTES
関連項目

This document was created by man2html, using the manual pages.
Time: 10:36:09 GMT, August 01, 2009