Homebrew/homebrew — pull request #26214 by molawson (2014-01-28 00:04:30+00:00)
Title: Services command results in startup errors when run with sudo

I've just started using the `brew services` commands and ran into problems when I tried to use them with `sudo` to have a few services (dnsmasq and nginx) launch at startup (e.g. `sudo brew services start dnsmasq`)

In both cases, I didn't get any errors from the `services` commands directly, but neither service would actually start. I checked out the system logs, and both services were exiting with error codes when launchd tried to start them.

It appears to be a permissions/ownership problem caused by my user name being added to the generated plist file [here](https://github.com/Homebrew/homebrew/blob/1fbef27dfb69a21d9e6797e700a2a1dd9b3a2fe4/Library/Contributions/cmd/brew-services.rb#L350-L355). I updated those lines to skip making the UserName edits if the command has been run as root. That has fixed the issue for me, and the non-sudo version of the command still works, as well, but I'm not sure if the assumption I've made in these changes is a valid one for all cases.

Thanks for taking a look! And [here](https://gist.github.com/molawson/76e6f921588249d6b4fe) is the output the config, etc. commands.