bernd / fpm-cookery

A tool for building software packages with fpm.
Other
460 stars 88 forks source link

Permission error on cleanup when not root #60

Closed haf closed 10 years ago

haf commented 10 years ago

Something like this:

-bash-4.1$ fpm-cook 
===> Starting package creation for teamcity-server-8.0.5 (centos, rpm)
===> 
===> Verifying build_depends and depends with Puppet
===> Verifying package: jdk
===> All build_depends and depends packages installed
===> Fetching source: 
===> Using cached file /opt/teamcity-agent/work/fpm-recipes/teamcity-server/cache/TeamCity-8.0.5.tar.gz
===> Building in /opt/teamcity-agent/work/fpm-recipes/teamcity-server/tmp-build/TeamCity
===> Installing into /opt/teamcity-agent/work/fpm-recipes/teamcity-server/tmp-dest
===> [FPM] Converting dir to rpm {}
WARNING: [FPM] no value for epoch is set, defaulting to nil {}
===> [FPM] Reading template {"path":"/usr/lib/ruby/gems/1.8/gems/fpm-0.4.42/templates/rpm.erb"}
WARNING: [FPM] no value for epoch is set, defaulting to nil {}
/usr/lib/ruby/1.8/fileutils.rb:1178:in `open': Permission denied - /tmp/package-dir-staging20131208-28170-1jkcjhp/var/lib/teamcity-server (Errno::EACCES)
    from /usr/lib/ruby/1.8/fileutils.rb:1178:in `entries'
    from /usr/lib/ruby/1.8/fileutils.rb:1178:in `entries'
    from /usr/lib/ruby/1.8/fileutils.rb:1340:in `postorder_traverse'
    from /usr/lib/ruby/1.8/fileutils.rb:1341:in `postorder_traverse'
    from /usr/lib/ruby/1.8/fileutils.rb:1340:in `each'
    from /usr/lib/ruby/1.8/fileutils.rb:1340:in `postorder_traverse'
    from /usr/lib/ruby/1.8/fileutils.rb:1341:in `postorder_traverse'
    from /usr/lib/ruby/1.8/fileutils.rb:1340:in `each'
    from /usr/lib/ruby/1.8/fileutils.rb:1340:in `postorder_traverse'
    from /usr/lib/ruby/1.8/fileutils.rb:1341:in `postorder_traverse'
    from /usr/lib/ruby/1.8/fileutils.rb:1340:in `each'
    from /usr/lib/ruby/1.8/fileutils.rb:1340:in `postorder_traverse'
    from /usr/lib/ruby/1.8/fileutils.rb:760:in `remove_entry'
    from /usr/lib/ruby/1.8/fileutils.rb:613:in `rm_r'
    from /usr/lib/ruby/1.8/fileutils.rb:609:in `each'
    from /usr/lib/ruby/1.8/fileutils.rb:609:in `rm_r'
    from /usr/lib/ruby/gems/1.8/gems/fpm-0.4.42/lib/fpm/package.rb:274:in `cleanup_staging'
    from /usr/lib/ruby/gems/1.8/gems/fpm-0.4.42/lib/fpm/package.rb:267:in `cleanup'
    from /usr/lib/ruby/gems/1.8/gems/fpm-cookery-0.16.2/lib/fpm/cookery/package/package.rb:69:in `cleanup'
    from /usr/lib/ruby/gems/1.8/gems/fpm-cookery-0.16.2/lib/fpm/cookery/packager.rb:171:in `build_package'
    from /usr/lib/ruby/gems/1.8/gems/fpm-cookery-0.16.2/lib/fpm/cookery/packager.rb:146:in `chdir'
    from /usr/lib/ruby/gems/1.8/gems/fpm-cookery-0.16.2/lib/fpm/cookery/packager.rb:146:in `build_package'
    from /usr/lib/ruby/gems/1.8/gems/fpm-cookery-0.16.2/lib/fpm/cookery/packager.rb:133:in `dispense'
    from /usr/lib/ruby/gems/1.8/gems/fpm-cookery-0.16.2/lib/fpm/cookery/cli.rb:104:in `exec'
    from /usr/lib/ruby/gems/1.8/gems/fpm-cookery-0.16.2/lib/fpm/cookery/cli.rb:68:in `execute'
    from /usr/lib/ruby/gems/1.8/gems/fpm-cookery-0.16.2/lib/fpm/cookery/book.rb:16:in `call'
    from /usr/lib/ruby/gems/1.8/gems/fpm-cookery-0.16.2/lib/fpm/cookery/book.rb:16:in `load_recipe'
    from /usr/lib/ruby/gems/1.8/gems/fpm-cookery-0.16.2/lib/fpm/cookery/cli.rb:64:in `execute'
    from /usr/lib/ruby/gems/1.8/gems/clamp-0.6.3/lib/clamp/command.rb:67:in `run'
    from /usr/lib/ruby/gems/1.8/gems/clamp-0.6.3/lib/clamp/subcommand/execution.rb:11:in `execute'
    from /usr/lib/ruby/gems/1.8/gems/clamp-0.6.3/lib/clamp/command.rb:67:in `run'
    from /usr/lib/ruby/gems/1.8/gems/clamp-0.6.3/lib/clamp/command.rb:125:in `run'
    from /usr/lib/ruby/gems/1.8/gems/fpm-cookery-0.16.2/bin/fpm-cook:7
    from /usr/bin/fpm-cook:19:in `load'
    from /usr/bin/fpm-cook:19
