Chef Error executing action `start` on resource 'service[httpd]' - ruby

Here is my very basic recipes/default.rb file;
package "httpd" do
action :install
end
node["apache"]["sites"].each do |sitename, data|
document_root = "/content/sites/#{sitename}"
directory document_root do
mode "0755"
recursive true
end
template "/etc/httpd/conf.d/#{sitename}.conf" do
source "vhost.erb"
mode "0644"
variables(
:document_root => document_root,
:port => data["port"],
:domain => data["domain"]
)
notifies :restart, "service[httpd]"
end
end
service "httpd" do
action [:enable, :start]
end
When I run the chef-client in the node it returns the following error:
Error executing action `start` on resource 'service[httpd]'
================================================================================
Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '1'
---- Begin output of /sbin/service httpd start ----
STDOUT: Starting httpd: [FAILED]
STDERR: Syntax error on line 15 of /etc/httpd/conf.d/stedelahunty2.conf:
order takes one argument, 'allow,deny', 'deny,allow', or 'mutual-failure'
---- End output of /sbin/service httpd start ----
Ran /sbin/service httpd start returned 1
Resource Declaration:
---------------------
# In /var/chef/cache/cookbooks/apache/recipes/default.rb
35: service "httpd" do
36: action [:enable, :start]
37: end
Compiled Resource:
------------------
# Declared in /var/chef/cache/cookbooks/apache/recipes/default.rb:35:in `from_file'
service("httpd") do
action [:enable, :start]
supports {:restart=>false, :reload=>false, :status=>true}
retries 0
retry_delay 2
default_guard_interpreter :default
service_name "httpd"
enabled true
pattern "httpd"
declared_type :service
cookbook_name "apache"
recipe_name "default"
end
I've tried renaming it apache, changing the options to ':restart', commenting out entirely but that means httpd fails to start. I just need a simple way to restart the service after the chef run has completed.
Again, apologies for the novice question; I'm very new to coding.
Cheers

That's not a chef problem. Apache httpd reports
Syntax error on line 15 of /etc/httpd/conf.d/stedelahunty2.conf: order takes one argument, 'allow,deny', 'deny,allow', or 'mutual-failure'

Related

How to resolve Mixlib::ShellOut::ShellCommandFailed error

I am trying to mock the data of node and run chefspec. But facing this error. Chefspec version=7.3.4
Chef version=13.9.1
Is there any problem with the simulation? how do I resolve the handler error?
Is there something I'm missing here? How can I debug the Mixlib::ShellOut::CommandTimeout?
================================================================================
Error executing action `install` on resource 'python_package[setuptools]'
================================================================================
Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '1'
---- Begin output of ["/usr/bin/python2.7", "-", "setuptools==40.5.0"] ----
STDOUT:
STDERR: No handlers could be found for logger "pip._internal.index"
Traceback (most recent call last):
File "<stdin>", line 43, in <module>
File "/usr/local/lib/python2.7/dist-packages/pip/_internal/index.py", line 543, in find_requirement
'No matching distribution found for %s' % req
pip._internal.exceptions.DistributionNotFound: No matching distribution found for setuptools==40.5.0
---- End output of ["/usr/bin/python2.7", "-", "setuptools==40.5.0"] ----
Ran ["/usr/bin/python2.7", "-", "setuptools==40.5.0"] returned 1
Resource Declaration:
---------------------
# In /chef-recipes/cookbooks/poise-python/files/halite_gem/poise_python/python_providers/base.rb
138: python_package 'setuptools' do
139: parent_python new_resource
140: version setuptools_version if setuptools_version.is_a?(String)
141: end
142: end
Compiled Resource:
------------------
# Declared in /chef-recipes/cookbooks/poise-python/files/halite_gem/poise_python/python_providers/base.rb:138:in `install_setuptools'
python_package("setuptools") do
package_name "setuptools"
action [:install]
default_guard_interpreter :default
declared_type :python_package
cookbook_name :"poise-python"
parent_python python_runtime[2]
version "40.5.0"
timeout 900
end
System Info:
------------
chef_version=13.9.1
platform=ubuntu
platform_version=16.04
ruby=ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-linux]
program_name=/usr/local/rvm/gems/ruby-2.4.2/bin/rspec
executable=/usr/local/rvm/gems/ruby-2.4.2/bin/ruby_executable_hooks

