0

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?

mhucka
  • 679
  • 4
  • 10
  • 22

2 Answers2

1

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.

  • Units gained new options StateDirectory=, CacheDirectory=, LogsDirectory= and ConfigurationDirectory= which are closely related to RuntimeDirectory= but manage per-service directories below /var/lib, /var/cache, /var/log and /etc. By making use of them it is possible to write unit files which when activated automatically gain properly owned service specific directories in these locations, thus making unit files self-contained and increasing compatibility with stateless systems and factory reset where /etc or /var are unpopulated at boot. Matching these new settings there's also StateDirectoryMode=, CacheDirectoryMode=, LogsDirectoryMode=, ConfigurationDirectoryMode= for configuring the access mode of these directories. These settings are particularly useful in combination with DynamicUser=yes as they provide secure, properly-owned, writable, and stateful locations for storage, excluded from the sandbox that such services live in otherwise.
Michael Hampton
  • 244,070
  • 43
  • 506
  • 972
1

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 that mkdir, 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.

John Mahowald
  • 32,050
  • 2
  • 19
  • 34