I try to set up a deployer user for CI with Teamcity. I followed the instructions from this question on ServerFault: What's the best way of handling permissions for apache2's user www-data in /var/www?The problem is that the Teamcity application is creating directories with 755 permissions and the apache(2.4) can't write in some of them. If I change the permissions to 775 manually, apache can write them.Here's what I did to set uo the permissions:I created a user teamcity. Added www-data group to the user as secondary groupChanged the ownership of /var/www to root:www-dataChanged permissions for directories with: find /var/www -type d -exec chmod 2775 {} + and for files with:find /var/www -type f -exec chmod 0664 {} +Added umask 0002 to /etc/profileTested:su teamcityumask >0002touch testfilels -l>-rw-rw-r-- 1 teamcity teamcity        0 May 25 10:38 testfilecd /var/wwwtouch testfilels -l>-rw-rw-r--  1 teamcity www-data      0 Mai 25 10:42 testfileFor directories its the same. They are rw for user and group.After a deployment the permissions of directories and files are 755 and not 775 as expected. The Teamcity application is started as a service:start-stop-daemon --start  -c teamcity --exec /opt/TeamCity/bin/runAll.sh startIt seems that I missed some detail, but can't find it.System:Debian jessieApache 2.4Teamcity 9Solution:I changed the startup script for the Teamcity service by adding umask 002 before the startup command.
umask not working as expected in other than home directory
permissions;apache httpd;umask
From the description, it seems that TeamCity is ignoring the umask.  Perhaps it sets the umask in its service script (which was not mentioned in the question).  If so, you could modify the script.  If not, since it's apparently a closed-source application and in Java, your ability to thwart that is limited.  You could make a cron job (running once per minute) which fixes the directory permissions.Further reading:How can I set the umask from within java?teamcity-vagrant (possibly relevant script)Install a Teamcity v9.x CentOS Build Agent , example showing where to start looking for the service script in systemd.