In the second run of chef-client, lazy attribute of docker_container on "link" is not getting resolved and passed unreadable value

my first time to ask stuff on stack-overflow, here in china i seldom able to meet any chef developer to talk about my problem so i am posting it here to seek for help. This issue has been bothering me for weeks and i am still trying to settle it.
here are my error msg:
* directory[/root/tools/projectname/../bootproxy] action create (up to date)
* template[/root/tools/projectname/../bootproxy/oc.proxy.conf] action create (up to date)
* directory[/root/tools/projectname/../bootproxy] action create (up to date)
* file[/tmp/dockerinfo.txt] action delete
- delete file /tmp/dockerinfo.txt
* bash[docker ps -a|grep -v CONTAINER|grep -v monitor|awk '{print $1, $NF}'] action run
- execute "bash" "/tmp/chef-script20170319-2107-fx41as"
* ruby_block[result] action run
- execute the ruby block result
* docker_container[bootproxy] action redeploy
- stopping bootproxy (will kill after 30s)
- deleting bootproxy
================================================================================
Error executing action redeploy on resource 'docker_container[bootproxy]'
================================================================================
Docker::Error::ServerError
--------------------------
Could not get container for bootproxy
Cookbook Trace:
---------------
/var/chef/cache/cookbooks/docker/libraries/docker_container.rb:319:in `block (3 levels) in <class:DockerContainer>'
/var/chef/cache/cookbooks/docker/libraries/helpers_base.rb:66:in `with_retries'
/var/chef/cache/cookbooks/docker/libraries/docker_container.rb:250:in `block (2 levels) in <class:DockerContainer>'
/var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider.rb:81:in `converge_if_changed'
/var/chef/cache/cookbooks/docker/libraries/docker_container.rb:247:in `block in <class:DockerContainer>'
/var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider.rb:132:in `instance_eval'
/var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider.rb:132:in `compile_and_converge_action'
/var/chef/cache/cookbooks/docker/libraries/docker_container.rb:169:in `call_action'
/var/chef/cache/cookbooks/docker/libraries/docker_container.rb:360:in `block in <class:DockerContainer>'
/var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider.rb:132:in `instance_eval'
/var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider.rb:132:in `compile_and_converge_action'
/var/chef/cache/cookbooks/docker/libraries/docker_container.rb:169:in `call_action'
/var/chef/cache/cookbooks/docker/libraries/docker_container.rb:403:in `block in <class:DockerContainer>'
/var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider.rb:132:in `instance_eval'
/var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider.rb:132:in `compile_and_converge_action'
/var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:78:in `run_action'
/var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:106:in `block (2 levels) in converge'
/var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:106:in `each'
/var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:106:in `block in converge'
/var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:105:in `converge'
Resource Declaration:
---------------------
# In /var/chef/cache/cookbooks/webserver/recipes/default.rb
218: docker_container container_name do
219: repo docker[:image]
220: tag docker[:tag]
221: #Add all docker link
222: # links node.set[:linking]
223: links lazy{node.run_state[:linking]}
224: env docker[:env]
225: command docker[:command]
226: kill_after 30
227: # autoremove true
228: action :redeploy
229: port docker[:ports]
230: volumes node.default["bindvolume"]
231: cap_add 'SYS_ADMIN'
232: devices []
233: privileged true
234: timeout 30
235: # {["/dev/fuse"]}
236: end
237: else
238: docker_container container_name do
239: repo docker[:image]
240: tag docker[:tag]
241: #Add all docker link
242: links node.run_state[:linking]
243: env docker[:env]
244: command docker[:command]
245: kill_after 30
246: # autoremove true
247: action :redeploy
248: port docker[:ports]
249: volumes node.default["bindvolume"]
250: cap_add 'SYS_ADMIN'
251: devices []
252: privileged true
253: timeout 30
254: # {["/dev/fuse"]}
255: end
256: end
257:
258: if (not (defined?(docker[:exec])).nil?) && (not "#{docker[:exec]}" == "")
259: execute 'execute command inside docker' do
260: command "docker exec -i #{container_name} /bin/bash -c \'#{docker[:exec]}\'"
261: end
262: end
263:
264: etchosts.push("#{container_name}:#{container_name}")
265: end
266:
267: #Add proxy.conf to folder if bootproxy defined
268: if defined?(node[:externalmode]) && node[:externalmode].eql?("bootproxy")
269: #Prepare bootproxy directories
270: directory "#{node[:deploycode][:basedirectory]}../bootproxy" do
Compiled Resource:
------------------
# Declared in /var/chef/cache/cookbooks/webserver/recipes/default.rb:218:in `block in from_file'
docker_container("bootproxy") do
action [:redeploy]
retries 0
retry_delay 2
default_guard_interpreter :default
declared_type :docker_container
cookbook_name "webserver"
recipe_name "default"
kill_after 30
repo "daocloud.io/library/nginx"
tag "stable-alpine"
exposed_ports {"80/tcp"=>{}, "5000/tcp"=>{}}
port_bindings {"80/tcp"=>[{"HostIp"=>"0.0.0.0", "HostPort"=>"80"}], "5000/tcp"=>[{"HostIp"=>"0.0.0.0", "HostPort"=>"5000"}]}
port ["80:80", "5000:5000"]
volumes_binds ["/root/tools/projectname/../bootproxy:/etc/nginx/conf.d/"]
links #<ChefCompat::CopiedFromChef::Chef::DelayedEvaluator:0x000000055c4a90#/var/chef/cache/cookbooks/webserver/recipes/default.rb:223>
cap_add ["SYS_ADMIN"]
privileged true
timeout 30
connection #<Docker::Connection:0x00000008301238 #url="unix:///", #options={:socket=>"/var/run/docker.sock", :read_timeout=>60}>
network_mode "bridge"
detach true
signal "SIGTERM"
end
Running handlers:
[2017-03-19T21:20:15+08:00] ERROR: Running exception handlers
Running handlers complete
[2017-03-19T21:20:15+08:00] ERROR: Exception handlers complete
Chef Client failed. 20 resources updated in 34 seconds
[2017-03-19T21:20:15+08:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2017-03-19T21:20:15+08:00] ERROR: docker_container[bootproxy] (webserver::default line 218) had an error: Docker::Error::ServerError: Could not get container for bootproxy
[2017-03-19T21:20:15+08:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
and here are my codes:
node.run_state[:linking] = []
#Special handling if bootproxy, get all local running docker id and name and link into bootproxy
if localfolder.eql?("bootproxy")
container_name = localfolder
node.set[:dockerinfo] = []
results = "/tmp/dockerinfo.txt"
file results do
action :delete
end
cmd = "docker ps -a|grep -v CONTAINER|grep -v monitor|awk \'{print $1, $NF}\'"
bash cmd do
code <<-EOH
#{cmd} > #{results}
EOH
end
ruby_block "result" do
only_if { "cat #{results}| wc -l;while [ $? -ne 0 ]; do cat #{results}| wc -l;done" }
# only_if { ::File.exists?(results) }
block do
f = File.open(results)
dockerinfo = Hash.new
f.each do |line|
dockerinfo[line.chomp.split(' ')[0]] = line.chomp.split(' ')[1]
end
f.close
node.set[:dockerinfo] = dockerinfo
node.run_state[:linking] = dockerinfo
node.run_state[:linking] = []
node.set[:dockerinfo].each do |hash, dockername|
node.run_state[:linking].push("#{dockername}:#{dockername}")
end
end
end
else
node.run_state[:linking] = etchosts
end
if node.default["bindvolume"].eql?([":"])
node.default["bindvolume"] = nil
end
if localfolder.eql?("bootproxy")
# Using lazy evaluation if bootproxy
docker_container container_name do
repo docker[:image]
tag docker[:tag]
#Add all docker link
# links node.set[:linking]
links lazy{node.run_state[:linking]}
env docker[:env]
command docker[:command]
kill_after 30
# autoremove true
action :redeploy
port docker[:ports]
volumes node.default["bindvolume"]
cap_add 'SYS_ADMIN'
devices []
privileged true
timeout 30
# {["/dev/fuse"]}
end
else
docker_container container_name do
repo docker[:image]
tag docker[:tag]
#Add all docker link
links node.run_state[:linking]
env docker[:env]
command docker[:command]
kill_after 30
# autoremove true
action :redeploy
port docker[:ports]
volumes node.default["bindvolume"]
cap_add 'SYS_ADMIN'
devices []
privileged true
timeout 30
# {["/dev/fuse"]}
end
end
What i am trying to do here, is to run a set of docker by chef docker cookbook version 2.14.3, with names looping into "localfolder", and when localfolder = "bootproxy", execute bash command to check what dockers are currently running and link them by a nginx docker named as "bootproxy".
My issue here is, whenever i cleared all my cache or after i have re-uploaded all my cookbook "webserver", chef-client runs fine without error. But when i rerun the chef-client, i got
Docker::Error::ServerError
--------------------------
Could not get container for bootproxy
due to the value of "links" in "docker_container" resources became "#" instead of an array that included the current running docker names like [ "container1:container1", "container2:container2", "container3:container3"]. So i suspect that the ruby_block that trying to get value from the host is being cached and not running after the first successive execution. My removal of cache (rm -rf /var/chef/cache) proved it but i cannot define removal of cache inside cookbook(not a neat way to work it out too). I need to make the chef-client able to rerun as i am using it to deploy my set of codes in the whole envionment. Please give me any advise for this.
Thanks!
I think you missed fixing the second resource, it isn't using the lazy{} helper.
Overall this code is kind of a mess so it's really hard to tell what it is doing in the first place. I recommend writing a lot of tests and maybe more comments.

Capistrano deploy - stuck at step 03

I've been playing with capistrano deploy, I managed to connect to my server, but now I am stuck at step 03, but I don't have log errors and I don't know which might be the next thing to do.
Help is highly appreciate. I don't whant you to solve by me of course not. I just want some guidance, thank you.
$ cap production deploy --trace
** Invoke production (first_time)
** Execute production
** Invoke load:defaults (first_time)
** Execute load:defaults
** Invoke bundler:map_bins (first_time)
** Execute bundler:map_bins
** Invoke deploy (first_time)
** Execute deploy
** Invoke deploy:starting (first_time)
** Execute deploy:starting
** Invoke deploy:check (first_time)
** Execute deploy:check
** Invoke git:check (first_time)
** Invoke git:wrapper (first_time)
** Execute git:wrapper
00:00 git:wrapper
01 mkdir -p /tmp
✔ 01 vlmg#vlmg.mx 0.249s
Uploading /tmp/git-ssh-vlmg-forms-production-ubuntu.sh 100.0%
02 chmod 700 /tmp/git-ssh-vlmg-forms-production-ubuntu.sh
✔ 02 vlmg#vlmg.mx 0.055s
This is my deploy.rb
# config valid only for current version of Capistrano
lock '3.6.0'
set :application, 'vlmg-forms'
set :repo_url, 'git#github.com:jose-octomedia/ar-vlmg-contact-forms.git'
# Default branch is :master
# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp
# Default deploy_to directory is /var/www/my_app_name
#set :deploy_to, '/'
# Default value for :scm is :git
# set :scm, :git
# Default value for :format is :airbrussh.
# set :format, :airbrussh
# You can configure the Airbrussh format using :format_options.
# These are the defaults.
# set :format_options, command_output: true, log_file: 'log/capistrano.log', color: :auto, truncate: :auto
# Default value for :pty is false
set :pty, true
# Default value for :linked_files is []
# append :linked_files, 'config/database.yml', 'config/secrets.yml'
# Default value for linked_dirs is []
# append :linked_dirs, 'log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'public/system'
# Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }
# Default value for keep_releases is 5
# set :keep_releases, 5
desc 'Restart application'
task :restart do
on roles(:web), in: :sequence, wait: 5 do
execute "service thin restart" ## -> line you should add
end
end
And this is my production.rb file
# server-based syntax
# ======================
# Defines a single server with a list of roles and multiple properties.
# You can define all roles on a single server, or split them:
server 'vlmg.mx', user: 'vlmg', roles: %w{web}, primary: true, port: 15555
# server 'example.com', user: 'deploy', roles: %w{app web}, other_property: :other_value
# server 'db.example.com', user: 'deploy', roles: %w{db}
set :deploy_to, "/home/vlmg/subdomains/ar.vlmg.mx"
# role-based syntax
# ==================
# Defines a role with one or multiple servers. The primary server in each
# group is considered to be the first unless any hosts have the primary
# property set. Specify the username and a domain or IP for the server.
# Don't use `:all`, it's a meta role.
#role :app, %w{admin#example.com}, my_property: :my_value
role :web, %w{vlmg#vlmg.mx}
# role :db, %w{deploy#example.com}
# Configuration
# =============
# You can set any configuration variable like in config/deploy.rb
# These variables are then only loaded and set in this stage.
# For available Capistrano configuration variables see the documentation page.
# http://capistranorb.com/documentation/getting-started/configuration/
# Feel free to add new variables to customise your setup.
# Custom SSH Options
# ==================
# You may pass any option but keep in mind that net/ssh understands a
# limited set of options, consult the Net::SSH documentation.
# http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start
#
# Global options
# --------------
set :ssh_options, {
keys: %w(/home/ubuntu/.ssh/id_rsa),
forward_agent: true
#auth_methods: %w(password)
}
#
# The server-based syntax can be used to override options:
# ------------------------------------
# server 'example.com',
# user: 'user_name',
# roles: %w{web app},
# ssh_options: {
# user: 'user_name', # overrides user setting above
# keys: %w(/home/ubuntu/.ssh/id_rsa),
# forward_agent: false,
## auth_methods: %w(publickey password)
# # password: 'please use keys'
# }
Edit: In response of enabling the logs. This is the results.
Still nothing in the logs that could help to solve.
INFO ---------------------------------------------------------------------------
INFO START 2016-08-10 19:49:49 +0000 cap production deploy
INFO ---------------------------------------------------------------------------
INFO [204569e4] Running /usr/bin/env mkdir -p /tmp as vlmg#vlmg.mx
DEBUG [204569e4] Command: /usr/bin/env mkdir -p /tmp
INFO [9596edc0] Running /usr/bin/env mkdir -p /tmp as vlmg#vlmg.mx
DEBUG [9596edc0] Command: /usr/bin/env mkdir -p /tmp
INFO [9596edc0] Finished in 0.288 seconds with exit status 0 (successful).
DEBUG Uploading /tmp/git-ssh-vlmg-forms-production-ubuntu.sh 0.0%
INFO Uploading /tmp/git-ssh-vlmg-forms-production-ubuntu.sh 100.0%
INFO [1014be51] Running /usr/bin/env chmod 700 /tmp/git-ssh-vlmg-forms-production-ubuntu.sh as vlmg#vlmg.mx
DEBUG [1014be51] Command: /usr/bin/env chmod 700 /tmp/git-ssh-vlmg-forms-production-ubuntu.sh
INFO [1014be51] Finished in 0.057 seconds with exit status 0 (successful).
After last command this are the results, basically the same, hanging for 20-30 seconds then:
00:00 git:wrapper
01 mkdir -p /tmp
✔ 01 vlmg#vlmg.mx 0.265s
Uploading /tmp/git-ssh-vlmg-forms-production-ubuntu.sh 100.0%
02 chmod 700 /tmp/git-ssh-vlmg-forms-production-ubuntu.sh
✔ 02 vlmg#vlmg.mx 0.063s
(Backtrace restricted to imported tasks)
cap aborted!
Net::SSH::ConnectionTimeout: Net::SSH::ConnectionTimeout
Errno::ETIMEDOUT: Connection timed out - connect(2) for 109.73.225.169:22
Tasks: TOP => git:wrapper
(See full trace by running task with --trace)
This step 03 is solved, thanks. Solution was specify port on ssh connection too.
set :ssh_options, {
keys: %w(/home/ubuntu/.ssh/id_rsa),
forward_agent: true,
port: 15555,
#auth_methods: %w(password)
}
Now I have new errors, but I think that should could be in another post.

Mixlib::ShellOut - timeout

I am trying to use Mixlib::ShellOut to execute commands under ruby_block inside a chef recipe.
In Some situations, we cannot complete the task in 600 seconds, and I would like extend further. I have added command in below way,
ruby_block "#{host_short_name}_reg_chef_node" do
block do
puts "Registering Chef Node #{host_full_name}"
_command = "cd #{node['nodeManager']['app']['base_dir']}; #{node['nodeManager']['knife']['binary']} bootstrap --sudo #{host_full_name}"
_command += " --ssh-user #{node['nodeManager']['admin']['user']} --no-host-key-verify --identity-file #{node['nodeManager']['admin']['keyfile']}"
_command +=" --environment #{params[:environment]} --run-list 'role[#{params[:role_hash]['role']}]'"
puts _command
vsphere_output = Mixlib::ShellOut.new(_command, :timeout => 10000)
vsphere_output.run_command
puts "Output: #{vsphere_output.stdout}"
puts "Error : #{vsphere_output.stderr}"
end
action :nothing
end
and I suspect it is not respecting timeout value. Please advise.

Chef fails when trying to deploy a Torquebox app on EC2

I'm pretty new to Chef/ops in general but I'm trying to deploy on EC2 and I keep running into this error. The stack trace file mentioned in the error does not exist so that's making it kind of hard to debug the problem. Also, whenever Chef fails, the permission on my EC2 box gets denied and I have to spin up a new instance. For reference, the original source of this file is from here: http://janitor.se/blog/2013/07/04/easier-neo4j-dot-rb-deployments-with-chef-plus-capistrano-plus-torquebox/
The error looks like this:
* script[install torquebox backstage] action run
- execute "bash" "/tmp/chef-script20131011-2067-1phzfkw"
[2013-10-11T03:47:51+00:00] ERROR: Running exception handlers
[2013-10-11T03:47:51+00:00] ERROR: Exception handlers complete
[2013-10-11T03:47:51+00:00] FATAL: Stacktrace dumped to /tmp/chef-solo/chef-stacktrace.out
Chef Client failed. 71 resources updated
[2013-10-11T03:47:51+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
ERROR: RuntimeError: chef-solo failed. See output above.
My recipe file - torquebox.rb:
download_file = File.join("/tmp", File.basename(node.torquebox.download_url))
remote_file download_file do
source node.torquebox.download_url
mode 00644
action :create_if_missing
notifies :run, "script[install-torquebox]", :immediately
end
script "install-torquebox" do
Chef::Log.info("Installing torquebox zip file...")
user 'torquebox'
interpreter "bash"
code <<-EOH
unzip -o #{download_file} -d /opt/torquebox/
ln -s /opt/torquebox/torquebox-2.3.2 /opt/torquebox/current
EOH
notifies :run, "execute[change ownership to torquebox]"
not_if do
File.exists? "/opt/torquebox/torquebox-2.3.2"
end
# not_if do
# File.exists? "/opt/torquebox/torquebox-2.2.0"
# end
#action :nothing
end
template "/etc/profile.d/torquebox.sh" do
source "torquebox.sh.erb"
mode 00644
owner 'root'
variables(
:jboss_user => node[:torquebox_env][:jboss_user],
:torquebox_home => node[:torquebox_env][:home],
:jboss_pidfile => node[:torquebox_env][:jboss_pidfile],
:jboss_console_log => node[:torquebox_env][:jboss_console_log],
:jboss_config => node[:torquebox][:configuration_file],
:jruby_opts => node[:torquebox_env][:jruby_opts],
:java_environment_file => node[:java][:java_environment]
)
notifies :restart, "service[jboss-as-standalone]"
end
# install torquebox backstage
#
execute "change ownership to torquebox" do
user "root"
cwd "/opt"
Chef::Log.info("changing ownership for torquebox")
command "chown -Rv 1000.1000 /opt/torquebox"
notifies :run, "script[install torquebox backstage]"
action :nothing
end
script "install torquebox backstage" do
Chef::Log.info("Installing torquebox backstage file...")
interpreter "bash"
user "torquebox"
cwd "/opt/torquebox"
code <<-EOH
export TORQUEBOX_HOME=/opt/torquebox/torquebox-2.3.2
export JAVA_HOME=/opt/jdk7/
export JBOSS_HOME=$TORQUEBOX_HOME/jboss
export JRUBY_HOME=$TORQUEBOX_HOME/jruby
export PATH=$JBOSS_HOME/bin:$JRUBY_HOME/bin:$JAVA_HOME/bin:$PATH
EOH
# jruby -S gem install torquebox-backstage
# jruby -S gem install ruby-shadow
# jruby -S backstage deploy
not_if do
File.exists? "/opt/torquebox/current/jruby/bin/backstage"
end
end
directory '/opt/apps/' do
owner "torquebox"
group "torqubox"
mode 00755
action :create
not_if do
File.exists? "/opt/apps/"
end
end
directory "/etc/jboss-as" do
owner "root"
group "root"
mode 00755
action :create
not_if do
File.exists? "/etc/jboss-as"
end
end
directory "/var/log/jboss-as" do
owner "torquebox"
group "torquebox"
mode 00755
action :create
not_if do
File.exists? "/var/log/jboss-as"
end
end
template "/etc/init.d/jboss-as-standalone" do
source "jboss-as-standalone.sh.erb"
variables(:environment_file => node[:torquebox][:environment_file])
mode 00755
owner 'root'
notifies :restart, "service[jboss-as-standalone]"
end
service "jboss-as-standalone" do
supports :status => true, :restart => true, :stop => true, :start => true
action [ :enable, :start ]
end
#if clustered then if cluster name is staging_cluster, so proxy name will be staging_cluster_proxy
#so for every cookbook, it should be paired with two of them
proxy_nodes = []
clustered_nodes = []
Chef::Log.warn("clustered status #{node[:torquebox][:clustered]}")
if node[:torquebox][:clustered]
clustered_nodes = search(:node, "roles:#{node[:torquebox][:cluster_name]}")
proxy_nodes = search(:node, "roles:#{node[:torquebox][:cluster_name]}_proxy")
template "/opt/torquebox/current/jboss/standalone/configuration/standalone-ha.xml" do
source "standalone-ha.xml.erb"
variables(:node_name => node.name, :node_ipaddress => node.ipaddress, :cluster_name => node[:torquebox][:cluster_name], :clustered_nodes => clustered_nodes, :proxy_nodes => proxy_nodes )
mode "0644"
notifies :restart, "service[jboss-as-standalone]"
end
end
if proxy_nodes.count == 0 and node[:torquebox][:clustered] == true
Chef::Log.warn("There is no proxy defined, cluster may not function")
end
if !node[:torquebox][:clustered]
template "/opt/torquebox/current/jboss/standalone/configuration/standalone.xml" do
source "standalone.xml.erb"
variables(:node_name => node.name, :node_ipaddress => node.ipaddress)
mode "0644"
notifies :restart, "service[jboss-as-standalone]"
end
end
template "/opt/torquebox/current/jboss/bin/standalone.conf" do
source "standalone.conf.erb"
mode "00644"
owner 'torquebox'
variables(:jboss_config => node[:torquebox][:configuration_file])
notifies :restart, "service[jboss-as-standalone]"
end
cookbook_file "/etc/jboss-as/jboss-as.conf" do
source "jboss-as.conf"
mode 00644
owner 'root'
end
# NGINX!
# this enables our site, kinda like a2ensite
execute 'enable-site' do
command "ln -sf /etc/nginx/sites-available/#{node[:server_name]} /etc/nginx/sites-enabled/#{node[:server_name]}"
notifies :restart, 'service[nginx]'
end
# Our configuration template. Take a look at templates/nginx.conf.erb to see what's going on.
template "/etc/nginx/sites-available/#{node[:server_name]}" do
source 'nginx.erb'
owner 'root'
group 'root'
mode 0644
notifies :run, "execute[enable-site]", :immediately
variables(
server_name: node.server_name
)
end
service 'nginx'
service 'jboss-as-standalone'

Resources