Posted at

Wildflyのインストールレシピ

More than 5 years have passed since last update.

ZabbixJMXエージェントの試行をする前に、

監視対象のWildflyのインストールレシピを作成する。

# OpenJDKをインストール

package "java-1.7.0-openjdk"

# wildflyをダウンロード・インストール
download_dir = Chef::Config[:file_cache_path]
tar_filename = node['wildfly']['tar_filename']
remote_file File.join(download_dir, tar_filename) do
source node['wildfly']['tar_url']
end

install_dir = node['wildfly']['install_dir']
jboss_home = node['wildfly']['jboss_home']
execute "uncompress wildfly.tar.gz" do
command "tar xf #{File.join(download_dir, tar_filename)} -C #{install_dir}"
not_if { Dir.exists?(jboss_home) }
end

# jboss用ユーザの作成
jboss_user = node['wildfly']['jboss_user']
jboss_group = node['wildfly']['jboss_group']
group jboss_group

user node['wildfly']['jboss_user'] do
gid jboss_group
home "/home/#{jboss_user}"
action :create
end

template "/etc/sudoers.d/wildfly" do
source "sudoers_wildfly.erb"
mode 0440
owner "root"
group "root"
variables(
:jboss_user => node['wildfly']['jboss_user']
)
end

# JBOSS_HOME以下のファイル全ての所有ユーザをJBoss用ユーザに変更
execute "modify #{jboss_home} owner" do
command "chown -R #{jboss_user}:#{jboss_group} #{jboss_home}"
end

# 環境変数の追加(JAVA_HOME、JBOSS_HOME)
template "/etc/profile.d/jboss.sh" do
source "profile_jboss.sh.erb"
variables(
:jboss_home => jboss_home
)
end

# service経由で起動する際の設定ファイルを作成
# JBOSS_MODE = "standalone"、JBOSS_CONFIG = "standalone.xml -b 0.0.0.0 -bmanagement=0.0.0.0"で動作確認
template "/etc/default/wildfly.conf" do
source "wildfly.conf.erb"
variables(
:jboss_home => jboss_home,
:jboss_user => jboss_user,
:jboss_mode => node['wildfly']['jboss_mode'],
:jboss_config => node['wildfly']['jboss_config']
)
end

# wildflyをサービス登録、自動起動設定、サービス起動
# ファイルのコピーをfileでやるとエラーになったのでexecuteで実施
execute "copy wildfly-init.sh" do
command "cp #{jboss_home}/bin/init.d/wildfly-init-redhat.sh /etc/init.d/wildfly && chmod 755 /etc/init.d/wildfly"
not_if { File.exists?("/etc/init.d/wildfly") }
end

execute "add wildfly service" do
command "chkconfig --add wildfly"
not_if "chkconfig --list wildfly 2> /dev/null"
end

service "wildfly" do
supports :status => true, :restart => true
action [:enable, :start]
end

# JBossの管理ユーザを追加
management_user = node['wildfly']['management_user']
management_password = node['wildfly']['management_password']
execute "add management user" do
command "./add-user.sh --silent=true #{management_user} #{management_password}"
cwd "#{jboss_home}/bin"
user jboss_user
not_if "grep '^#{management_user}=' #{node['wildfly']['configuration_dir']}/mgmt-users.properties"
end