Skip to content
This repository has been archived by the owner on May 14, 2021. It is now read-only.

application_unicorn resource's upstart template not generating a .conf file for service #88

Open
SimonKaluza opened this issue Dec 5, 2016 · 4 comments

Comments

@SimonKaluza
Copy link

During the convergence of our application block, Chef never winds up triggering the application_unicorn's Upstart LWRP provider's Upstart#create_service method that creates the Upstart conf file that governs the app.

Because this conf file never gets generated, Upstart does not recognize the service "my_app_web" and when Chef attempts to restart the service we get the exception output:

   ================================================================================
   Error executing action `restart` on resource 'application[my_app_web]'
   ================================================================================

   Mixlib::ShellOut::ShellCommandFailed
   ------------------------------------
   application_unicorn[my_app_web] (my_app-chef::app_server line 161) had an error: Mixlib::ShellOut::ShellCommandFailed: poise_service[my_app_web] (/var/chef/cache/cookbooks/my_app-chef/recipes/app_server.rb line 161) had an error: Mixlib::ShellOut::ShellCommandFailed: service[my_app_web_app] (/var/chef/cache/cookbooks/my_app-chef/recipes/app_server.rb line 161) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
   ---- Begin output of /sbin/start my_app_web_app ----
   STDOUT:
   STDERR: start: Unknown job: my_app_web_app
   ---- End output of /sbin/start my_app_web_app ----
   Ran /sbin/start my_app_web_app returned 1

   Cookbook Trace:
   ---------------
   /var/chef/cache/cookbooks/poise-service/files/halite_gem/poise_service/service_providers/base.rb:75:in `block in action_start'
   /var/chef/cache/cookbooks/poise-service/files/halite_gem/poise_service/service_providers/base.rb:135:in `notify_if_service'
   /var/chef/cache/cookbooks/poise-service/files/halite_gem/poise_service/service_providers/base.rb:74:in `action_start'
   /var/chef/cache/cookbooks/poise-service/files/halite_gem/poise_service/service_providers/upstart.rb:45:in `action_restart'
   /var/chef/cache/cookbooks/poise-service/files/halite_gem/poise_service/service_mixin.rb:125:in `block in action_restart'
   /var/chef/cache/cookbooks/poise-service/files/halite_gem/poise_service/service_mixin.rb:154:in `notify_if_service'
   /var/chef/cache/cookbooks/poise-service/files/halite_gem/poise_service/service_mixin.rb:124:in `action_restart'
   /var/chef/cache/cookbooks/application/files/halite_gem/poise_application/resources/application.rb:249:in `block in proxy_action'
   /var/chef/cache/cookbooks/application/files/halite_gem/poise_application/resources/application.rb:247:in `proxy_action'
   /var/chef/cache/cookbooks/application/files/halite_gem/poise_application/resources/application.rb:229:in `action_restart'

Here is our cookbook's full application block:

application 'my_app_web' do
  path "#{node['my_app']['app_deploy_root']}/latest"
  git '[email protected]:myapp.git' do
    deploy_key deploy_key['rsa']
    revision node['my_app']['revision']
  end
  ruby_runtime 'my_app_ruby' do
    version '2.2'
    provider :ruby_build
  end

  bundle_install do
    path "#{node['my_app']['app_deploy_root']}/latest" # Have to respecify path?  Ghetto as fuck, thanks Poise cookbooks
    vendor true
  end

  rails do
    rails_env node['my_app']['environment_name']
    path "#{node['my_app']['app_deploy_root']}/latest"
    database({
                 adapter: 'postgresql',
                 database: node['my_app']['postgres']['database'],
                 timeout: 5000,
                 username: postgres_credentials['application_username'],
                 password: postgres_credentials['application_password'],
                 host: node['my_app']['master_db_ip'].nil? ? 'localhost' : node['my_app']['master_db_ip'],
                 pool: 100,
                 redis_url: "redis://#{node['my_app']['master_db_ip']}:6379"
             })
    precompile_assets true
    migrate true
  end

  unicorn do
    path "#{node['my_app']['app_deploy_root']}/latest"
    port '8080'
    service_name 'my_app_web_app'
    action :enable
  end
end
@gaurish
Copy link

gaurish commented Jan 1, 2017

i run into the same issue.

@SimonKaluza
Copy link
Author

SimonKaluza commented Jan 12, 2017

The core issue seems to be that the application_unicorn poise-service resource's "start" action is getting triggered before the enable action is run. Because the poise-service's action_enable method is what actually calls the create_service and generates the service's upstart template (and the start action is trying to use it before then), I think this calling order needs a restructuring.

@coderanger
Copy link
Member

This almost always happens because Chef encounters an error and is trying to run queued notifications during shutdown. Look above that for another error message.

@coderanger
Copy link
Member

Also you do not need to respecify the path property, it inherits from the application resource.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants