Question

Me along with a team of developers use fabric to deploy code to remote server, Whenever a new file is created and added to the git repo the default permission will be -rw--r--r which makes it impossible for other developers to update this file (all users belong to same primary group).

I want the permissions to be -rw-rw-r (group writable), i tried setting "umask 002" inside fabfile.py run("umask 002") but its not working. Is there solution to this, other than going and editing /etc/bash.bashrc

[Edit -1] output of fab script

[devsrv] Executing task 'deploy'
[localhost] local: bash -l -c "umask 002"
[localhost] local: bash -l -c "git push"
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 279 bytes, done.
Total 2 (delta 1), reused 0 (delta 0)
To devsrv:/opt/git/xyzprojv1.git
   8a7dcd5..141eb52  master -> master
[devsrv] run: umask 002
[devsrv] run: test -d /opt/webapps/xyzprojv1
[devsrv] run: git pull
[devsrv] out: remote: Counting objects: 3, done.
[devsrv] out: remote: Compressing objects: 100% (2/2), done.
[devsrv] out: remote: Total 2 (delta 1), reused 0 (delta 0)
[devsrv] out: Unpacking objects: 100% (2/2), done.
[devsrv] out: From /opt/webapps/../git/xyzprojv1
[devsrv] out:    8a7dcd5..141eb52  master     -> origin/master
[devsrv] out: Updating 8a7dcd5..141eb52
[devsrv] out: Fast-forward
[devsrv] out:  0 files changed, 0 insertions(+), 0 deletions(-)
[devsrv] out:  create mode 100644 umask_test
Was it helpful?

Solution

look like fabric runs each command in a separate shell (though i am not sure), I have temporarily solved this by rewriting commands that changes file-system in following format. If anyone has a better explanation on how fabric does this, it will be very helpful.

Instead of using

run("umask 002")
run("git pull")

i have changed that to

run("umask 002 && git pull")

And everything works as expected

[Edit]

Fabric has a clear documentation on this http://www.fabfile.org/faq.html#my-cd-workon-export-etc-calls-don-t-seem-to-work

So each call has its own distinct shell session. That is why umask set on a call has no effect on other subsequent calls

OTHER TIPS

Building on Ryu_hayabusa's answer, as pointed out in the edit link, you can also use the prefix context manager:

with prefix('umask 002'):
    run('git pull')
    # Other code here, also umasked

[edit]

Adding in the comment from BigToach -- multiple with statements can be combined on a single line as in:

with cd('/some/dir'), prefix('umask 002'):
    run('git pull')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top