On a CentOS Linux 7.8 system, if I create a systemd service configuration file and include LogsDirectory
and/or CacheDirectory
in the [Service]
section, then do a systemctl daemon-reload
, the following errors are printed in /var/log/messages
:
Sep 8 13:14:50 model systemd: [/etc/systemd/system/hugo-sbml.service:18] Unknown lvalue 'CacheDirectory' in section 'Service'
Sep 8 13:14:50 model systemd: [/etc/systemd/system/hugo-sbml.service:19] Unknown lvalue 'LogsDirectory' in section 'Service'
The man page for systemd.exec
is confusing: it does not document LogsDirectory
and CacheDirectory
, but it does list error codes associated with failures involving them. Googling around, those settings appear to be commonly used in systemd configuration files.
Is there a replacement for the LogsDirectory
and CacheDirectory
settings in a systemd
service configuration file on CentOS 7? Or to put it another way, what are we supposed to do if we need log and cache directories to be created?
That is a documentation error of some sort. The directives you're looking for were not present in systemd 219, used by CentOS 7. They were added in systemd 235. You may use them in CentOS 8, which has systemd 239. You can also create these directories yourself.
Per the changelog in NEWS, options
StateDirectory=, CacheDirectory=, LogsDirectory= and ConfigurationDirectory=
are new in 235. EL 7 at 219 does not have those options.You will need to come up with some not systemd managed way to create these directories under
/var/log/
and/var/cache/
. Create an RPM package that owns the directories, add wrapper scripts to the systemd unit thatmkdir
, change the software to create its log and cache directories if they do not exist.Slightly disappointing that logs and cache directory existance is not self contained in the unit, yes. Once systemd is upgraded, in other words upgrade to CentOS 8, then you can use the feature.