Expected Config File Locations
Abigail
abigail at abigail.be
Tue Aug 30 15:43:13 BST 2011
On Tue, Aug 30, 2011 at 01:55:48PM +0100, Smylers wrote:
> Hi. I'm looking for some advice on where I should put the config file
> for a command I'm distributing on Cpan. Where would you it to be? I'm
> interested in opinions of Windows, Mac, and Unix users, for both
> per-user and system-wide config.
>
> Or has anybody here dealt with this in Perl, for a command which comes
> with a Cpan module and could be installed on any OS where Perl runs?
> File::ConfigDir looks like it should be useful for this. I think I'd
> want the system_cfg_dir and user_cfg_dir functions (my command doesn't
> have a graphical interface, so I don't think it counts as a 'desktop
> application') -- do these seem plausible for your platform?
>
> In particular, on Windows:
>
> * system_cfg_dir returns the value of %windir%. Is %windir%\bang* a
> sensible place for the config of a command called bang?
>
> * user_cfg_dir returns the user's home directory. Is that a sensible
> place for a configuration file?
>
> I see that psql uses %APPDATA%\postgesql\psqlrc.conf for per-user
> config -- is that better?
>
> * What name would you expect the file to have? Unix has the convention
> of a leading dot, such as .vimrc, to hide the file and prevent it from
> cluttering up typical directory listings. I see that Vim uses the name
> _vimrc on Windows.
>
> What about the file extensions? I see .psqlrc on Unix is psqlrc.conf
> on Windows; does the .conf help with using a text editor to edit it?
>
> * Most Windows systems seem to be single-user; do I even need both
> system-wide and per-user locations on Windows, and if not which one
> would you expect to find?
>
> And on Unix:
>
> * system_cfg_dir always returns /etc/. On some Unices such as FreeBSD
> I've seen /usr/local/etc/ used for commands that are installed under
> /usr/local/. Is that what you'd expect?
There's no real standard for Unix - but there are some convention.
A convention followed by many applications is that there are different
"levels" of configuration: system defaults, user defaults, directory
defaults. System defaults are often found in one or more of:
/etc/
/etc/system/
/etc/application/
/var/application/
/usr/local/etc/
/opt/etc/
$PREFIX/etc/ (with $PREFIX set at configure time)
User defaults are typically found in $HOME, and $HOME/.application/,
while directory defaults are found in the current working directory.
Now, some applications search a set of directories for configuration
files, and load all of them (typically system level first, then user
level, then directory level). Others search from most specific to least
specific, loading the first they find.
And even then, many application allow you to pass a configuration file
on the command line.
> File::ConfigDir has local_cfg_dir, which returns /usr/local/etc. So I
> could use that if the command has been installed in /usr/local/bin/
> and stick with /etc/ otherwise.
>
> But I'd be surprised to find /usr/local/etc/ being used on Linux.
>
> * What filename would you expect for a command's configuration file? I'm
> used to the "rc" suffix, so .bangrc for a command called bang, but for
> many of the common .*rc files the contents are genuine 'run commands'.
> For example, .bashrc, .muttrc, and .vimrc all contain commands which
> could be typed into the program interactively after starting it.
System level configuration files usually do *not* have a leading dot,
and many of them do not have an rc suffix. And not everything that is
for the form "run commands" ends in rc - .profile and .logout (or there
bash equivalents).
> That doesn't apply to my command, which isn't interactive, so maybe rc
> isn't the best suffix. But there are others like this, such as
> .screenrc, .cvsrc, .lynxrc, .offlineimaprc, and .muttprintrc.
And many more.
> Git has .gitconfig and SSH .ssh/config. MySQL uses .my.cnf. Would
> .bangconfig or .bang.cnf be better than .bangrc?
>
> And on OSX:
>
> * Is this aspect of the system sufficiently similar to FreeBSD that
> whatever is appropriate there would be appropriate on OSX as well? If
> not, what's different?
>
> Thanks for any wisdom you can share.
I can only tell you what I would do. For an application womble, I'd look
for $PREFIX/etc/womblerc, and /etc/womblerc, loading the first one found.
The load $HOME/.womblerc (if exists). Finally, look for ./.womblerc, and
load that as well (if exist).
Unless of course, the user uses the -f option, which loads configuration
from the file(s) given at the command line, ignoring any of the configuration
files.
Abigail
More information about the london.pm
mailing list