I would like to create a directory /var/volatile/log/mydir or /var/log/mydir in a Yocto build. Based on the OE manual, we should not include the /var directory in any recipe file (http://www.embeddedlinux.org.cn/OEManual/recipes_volatiles.html). I tried to include this line install -m 0755 -d ${D}${localstatedir}/volatile/log/mydir
in my bbappend file, and I can confirm it that it doesn't work.
My application needs the directory /var/log/mydir to write a volatile logfile in that directory, for instance /var/log/mydir/myapp.log.
Since it is a volatile data, I can create the directory in the systemd service file such as:
[Service]
Type=simple
UMask=0027
User=@MYUSER@
Group=@MYGROUP@
ExecStartPre=mkdir -p /var/log/mydir
ExecStart=/usr/bin/myapp
The problem is that myapp cannot create the directory after the booting due to permission denied. How can I deal with this permission issue in Yocto setup?
Since the volatile directory is created during the runtime, not during the bibake compilation, a normal install -d doesn't work. These steps allows me to create the directory:
d /var/log/mydir 0775 myuser mygroup -
do_install_append()
of the myapp.bbappend file.install -d ${D}${sysconfdir}/tmpfiles.d/
install -m 0755 ${WORKDIR}/myapp.conf ${D}${sysconfdir}/tmpfiles.d/