Some asset related tasks run during app start up

I was wondering … is there a rake task that we can run to do this plugin handling instead of doing that during the application start up? We run our instances with apparmor and would like to avoid allowing the app server to write application files.

systemd[1]: Stopped Discourse Puma.
systemd[1]: Started Discourse Puma.
bundler.ruby2.6-2.1.4[28628]: `/srv/www/vhosts//discourse/` is not writable.
bundler.ruby2.6-2.1.4[28628]: Bundler will use `/tmp/bundler20200127-28628-npwuek28628' as your home directory temporarily.
bundler.ruby2.6-2.1.4[28628]: [28628] Puma starting in cluster mode...
bundler.ruby2.6-2.1.4[28628]: [28628] * Version 4.3.1 (ruby 2.6.5-p114), codename: Mysterious Traveller
bundler.ruby2.6-2.1.4[28628]: [28628] * Min threads: 4, max threads: 8
bundler.ruby2.6-2.1.4[28628]: [28628] * Environment: production
bundler.ruby2.6-2.1.4[28628]: [28628] * Process workers: 2
bundler.ruby2.6-2.1.4[28628]: [28628] * Preloading application
bundler.ruby2.6-2.1.4[28628]: [28628] ! Unable to load application: Errno::EACCES: Permission denied @ apply2files - app/assets/javascripts/plugins/discourse-details.js.erb
bundler.ruby2.6-2.1.4[28628]: bundler: failed to load command: /usr/bin/puma.ruby2.6 (/usr/bin/puma.ruby2.6)
bundler.ruby2.6-2.1.4[28628]: Errno::EACCES: Permission denied @ apply2files - app/assets/javascripts/plugins/discourse-details.js.erb
bundler.ruby2.6-2.1.4[28628]:   lib/plugin/instance.rb:559:in `delete'
bundler.ruby2.6-2.1.4[28628]:   lib/plugin/instance.rb:559:in `activate!'
bundler.ruby2.6-2.1.4[28628]:   lib/discourse.rb:191:in `block in activate_plugins!'
bundler.ruby2.6-2.1.4[28628]:   lib/discourse.rb:188:in `each'
bundler.ruby2.6-2.1.4[28628]:   lib/discourse.rb:188:in `activate_plugins!'
bundler.ruby2.6-2.1.4[28628]:   config/application.rb:270:in `block in <class:Application>'
bundler.ruby2.6-2.1.4[28628]:   lib/plugin_initialization_guard.rb:5:in `plugin_initialization_guard'
bundler.ruby2.6-2.1.4[28628]:   config/application.rb:269:in `<class:Application>'
bundler.ruby2.6-2.1.4[28628]:   config/application.rb:59:in `<module:Discourse>'
bundler.ruby2.6-2.1.4[28628]:   config/application.rb:58:in `<top (required)>'
bundler.ruby2.6-2.1.4[28628]:   config/environment.rb:4:in `require'
bundler.ruby2.6-2.1.4[28628]:   config/environment.rb:4:in `<top (required)>'
bundler.ruby2.6-2.1.4[28628]:   config.ru:6:in `require'
bundler.ruby2.6-2.1.4[28628]:   config.ru:6:in `block in <main>'
bundler.ruby2.6-2.1.4[28628]:   /usr/lib64/ruby/gems/2.6.0/gems/rack-2.0.8/lib/rack/builder.rb:55:in `instance_eval'
bundler.ruby2.6-2.1.4[28628]:   /usr/lib64/ruby/gems/2.6.0/gems/rack-2.0.8/lib/rack/builder.rb:55:in `initialize'
bundler.ruby2.6-2.1.4[28628]:   config.ru:in `new'
bundler.ruby2.6-2.1.4[28628]:   config.ru:in `<main>'
bundler.ruby2.6-2.1.4[28628]:   /usr/lib64/ruby/gems/2.6.0/gems/rack-2.0.8/lib/rack/builder.rb:49:in `eval'
bundler.ruby2.6-2.1.4[28628]:   /usr/lib64/ruby/gems/2.6.0/gems/rack-2.0.8/lib/rack/builder.rb:49:in `new_from_string'
bundler.ruby2.6-2.1.4[28628]:   /usr/lib64/ruby/gems/2.6.0/gems/rack-2.0.8/lib/rack/builder.rb:40:in `parse_file'
bundler.ruby2.6-2.1.4[28628]:   /usr/lib64/ruby/gems/2.6.0/gems/puma-4.3.1/lib/puma/configuration.rb:321:in `load_rackup'
bundler.ruby2.6-2.1.4[28628]:   /usr/lib64/ruby/gems/2.6.0/gems/puma-4.3.1/lib/puma/configuration.rb:246:in `app'
bundler.ruby2.6-2.1.4[28628]:   /usr/lib64/ruby/gems/2.6.0/gems/puma-4.3.1/lib/puma/runner.rb:155:in `load_and_bind'
bundler.ruby2.6-2.1.4[28628]:   /usr/lib64/ruby/gems/2.6.0/gems/puma-4.3.1/lib/puma/cluster.rb:413:in `run'
bundler.ruby2.6-2.1.4[28628]:   /usr/lib64/ruby/gems/2.6.0/gems/puma-4.3.1/lib/puma/launcher.rb:172:in `run'
bundler.ruby2.6-2.1.4[28628]:   /usr/lib64/ruby/gems/2.6.0/gems/puma-4.3.1/lib/puma/cli.rb:80:in `run'
bundler.ruby2.6-2.1.4[28628]:   /usr/lib64/ruby/gems/2.6.0/gems/puma-4.3.1/bin/puma:10:in `<top (required)>'
bundler.ruby2.6-2.1.4[28628]:   /usr/bin/puma.ruby2.6:23:in `load'
bundler.ruby2.6-2.1.4[28628]:   /usr/bin/puma.ruby2.6:23:in `<top (required)>'
systemd[1]: discourse-puma.service: Main process exited, code=exited, status=1/FAILURE
systemd[1]: discourse-puma.service: Unit entered failed state.
systemd[1]: discourse-puma.service: Failed with result 'exit-code'.
systemd[1]: discourse-puma.service: Service RestartSec=100ms expired, scheduling restart.
systemd[1]: Stopped Discourse Puma.

This is on 2.4.0.beta10.

1 Like

This is going to require changes here

https://github.com/discourse/discourse/blob/58d6ee36ee460e2f7f5da0121dcbaa7929b7d7d5/lib/plugin/instance.rb#L559-L565

We are unconditionally deleting a file for plugins that define js assets on plugin boot. I guess we could be doing this stuff in tmp folder instead.

2 Likes

why not as part of the normal asset rake task?

Not against amending this afaik it is the way it is mostly for historical reasons, it would be a fairly complex change

1 Like