All user-editable configuration parameters on NethServer are stored in
plain text database.

These values are used to generate the system configuration files, such
as those found in the /etc/ directory.
The configuration databases may be modified by various programs on the
system, including the web interface or scripts run from the command line
by a system administrator.

Each entry in the database is either a simple key/value pair or a key
and a collection of related property/value pairs.

You can access database entries from the command line using the
config command, as shown above, or the db command. The
config command provides a shorthand for accessing the
configuration database. The following commands are equivalent:

You can also access configuration database entries programmatically
using the esmith::ConfigDB and related Perl modules, which are
abstractions for the esmith::DB module.
For example, we can retrieve and show the admin account details like
this:

The configuration databases are initialized from files in the
/etc/e-smith/db/ hierarchy. These files can perform one of three
actions:

Create a database entry and set it to a default value, if the entry
does not already exist.

Migrate an entry from a previous value to a new value.

Force a database entry to a specific value, regardless of its current
setting (use with care!)

This design allows each package to provide part of the system
configuration, or migrate the system configuration values as required.
Note that a single database property can only be owned by one package.
Database initialization is run during system install, system upgrade and
after new software has been installed.

If you examine the /etc/e-smith/db/configuration/ directory you will
see three subdirectories: defaults/, force/ and migrate/ to
match the three options above. A similar structure exists for each of
the other databases. A new database can be created by populating a new
directory tree under the /etc/e-smith/db/ directory.

Configuration databases can also be initialized using a special
/usr/libexec/nethserver/initialize-<dbname>-database script, where dbname is the database name.
For example: /usr/libexec/nethserver/initialize-mycustomdb-database.

Migrate fragments are small pieces of Perl text which can be used to
perform more complex migrations than is possible with defaults and force
files. They would normally be used to replace database keys or
properties with new names, or to adjust policy settings during an
upgrade.

Each fragment is passed a reference to the current database in the
$DB variable. This variable is an instance of the appropriate
esmith::DB subclass, e.g. esmith::AccountsDB when the accounts
database migrate fragments are being executed. This means that you can
use the methods of that subclass, for example
esmith::AccountsDB->users().

Here is an example of a migrate fragment, which replaces the outdated
popd entry with the new name pop3:

This fragment checks whether the database (the configuration database in
this case) has a popd entry. If that entry does not exist, the
migrate fragment returns immediately. If the popd entry exists, we
need to convert it, so we retrieve the pop3 entry (or create it if
it doesn’t already exist). We then merge the properties from the
popd entry into the pop3 entry and finally delete the popd
entry.

If this migrate fragment is run again, it will return immediately as the
popd entry has already been deleted.

Please be careful with migrate fragments. Although they should only
modify entries within the current database, there are no restrictions
placed on what they can do. The ability to open and even modify other
databases may be required to perform a migration.

Migrate fragments must be safe to run multiple times. They should
migrate the value when required and do nothing in other cases.

Migrate fragments should never call croak or die. This will cause the
database migration to stop. If an error is detected, call carp or
warn to note the error in the logs.

Migrate fragments should call good termination with return(0) rather
than exit(0).

Migrate fragments should be owned by the package requiring the
migration so that the migration only occurs when that package is
installed.

Migrate fragments should be self-contained and ideally perform only
one migration per fragment.

The configuration databases should only be modified using the tools
and APIs provided.

The order of the entries and the order of properties is undefined.

The keys and property names are currently treated in a
case-sensitive manner, though this may change in the future.
Do not create keys or property names which differ only by their
case.

Underscores and hyphens are valid in key and property names, but
should normally be avoided.

Do not “overload” an existing property with a new value. If the
existing values do not meet your requirements, discuss your
implementation with the developers. Values which are not known by the
base may cause serious issues on upgrade. If the existing panels have
three choices, do not invent new choices without enhancing the panel
to support them.

The type pseudo-property is used internally and is
reserved .

By convention, database keys are lower case, and property names are
stored in mixed case. The type, status and access
properties are exceptions to this convention.

The storage location and internals of the databases is subject to
change.

The configuration databases are currently stored as pipe-delimited
flat text files in the /var/lib/nethserver/db/ directory.

All entries in a single database share the same namespace. Users,
groups, information bays, printers, and other entries in the accounts
database currently all share one namespace. This means that you cannot
have a user with the same name as an information bay, group or other
entry in the accounts database.

However, it would be possible to have a host named fredfrog as well
as a user named fredfrog as they are stored in separate databases
and thus different namespaces.