Chefを使ってWebLogic Serverを停止してみた


概要

Chefを使ってWebLogic Serverをインストール、ドメイン作成、そして管理サーバの起動までChefで自動実行してみました。

しかし、このままでは起動したままなので停止もChefで実行できるようにしてみます。

WebLogic Server の起動

WebLogic Serverの停止に関するマニュアルも、起動時と同様に以下にまとまっています。

WebLogic Serverの起動にはいくつかの方法があります。

  • WebLogic Server付属の停止スクリプトを使用して停止
    • 管理サーバーを停止するためのstopWebLogic.sh
    • 管理対象サーバーを停止するためのstopManagedWebLogic.sh
  • JVMの強制停止
    • サーバーを起動したシェル(コマンド・プロンプト)がまだ開いている場合は、[Ctrl]+[C]
    • killコマンドを使用してJVMを強制停止

Chefを使ってやりたい事

今回は起動時と同様にWLSTを使用して管理サーバ・インスタンスを停止します。
WebLogic Server付属のスクリプトは内部でWLSTを呼び出しているので、その処理に従ってChefでWLSTを呼び出すようにします。

今回作成するRecipe

  • WLSTのスクリプト・モードで起動中のWebLogic Server管理サーバに接続し、管理サーバを停止します。
    • 使用するWLSTスクリプトは、Templateとして用意しておきます。

Recipe. WebLogic Server 管理サーバの起動

以下の3種類のファイルを作成します。
- Recipe
- Template
- Attribute

Templateでは、WebLogic Server 停止用のWLSTスクリプトを用意します。

  • Template

以下の箇所で、startServerコマンドにより管理サーバを起動します。

templates/default/shutdown-AdminServer.py.erb
connect( '<%= node['weblogic-domain-lifecycle']['wlsuser'] %>', '<%= node['weblogic-domain-lifecycle']['password'] %>', '<%= node['weblogic-domain-lifecycle']['admin_server_url'] %>' )
shutdown('<%= node['weblogic-domain-lifecycle']['admin_server_name'] %>','Server', ignoreSessions='true' )
exit()
  • connect構文
    • connect([username], [password], [url])

connect構文で使用している引数の説明です。

引数 定義
username WLSTをサーバーに接続するときのユーザー名
password WLSTをサーバーに接続するときのパスワード
url 管理サーバーのURL
デフォルトのt3://localhost:7001
  • shutdown構文
    • shutdown([name], [entityType], [ignoreSessions], [timeOut], [force], [block], [properties], [waitForAllSessions])

shutdown構文で使用している引数の説明です。

引数 定義
name 定義するサーバーまたはクラスタの名前
デフォルト:WLSTが現在接続しているサーバー
entityType ServerまたはCluster
デフォルト:Server
ignoreSessions 停止時に、WLSTがすべてのHTTPセッションを直ちに中止するか、または、HTTPセッションの完了(またはタイムアウト)を待機するかどうかを指定するブール値
デフォルト:false
  • Attribute

Attributeでは各デフォルト値を設定しています。

attributes/default.rb
default['weblogic-domain-lifecycle']['wlsuser'] = 'weblogic'
default['weblogic-domain-lifecycle']['password'] = ''
default['weblogic-domain-lifecycle']['admin_server_url'] = 't3://oel72:7001'
default['weblogic-domain-lifecycle']['admin_server_name'] = 'AdminServer'
  • Recipe

RecipeではWLSTをスクリプト・モードで実行しています。
-(参考)スクリプト・モード

recipes/shutdown-admin.rb
execute "wlst.sh shutdown_#{node['weblogic-domain-lifecycle']['domain_name']}_AdminServer.py" do
  environment "CONFIG_JVM_ARGS" => "-Djava.security.egd=file:/dev/./urandom"
  command <<-EOH
    . #{node['weblogic-domain-lifecycle']['wls_home']}/server/bin/setWLSEnv.sh
    #{node['weblogic-domain-lifecycle']['oracle_common']}/common/bin/wlst.sh #{node['weblogic-domain-lifecycle']['response_file_dir']}/shutdown_#{node['weblogic-domain-lifecycle']['domain_name']}_AdminServer.py
  EOH
  user node['weblogic-domain-lifecycle']['user']
  group node['weblogic-domain-lifecycle']['group']
  action :run
  only_if { File.exists?("#{node['weblogic-domain-lifecycle']['domain_base']}/#{node['weblogic-domain-lifecycle']['domain_name']}/servers/AdminServer/tmp/AdminServer.lok") }
end

管理サーバが起動済みの場合にのみ停止要求を行うように、起動時ロックファイルの存在確認を入れています。

recipes/shutdown-admin.rb
 only_if { File.exists?("#{node['weblogic-domain-lifecycle']['domain_base']}/#{node['weblogic-domain-lifecycle']['domain_name']}/servers/AdminServer/tmp/AdminServer.lok") }

Chefの実行イメージ

まとめ

今回のレシピで管理サーバの停止を行いました。
これでWebLogic Serverのインストールから起動、停止までの最も基本的な一連のライフサイクルをChefで実施する事ができるようになりました。
基本的な操作というものは頻繁に実施する事になるので、このように自動化しておけば本質的な作業に集中できて効率的ですね。