Unitech/pm2 — pull request #329 by achingbrain (2014-03-03 19:40:12+00:00)
Title: Adds option to switch to a different user/group before starting a managed process

This is an attempt to address part of https://github.com/Unitech/pm2/issues/268 - if you run pm2 as root, everything it starts also runs as root.

It adds two options to the command line `--run-as-user` and `--run-as-group`.

If you are running `pm2` as root, and you start a process like this:

```
# pm2 --run-as-user foo start test.js
```

..then pm2 will fork the current process (as `root`), set up the child's logs and pid file (as `root`, in /root/.pm2), then switch to user `foo` to require and run `test.js`. Because the logs were opened before the privilege drop the process can still write to them even though the new user doesn't have the permissions to do so.

If you then do `ps aux | grep pm2` you'll see something like:

```
root 31568 0.0 0.0 2432784 476 s009 R+ 7:30PM 0:00.00 grep pm2
foo 31564 0.0 0.1 3057912 23156 ?? S 7:30PM 0:00.10 pm2: test
root 31561 0.0 0.1 3053776 19968 ?? Ss 7:30PM 0:00.12 pm2: Satan Daemonizer
```

..which shows that `pm2` is still running as `root` whereas the managed process `test.js` is running as `foo`.