gitlabhq/gitlabhq — pull request #5960 by jeffb-bt (2013-12-30 18:13:33+00:00)
Title: Switch from using a global sudo to su calls per-rake

The initial sudo fails from non-tty, and is not best practice. This switches to su for the calls needing the gitlab environment.

Not all servers have sudo. They should, but not all do. Thus init.d scripts typically use su instead when feasible.
sudo by default does not allow execution (even as root) without a tty, thus the gitlab script broke down when not manually invoked (via Puppet or on boot, for instance).

I was unable to emulate the initial call to sudo (basically rerunning the script as git user) with su, although it might be possible with some work. Instead I switched to wrapping individual rake calls with su. File removals could also be wrapped in a similar fashion if there is some security concern (there should not be).