Change users and file permissions after deployment

1,776 views
Skip to first unread message

Feurio

unread,
Sep 20, 2006, 6:48:31 AM9/20/06
to Capistrano
Hello,

sinve yesterday I am doing my deployment with capistrano 1.2.0, rails
1.1.6 and litespeed webserver 2.2.
The deployment via rake remote:deploy works.
But there is still one problem:
How can I change the user and the file permissions for everything that
is deployed automatically?
e.g. I want everything to belong to "www-data" and the file permission
should be ug=rwx
What is the best way to do this?

Feurio

Richard McMahon

unread,
Sep 20, 2006, 7:02:40 AM9/20/06
to capis...@googlegroups.com
I use the after_* task to hook in this ownership and permission juggling.
I use a different user and group per app so #{application} below is the username I want to own the files.

desc "Updates execute permissions on the fcgi handlers"
task :after_update_code, :roles => :app do
  run "chmod +x #{release_path}/public/dispatch.*"
  run "chmod 777 #{release_path}/public"
  run "chmod +x #{release_path}/script/*"
  run "mkdir #{release_path}/cache"
  run "chmod 775 #{release_path}/cache"
  run "chown -R #{application}:#{application} #{release_path}"
end

For initial setup I use another hook to create that user and attach the apache's nobody user to that group:

desc "Creates an additional shared devices directory for images"
task :after_setup, :roles => [:app, :db, :web] do
  run "adduser #{application}"
  run "gpasswd -a nobody #{application}"
  run "chgrp -R #{application} #{deploy_to}"
end

Hope that helps,
--Richie.

Feurio

unread,
Sep 20, 2006, 11:21:25 AM9/20/06
to Capistrano
Thanks Richie,

I think your answer will help me do what I want, but there still
something I didn´t get...
this kind of after_update_code task ... is it executed automatically
after the update_code task?

Feurio

Feurio

unread,
Sep 20, 2006, 11:31:35 AM9/20/06
to Capistrano
I found the answer myself in the next post Jamis telling that this kind
of task get executed automatically... :-)

Great.

Feurio

Tom Ward

unread,
Sep 20, 2006, 11:32:49 AM9/20/06
to capis...@googlegroups.com
Yes, if you define any task after_<another_task_name> it will get
called after the original task. Similarly you can define before tasks
to run prior to original tasks.

Tom

Reply all
Reply to author
Forward
0 new messages