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?