# Proper location for daemon configuration files?



## ianc1215 (Nov 13, 2022)

When porting over a piece of software from Linux I want to have a file that allows me to set the default directory and user that the daemon should run as. In the FreeBSD universe where do these files live? Is /etc/default/service.conf still as valid as it is on Linux or is there a "better" place to store them?


----------



## Phishfry (Nov 13, 2022)

ianc1215 said:


> Is /etc/default/service.conf still as valid as it is on Linux or is there a "better" place to store them?


/etc/defaults/ should not be used in my opinion. This directory contains very important system files.
Same with /boot/defaults/
I think /usr/local/etc/ is our preferred user location and sub-directories under this structure.

Some ports use /usr/local/etc/ and some make a program directory for settings. ie. /usr/local/etc/nginx/


----------



## Phishfry (Nov 13, 2022)

Any ports that need a rc.d startup script should use /usr/local/etc/rc.d/.
/etc/rc.d/ directory is only for FreeBSD files.


----------



## ianc1215 (Nov 14, 2022)

Phishfry said:


> Any ports that need a rc.d startup script should use /usr/local/etc/rc.d/.
> /etc/rc.d/ directory is only for FreeBSD files.


Ok so configuration files that change how the startup script runs would still be stored in /usr/local/etc


----------



## Phishfry (Nov 14, 2022)

That location is fine but generally you wouldn't change the startup script at all.
You add option flags that you could enable on a per user basis.

For example for the core service of syslog.

In your rc.d script you would add accommodations for flags like this:
/etc/rc.conf

```
syslogd_enable="YES"
syslogd_flags="-ss"
```
So with this you are launching `syslogd` with the -ss option.
Not all users would need the -ss option flag.

So if you notice, syslogd is launched automatically without an rc.conf setting.
This is where /etc/defaults/rc.conf comes in. syslogd is enabled by /etc/defaults/rc.conf
So enabling it is not needed. It is a FreeBSD default service. Baked into /etc/defaults/rc.conf.
To override it you don't touch /etc/defaults/rc.conf but use /etc/rc.conf to override the default setting.

```
syslogd_enable="NO"
```


----------



## PMc (Nov 15, 2022)

I prefer to create an extra tree for my own or ported things. I leave /etc to the base system, and /usr/local to pkg. And then I have /ext/bin, /ext/libexec, /ext/etc, /ext/etc/rc.d and so on, and I add /ext/etc/rc.d to the startup directories, and put the configurations all into /etc/rc.conf.local.
So I have only very limited additions into /etc, and nothing but the packages in /usr/local, and keeping things clean is quite a bit easier.
And when I add some software, I try to write a proper rc.d script, move the interesting configurations into variables and put them into /etc/rc.conf.local. (That works well for my netgraphs, bhyve guests, various python- and rails-applications, etc.)
Finally, add /ext/src/... for some repo where these scripts are maintained and get installed via make, and a few years later one will still understand what was done and why.


----------



## VladiBG (Nov 15, 2022)

hier(7)
					






					www.freebsd.org


----------



## SirDice (Nov 15, 2022)

ianc1215 said:


> want to have a file that allows me to set the default directory and user that the daemon should run as.


Defaults should be set in the rc(8) script. And it should pick up rc.conf variables so users can overrule them.

In your rc(8) script, you set the defaults:

```
: ${myservice_enable:=NO}
: ${myservice_directory:=/some/default/dir}
: ${myservice_user}:=default_user}
```


Then rc.conf variables can be used to overrule the defaults:

```
myservice_enable="YES"
myservice_directory="/some/where"
myservice_user="myuser"
```


----------

