WildFly: デプロイ時のnameとruntime-nameの役割
WildFlyへのCLIツールを利用したデプロイ時に--name
オプションと--runtime-name
オプションがあり、それぞれが何を意味しているのか分からなかったため、実験しつつ調べてみました。
まずはヘルプを読む
ざっくり把握した内容
name
はユニークでなければならない- 明示的に指定されなければ、ファイル名(war)がそのまま
name
になる runtime-name
はユニークである必要はないruntime-name
が重複している場合、どれか一つしか起動できない
[standalone@localhost:9990 /] deploy --help SYNOPSIS deploy ((file_path | --url=deployment_url) [--script=script_name] [--name=deployment_name] [--runtime-name=deployment_runtime_name] [--force | --disabled] [--unmanaged]) | --name=deployment_name [--server-groups=group_name (,group_name)* | --all-server-groups] [--headers={operation_header (;operation_header)*}] DESCRIPTION Deploys the application designated by the file_path or enables an already existing but disabled in the repository deployment designated by the name argument. If executed w/o arguments, will list all the existing deployments. ARGUMENTS ...(中略)... --name - the unique name of the deployment. If the file path argument is specified the name argument is optional with the file name been the default value. If the file path argument isn't specified then the command is supposed to enable an already existing but disabled deployment, and in this case the name argument is required. --runtime-name - optional, the runtime name for the deployment. This will form the basis for such things as default Java EE application and module names. This would typically be the same as --name, and if not specified the value used for --name will be used. In some cases users may wish to have two deployments with the same 'runtime-name' (e.g. two versions of "example.war") both available in the management configuration, in which case the deployments would need to have distinct 'name' values but would have the same 'runtime-name'. Within an individual server, only one deployment with a given 'runtime-name' can deployed. However, multiple deployments with the same 'runtime-name' can exist in the configuration, so long as only one is enabled. ...(略)...
サンプルアプリケーション
2つのごく単純なアプリケーション(war)を用意
- app-a.war: 「Hello, A」と表示
- app-b.war: 「Hello, B」と表示
何もオプションを指定せずデプロイ
NAME
とRUNTIME-NAME
はどちらもそのままwarファイル名となります。
アプリケーションにアクセスする際も、warファイル名がURLに含まれます(suffixは除く)。
- http://localhost:8080/app-a/
- 「Hello, A」と表示される
- http://localhost:8080/app-b/
- 「Hello, B」と表示される
[standalone@localhost:9990 /] deploy app-a.war [standalone@localhost:9990 /] deployment-info NAME RUNTIME-NAME PERSISTENT ENABLED STATUS app-a.war app-a.war true true OK app-b.war app-b.war true true OK
アンデプロイする時はNAME
(=warファイル名)を指定します。
ファイルは残してdisabled
状態にしたい場合は、--keep-content
オプションを付けます。
この状態でアクセスすると、どちらも「404 - Not Found」と表示されます。
[standalone@localhost:9990 /] undeploy app-a.war [standalone@localhost:9990 /] undeploy app-b.war --keep-content [standalone@localhost:9990 /] deployment-info NAME RUNTIME-NAME PERSISTENT ENABLED STATUS app-b.war app-b.war true false STOPPED
--name
オプションを指定してデプロイ
hoge.war
にすると/hoge
でアクセス出来るようになります。
- http://localhost:8080/A/
- 「Hello, A」と表示される
- http://localhost:8080/B/
- 「Hello, B」と表示される
[standalone@localhost:9990 /] deploy app-a.war --name=A.war [standalone@localhost:9990 /] deploy app-b.war --name=B.war [standalone@localhost:9990 /] deployment-info NAME RUNTIME-NAME PERSISTENT ENABLED STATUS A.war A.war true true OK B.war B.war true true OK
アンデプロイは自分で指定したNAME
でやります。
[standalone@localhost:9990 /] undeploy A.war [standalone@localhost:9990 /] undeploy B.war
--runtime-name
オプションを指定してデプロイ
どちらもapp.war
というruntime-name
で起動しようとしてみます。
[standalone@localhost:9990 /] deploy app-a.war --runtime-name=app.war [standalone@localhost:9990 /] deployment-info NAME RUNTIME-NAME PERSISTENT ENABLED STATUS app-a.war app.war true true OK [standalone@localhost:9990 /] deploy app-b.war --runtime-name=app.war {"JBAS014653: Composite operation failed and was rolled back. Steps that failed:" => {"Operation step-1" => "JBAS018785: There is already a deployment called app-a.war with the same runtime name app.war"}}
app-b.war
のほうは、runtime-name
がかぶってしまったため、デプロイ失敗しました。
この状態で http://localhost:8080/app/ にアクセスすると「Hello, A」と表示されます。
次に、app-a.war
をdisabled
状態に変えて、app-b.war
をデプロイしてみます。
[standalone@localhost:9990 /] undeploy app-a.war --keep-content [standalone@localhost:9990 /] deploy app-b.war --runtime-name=app.war [standalone@localhost:9990 /] deployment-info NAME RUNTIME-NAME PERSISTENT ENABLED STATUS app-a.war app.war true false STOPPED app-b.war app.war true true OK
この状態で http://localhost:8080/app/ にアクセスすると「Hello, B」という表示に変わっています。
まとめ
name
は管理上利用する名称- デプロイ・アンデプロイ時のコマンドの引数として与える
- ユニークでなければならない
runtime-name
はURLの一部となる- ユニークである必要はない
- 同一の
runtime-name
のものは、どれか1つしかデプロイ状態にできない