Is it safe to store persistent data into /var/app_name/

filesystems

I want to create a system-wide directory, that contains application specific (read-write) data (like log files, configurations and other app specific metadata).

After reading a bit more about the Linux file system, I thought about using /var/app_name/, but then I found out, that some of the subdirs are temporary (not persistent among restarts, like run, log, tmp).

How significant is this? I mean, should I use another directory (like /home/app_name/) or using /var/app_name/ is OK?

Best Answer

From the Filesystem Hierarchy Standard:

Applications must generally not add directories to the top level of /var. Such directories should only be added if they have some system-wide implication, and in consultation with the FHS mailing list.

You should use /etc/app_name/ to store config files and other stuff for your program, and /var/log/app_name/ to store its logfiles.

For the data used by the application, you can store:

  • in /var/lib/app_name/ the persistent data and metadata
  • in /var/cache/app_name/ any app cache that can safely be deleted
  • in /var/spool/app_name/ the data that awaits processing

Definitely do not use /home/app_name/ which is reserved to the homedir of user app_name. If your program needs to create a specific user to run as, that'll be its place.

About your question in the comment: Linux does not delete neither rotate logs automatically for anything you put into /var/log/. In fact, often sysadmins have the opposite problem of logs filling up all the space... So it's up to you to delete or rotate logfiles; this is done via logrotate or a custom cron job.

Related Question