Default hierachy for tmpfs

Dear Daemon folks!

I'm feeling still pretty new to FreeBSD, while I'm on it since half a year. And I am still missing a very essential feature extending the tmpfs's abilities.
By the nature of any tmpfs, e.g. /run is empty after every boot. So far this is not a problem, but I would like to have a predefined folder hierarchy in some situations. On Linux this can be done by adding a file into /etc/tmpfiles.d/*.conf, which holds the information of names, owner, group, permissions, and last but not least cleanup settings if wanted.
It think this was implemented for cleaning persistent temps in the first place, but nowadays it also let's one just create a folder hierarchy. This is very handy esp. for tmpfs, though these start empty.

The situation is following: If a tmpfs is set up it might be have restricted write access. For example a service user account/group shall get access to there, it will fail, because after the tmpfs was emptied it couldn't create any folder or file. But the tmpfiles.d configs help here out: It would create the service user's subfolder right after / while booting though the service can access this folder as it's own, while the root of tmpfs is still protected but maybe shared by different service's users.

Alternative implementations are welcome, but workarounds might do the trick, too. =)

Thanks in beforehand.

Kind regards
Dom
 
By the nature of any tmpfs, e.g. /run is empty after every boot.
That's primarily a Linux thing. FreeBSD uses /var/run, not /run.

On Linux this can be done by adding a file into /etc/tmpfiles.d/*.conf, which holds the information of names, owner, group, permissions, and last but not least cleanup settings if wanted.
That would be /tmp, not /run. If you want to use tmpfs(5) for /tmp, add to /etc/fstab:
Code:
tmpfs                   /tmp            tmpfs   rw,mode=1777    0       0
/etc/rc.d/cleartmp will do the rest.

Don't need to set any permissions for /var/run (or /run). It's root owned, if a service is running on some user account and needs to write a pid file (or something else), its rc(8) script should set the correct permissions before starting it.

For example (from /usr/local/etc/rc.d/zabbix_agentd):
Code:
zabbix_agentd_precmd()
{
        pidfile=${zabbix_agentd_pidfile}
        if get_pidfile_from_conf PidFile ${zabbix_agentd_config}; then
                pidfile="$_pidfile_from_conf"
        fi
        logfile=/var/log/zabbix/zabbix_agentd.log
        if get_pidfile_from_conf LogFile ${zabbix_agentd_config}; then
                logfile="$_pidfile_from_conf"
        fi
        local rundir=${pidfile%/*}
        local logdir=${logfile%/*}
        [ -d $rundir ] || install -d -m 0755 -o zabbix -g zabbix $rundir
        [ -d $logdir ] || install -d -m 0755 -o zabbix -g zabbix $logdir

        # This shouldn't be necessary with pidfile, but empirically it was the
        # only way to reap the parent PID instead of all PIDs from
        # check_process, which may leak SysV IPC objects and prevent restart
        # and/or race condition on restart.
        rc_pid=$(check_pidfile ${pidfile} ${command})
}
 
As far as I read, if you e.g. install xfce4, you have to setup a /run as well. (This might be outdated.)
However, that was not the point at all. I could create a tmpfs at any mount point I wish through /etc/fstab. Also the given situation is not about a service.



I require a custom mounted tmpfs, which is not only owned by a single user. But containing folders where a single user has full access rights. Maybe the following is a better example:
Think of a /home mounted on a tmpfs. No user has write access to /home itself, but to their folders located within, e.g. /home/someuser. But because /home itself is a tmpfs file system, after reboot the users' folders are gone. Though, it is required to re-create the folders with the correct permissions after reboot. On THIS point a service could DO the trick of course.

What I would like to know is:
  • Is there a port/program/system which is offering this method out of the box or
  • do I have to write my own service for this?
As reference, this is the variant I know from Linux: tmpfiles.d(5).
 
I maybe a little late, but if I get it right, You need run 'service var_run restart' right after You populate '/var/run/' on your own.
As a result You will get the mtree-file in `/var/db/mtree/` to populate Your '/var/run/' folder on boot.

Bash:
[root@rhino /]$ grep var_run /etc/defaults/rc.conf 
var_run_enable="YES" 	# Save/restore /var/run structure at shutdown/reboot
var_run_autosave="YES" 	# Only restore /var/run structure at shutdown/reboot
			            # The user is expected to issue service var_run save to
var_run_mtree="/var/db/mtree/BSD.var-run.mtree"
[root@rhino /]$ grep run /etc/fstab
tmpfs			/var/run			tmpfs	rw,mode=1777		0 0
[root@rhino /]$ ls -l /var/db/mtree/BSD.var-run.mtree
-rw-r--r--  1 root wheel 682 Sep 23 22:34 /var/db/mtree/BSD.var-run.mtree

Just checked it worked.
After reboot my new '/var/run/redis/' is in place.
 
Back
Top