Configuration directory for Linux service
By Urs Fässler
Have you ever struggled with finding the right place to store your service’s configuration files on a Embedded Linux system?
I’ve observed numerous file storage and System Configuration practices, such as placing everything under /data
, utilizing /opt/…
, or keeping operational data under /etc/…
, among others.
While these methods are feasible, I would advise against them.
The Filesystem Hierarchy Standard (FHS) specifies the appropriate locations for different types of files.
If you’re developing services for Embedded Linux, adhering to the FHS can significantly simplify software deployment and management. By following these standards, developers ensure their applications are more portable and easier to maintain. For instance, tools like Yocto automatically locate files expected in standard directories. Runtime behavior is as expected when you choose the correct location for temporary and log files.
Typically, I recommend the following paths:
-
/usr/bin/<app>
: the service binary -
/usr/lib/<lib>
: for a library -
/usr/share/<app>/
: static data needed by the service, such as images and documentation -
/var/lib/<app>/
: files the service is writing (e.g. configuration only the service is writing and reading) -
/etc/<app>/
: static configuration for a single unit, tailored to a specific customer’s requirements
Since writing to /var/lib/<app>/
is restricted for normal users, developing the service can be challenging.
This issue can be resolved by using ~/.config/<app>/
when the service runs as a user or during development.
I hope this is helpful, and I’m eager to learn about your practices for storing:
-
Calibration data for a unit
-
Configuration to specify the model
-
Any other scenarios I might have missed