# Environment of daemon when starting with sudo



## ractive (Jan 27, 2010)

Hello everyone

Our rc script contains user and group settings.

```
user=someuser
group=somegroup
```

The daemon that is started by this script still has the environment of the user that has started it i.e. with "sudo /usr/local/etc/rc.d/some_rc.sh start". This is the output of /usr/bin/env when called by the started daemon when the user james started it with "sudo ...":

```
SUDO_GID=1001
USER=root
MAIL=/var/mail/james
HOME=/home/james
SUDO_UID=1001
LOGNAME=root
TERM=xterm
USERNAME=root
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
SUDO_COMMAND=/usr/local/etc/rc.d/some_rc.sh start
SHELL=/usr/local/bin/bash
SUDO_USER=james
```

How can I change the environment to the user that is defined in the rc-script (i.e. "someuser" as in the example above)?


Thanks for your help
James


----------



## SirDice (Jan 27, 2010)

Start the application in the rc script with su to change it to run on someuser.


----------



## tangram (Jan 27, 2010)

If you goal it run the rc script as some user other than root you can also modify the port's Makefile, ports/UIDs and ports/GIDs. It's not very complicated and way better than running the rc script as root. Have a look at Porter's Handbook 6.23 Adding users and groups.


----------



## ractive (Jan 27, 2010)

BTW I just found out that run_rc_command runs ${command} as the user set in the variable ${name}_user (http://www.freebsd.org/cgi/man.cgi?query=rc.subr&sektion=8), but uses "su -m" which does not change the environment. :-(


----------