haf commented 10 years ago

Source of recipe: https://github.com/haf/fpm-recipes

bernd commented 10 years ago

Is it possible that you built as root before and didn't clean up the build directories?

haf commented 10 years ago

No, I removed everything from there as a part of verifying it was a problem.

bernd commented 10 years ago

Okay, thanks. I'll try to reproduce this.

haf commented 10 years ago

Tell me if you need anything.

bernd commented 10 years ago

I was able to reproduce the problem. The following diff to your recipe fixes the problem.

--- teamcity-server/recipe.rb
+++ teamcity-server/recipe.rb
@@ -28,11 +28,11 @@ class TeamcityServer < FPM::Cookery::Recipe

     # InitV script
     etc('init.d').install workdir('teamcity-server')
-    chmod 755, etc('init.d/teamcity-server')
+    chmod 0755, etc('init.d/teamcity-server')

     # data directory
     (var/'lib/teamcity-server').mkdir
-    chmod 755, (var/'lib/teamcity-server')
+    chmod 0755, (var/'lib/teamcity-server')

     # installation directory
     opt('teamcity-server/conf').mkdir

The first parameter (mode) for the chmod method should be an octal number. (see FileUtils.chmod)

$ fpm-cook --no-deps
===> Starting package creation for teamcity-server-8.0.5 (ubuntu, deb)
===> 
===> Fetching source: 
===> Using cached file /tmp/fpm-recipes/teamcity-server/cache/TeamCity-8.0.5.tar.gz
===> Building in /tmp/fpm-recipes/teamcity-server/tmp-build/TeamCity
===> Installing into /tmp/fpm-recipes/teamcity-server/tmp-dest
===> [FPM] Converting dir to deb {}
===> Removing existing package file: teamcity-server_8.0.5-2_amd64.deb
===> [FPM] No deb_installed_size set, calculating now. {}
===> [FPM] Reading template {"path":"/home/bernd/.rvm/gems/ruby-1.9.3-p545/gems/fpm-1.0.2/templates/deb.erb"}
===> [FPM] Creating {"path":"/tmp/package-deb-build20140303-9280-1i8z8pg/control.tar.gz","from":"/tmp/package-deb-build20140303-9280-1i8z8pg/control"}
===> [FPM] Created deb package {"path":"teamcity-server_8.0.5-2_amd64.deb"}
===> Created package: /tmp/fpm-recipes/teamcity-server/pkg/teamcity-server_8.0.5-2_amd64.deb

Sorry it took so long...

haf commented 10 years ago

Wow, gj @ me for giving it a decimal then :). I didn't even know there were a prefix for octal in ruby! Cool.

Thanks for spending the time to track this down!