LDP/LDP/howto/docbook/Autodir-HOWTO.xml

691 lines
44 KiB
XML
Raw Normal View History

2004-10-05 23:31:43 +00:00
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
"http://docbook.org/xml/4.2/docbookx.dtd" []>
<article>
<articleinfo>
<!-- Use "HOWTO", "mini HOWTO", "FAQ" in title, if appropriate -->
<title>Autodir HOWTO</title>
<editor> Rahul Sundaram </editor>
<author>
<firstname>Venkata Ramana</firstname>
<surname>Enaganti</surname>
<affiliation>
<!-- Valid email...spamblock/scramble if so desired -->
<address><email>ramana &lt;&gt; intraperson dot com</email></address>
</affiliation>
</author>
<!-- All dates specified in ISO "YYYY-MM-DD" format -->
<pubdate>2004-09-23</pubdate>
<!-- Most recent revision goes at the top; list in descending order -->
<revhistory>
<revision>
<revnumber>1.00</revnumber>
<date>2004-09-23</date>
<authorinitials>VRE</authorinitials>
<revremark>Initial release, reviewed by Rahul Sundaram at TLDP</revremark>
</revision>
<revision>
<revnumber>0.32</revnumber>
<date>2004-09-13</date>
<authorinitials>VRE</authorinitials>
<revremark>New sections like requirements and others.</revremark>
</revision>
<revision>
<revnumber>0.10</revnumber>
<date>2004-06-24</date>
<authorinitials>VRE</authorinitials>
<revremark>second draft</revremark>
</revision>
<revision>
<revnumber>0.9</revnumber>
<date>2004-06-11</date>
<authorinitials>VRE</authorinitials>
<revremark>first draft</revremark>
</revision>
</revhistory>
<!-- Provide a good abstract; a couple of sentences is sufficient -->
<abstract>
<para>
This HOWTO is about <emphasis role="bold">Autodir</emphasis> installation, configuration and other issues related to <emphasis role="bold">Autodir</emphasis>.
</para>
</abstract>
</articleinfo>
<!-- Content follows...include introduction, license information, feedback -->
<sect1 id="intro">
<title>Introduction</title>
<para><emphasis role="bold">Autodir</emphasis> offers a simple and effective means to create directories like home directories in a transparent manner. It relies on the <ulink url="htp://www.autofs.org">autofs</ulink> protocol for its operation.</para>
<para>This document explains how to create directories on demand using <emphasis role="bold">Autodir</emphasis> in a transparent way to the applications. This document also explains using transparent backup feature that is possible with <emphasis role="bold">Autodir</emphasis> without bringing system down for backup purpose for all directories managed by <emphasis role="bold">Autodir</emphasis>.</para>
<!-- Legal Sections -->
<sect2 id="copyright">
<title>Copyright and License</title>
<!-- The LDP recommends, but doesn't require, the GFDL -->
<para>
This document, <emphasis>Autodir HOWTO</emphasis>,
is copyrighted (c) 2004 by <emphasis>Venkata Ramana Enaganti</emphasis>.
This work is licensed under the Creative Commons Attribution License. To view a copy of this license, visit <ulink url="http://creativecommons.org/licenses/by/2.0">http://creativecommons.org/licenses/by/2.0/</ulink> or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
</para>
<para>
Linux is a registered trademark of Linus Torvalds.
</para>
</sect2>
<sect2 id="disclaimer">
<title>Disclaimer</title>
<para>
No liability for the contents of this document can be accepted.
Use the concepts, examples and information at your own risk.
There may be errors and inaccuracies, that could be damaging to
your system. Proceed with caution, and although this is highly
unlikely, the author(s) do not take any responsibility.
</para>
<para>
All copyrights are held by their by their respective owners,
unless specifically noted otherwise. Use of a term in this
document should not be regarded as affecting the validity of any
trademark or service mark. Naming of particular products or
brands should not be seen as endorsements.
</para>
</sect2>
<!-- Feedback -->
<sect2 id="feedback">
<title>Feedback</title>
<para>
Feedback is most certainly welcome for this document. Send
your additions, comments and criticisms to the following
email address : <email>ramana &lt;&gt; intraperson dot com</email>.
</para>
</sect2>
<sect2>
<title>New Versions of this Document</title>
<para>The latest version of this HOWTO will be made available from <ulink url="http://www.intraperson.com/autodir/">here</ulink>.</para>
</sect2>
<sect2 id="credits">
<title>Credits / Contributors</title>
<para>
In this document, I have the pleasure of acknowledging for language and technical review work:
</para>
<!-- Please scramble addresses; help prevent spam/email harvesting -->
<itemizedlist>
<listitem>
<para>Rahul Sundaram<email>rahulsundaram@yahoo.co.in</email></para>
</listitem>
</itemizedlist>
</sect2>
</sect1>
<!--
The rest of the document follows. This is where your
subject-specific content goes. A logical reading
progression should be present - installation, setup,
configuration, using, advanced topics, etc.
-->
<!-- Other Sections of Interest... -->
<sect1>
<title>Before going to details...</title>
<para>After releasing intraperson beta, I started working on a administration guide that deals with administration aspects of <emphasis role="bold">intraPerson</emphasis>. For more details check <ulink url="http://www.intraperson.com"> http://www.intraperson.com</ulink>. But I was stuck with one simple thing. It is easy to create users in ldap -- at least I think so; but how to create home directories for those users in ldap whereever those ldap accounts are imported?</para>
<para>I found some solutions But I was not satisfied as every solution has serious drawback attached with it. But after going through autofs documents and hacking little bit, I arrived at conclusion that autofs protocol may offer much better solution to this challenge.</para>
<para>The result is <emphasis role="bold">Autodir</emphasis>, based on the autofs protocol.</para>
</sect1>
<sect1>
<title>Why not pam_mkhomedir?</title>
<para>The PAM module <literal>pam_mkhomedir</literal> uses Pluggable Authentication Module architecture for its operation. As such, there are some limitations associated with it. For instance:</para>
<itemizedlist>
<listitem><para>Some servers may not authenticate users but they may expect user directories to exist. This means they do not use PAM, and in turn, <literal>pam_mkhomedir</literal> does not get a chance to create home directories. The notorious example is on email servers.</para></listitem>
<listitem><para>PAM is always an optional component for authentication. Some may not use PAM at all and use a different method to authenticate users. In this case <literal>pam_mkhomedir</literal> is never going to be used.</para></listitem>
<listitem><para>Generally <filename>/home</filename> is owned by root and only root users can create home directories in it. Therefore the server that wishes to create home directories through PAM must be run as root, or else the home directory must be made similar in permission to <filename>/tmp</filename>.</para></listitem>
</itemizedlist>
<para>Finally, <emphasis role="bold">Autodir</emphasis> is much wider in scope and supports many more interesting features.</para>
</sect1>
<sect1>
<title>Where it can be used</title>
<itemizedlist>
<listitem><para>Where user accounts reside in centralized database like ldap, SQL, NIS, NIS+ or other databases, from which user and groups are imported to other systems. To create, for example home, group directories in those systems which import these accounts from centralized database, on demand.</para></listitem>
<listitem><para>To exploit its transparent backup feature for 24*7 online systems.</para></listitem>
<listitem><para>It can be also used even when accounts are in a local system, to some extent hiding what accounts exist in <filename>/home</filename> directory, for example.</para></listitem>
</itemizedlist>
</sect1>
<sect1>
<title>What it is not</title>
<para><emphasis role="bold">Autodir</emphasis> can create directories but it does not remove them once user, group entries are removed from system accounts database. And there may be some more limitations with modules used with <emphasis role="bold">Autodir</emphasis>. Check appropriate sections.</para>
</sect1>
<sect1>
<title>Differences between Autodir and Autofs</title>
<para>Now the important issue arises as there is already an autofs package to handle mounts and Autodir is in similar line with the autofs package.</para>
<itemizedlist>
<listitem>
<para>The main purpose of autofs is to deal with network mounts on demand instead of mounting all at the same time, which results in preserving system resources. Though there is some support in the autofs package to mount home directories on demand, the requirement is that <emphasis>these home directories must exist already</emphasis>.</para>
<para>On the other side, <emphasis role="bold">Autodir</emphasis> specializes <emphasis>only</emphasis> in local directory creation and mounting them on demand.</para>
<para><emphasis role="bold">Autodir</emphasis> can also create real directories in disk file systems such that they do not reside in one single flat base directory. This is how utilities like <command>useradd</command> create by default. In a standard file system setup, all home directories reside in base <filename>/home</filename> directory. For file systems like ext2, ext3 performance will degrade if large number of home directories exist in single base directory.</para>
<para> For applications accessing these directories, <emphasis role="bold">Autodir</emphasis> presents all directories for them in a <emphasis>single</emphasis> autofs mounted virtual base directory <emphasis>on demand</emphasis>; actual directories are created in subdirectories of some other directory in hierarchical style.</para>
<para> For example, the real home for a user with uid <literal>user1</literal> will be created as <filename>/autohome/u/us/user1</filename> if configured that way, but mounted in <filename>/home</filename> on demand for applications accessing home directory in <filename>/home/user1</filename>.</para>
<para>Permissions for real base directory, where actual home directories are kept <filename>/autohome</filename> in the above example, are kept in such a way that <filename>/autohome</filename> can not be accessed by anyone except by root.</para>
<para>This mounting of directories on demand and unmounting when not in use presents an interesting opportunity -- the ability to tell when a directory is in use and when it is not in use. This simply means a program like backup can be started when a directory is unmounted.</para>
<para><emphasis role="bold">Autodir</emphasis> exploits this capability by starting the command-line mentioned backup whenever a directory becomes unused.</para>
</listitem>
<listitem>
<para>There is one more important issue to be presented if you are an administrator reading this document. <emphasis role="bold">Autodir</emphasis> does not call external programs <command>mount</command> and <command>umount</command>, as is the case with the autofs package; rather, it uses system calls directly. As a side effect, it is faster and more reliable, but <filename>mtab</filename> is not updated. I felt this was not necessary as all mounts and unmounts are local directories.</para>
</listitem>
<listitem>
<para>Another minor difference is that <emphasis role="bold">Autodir</emphasis> is completely <emphasis>multi-threaded</emphasis>. Autofs is also expected to be multi-threaded in future versions.</para>
</listitem>
</itemizedlist>
</sect1>
<sect1>
<title>How it works</title>
<para><emphasis role="bold">Autodir</emphasis> uses modules to get specific functionality. The core <emphasis role="bold">Autodir</emphasis> implements generic functionality on which modules can exploit and add specific functionality of their own.</para>
<para>At any moment only one module can be added to <emphasis role="bold">Autodir</emphasis>. If there are two modules, for example <literal>autohome</literal>, <literal>autogroup</literal>, two processes of <emphasis role="bold">Autodir</emphasis> should be created so that each process will have required modules attached to it.</para>
<para>For further explanation I chose the <literal>autohome</literal> module which handles transparent home directory creation.</para>
<note>
<itemizedlist>
<listitem><para><literal>autohome</literal> module creates user home directories on demand if these does not exist already.</para></listitem>
<listitem><para>It is assumed user accounts exists but not their home directories. Either because these accounts were created with the <literal>-M</literal> option with <command>useradd</command> or these accounts were imported from ldap, NIS or some other external database for which home directories are yet to be created.</para></listitem>
<listitem><para>It also assumed <emphasis>for this explanation only</emphasis> that all user home directories are expected to be in the <filename>/home</filename> directory.</para></listitem>
</itemizedlist>
</note>
<note><para>Some fine details are intentionally kept aside to make explanation easy to understand.</para></note>
<para>First autofs file system is mounted on <filename>/home</filename> directory by <emphasis role="bold">Autodir</emphasis>. And this is informed to the Linux kernel that <filename>/home</filename> is managed by user space application <emphasis role="bold">Autodir</emphasis> from now on.</para>
<note>Do not bother too much about autofs file system if you do not understand about it. Just think some special kind of file system something in similarity with memory based file system but with some additional special properties.</note>
<screen>
+----------------+
| Linux Kernel |
+----------------+
/ \
/ \
/ \
/ \
+-------------+ +--------+ +------------+ +-----------------+
| Application |------>| /home |&lt;-----&gt;| Autodir |&lt;------&gt;| autohome module |
+-------------+ +--------+ +------------+ +-----------------+
\ /
\ +----------------+ /
+-| /autohome |&lt;------------------+
+----------------+
</screen>
<para>Whenever an application or daemon needs access to user's home directory, for example <filename>/home/userhome1</filename>, they directly enter into <filename>/home/userhome1</filename> to access it. Kernel which notices this, informs to <emphasis role="bold">Autodir</emphasis> if <filename>userhome1</filename> directory does not exist already in <filename>/home</filename>.</para>
<para><emphasis role="bold">Autodir</emphasis>, in turn, passes this request to <literal>autohome</literal> module. <literal>autohome</literal> module does not touch <filename>/home</filename> directory. Instead it manages <emphasis>real home directories</emphasis> some where else, for example in <filename>/autohome</filename> as shown in the above figure.</para>
<para><literal>autohome</literal> module creates real home directory if it does not exist already in <filename>/autohome</filename> directory. After it is successfully created or failed to created, whatever the outcome, it is reported back to <emphasis role="bold">Autodir</emphasis> along with the path to real home directory -- if successful.</para>
<para>If <literal>autohome</literal> module reports success, <emphasis role="bold">Autodir</emphasis> creates <filename>userhome1</filename> directory under <filename>/home</filename> and mounts <emphasis>real home directory</emphasis> from <filename>/autohome</filename> on it. At the end <emphasis role="bold">Autodir</emphasis> informs this to the kernel whether this whole operation successful or failure. Accordingly kernel allows application to enter the directory or reports that no such directory exists, in case of failure, back to the application.</para>
</sect1>
<sect1>
<title>Some definitions</title>
<para>Before going further it is better to understand the following terms to simplify explanation.</para>
<variablelist>
<varlistentry><term><emphasis role="bold">Virtual directories</emphasis></term><listitem><para> These directories do not exist on disk. Instead these are created and deleted on demand in memory. If system reboots all these directories vanish. In the previous figure, all directories under <filename>/home</filename> are <emphasis>virtual directories</emphasis>.</para></listitem></varlistentry>
<varlistentry><term><emphasis role="bold">Virtual base directory</emphasis></term><listitem><para> This is the directory that holds all <emphasis>Virtual directories</emphasis>. This directory <emphasis>does</emphasis> exist on disk and therefore it remains even after reboot. In the previous figure <filename>/home</filename> is <emphasis>virtual base directory</emphasis>.</para></listitem></varlistentry>
<varlistentry><term><emphasis role="bold">Real directories</emphasis></term><listitem><para> These are the directories that actually reside on the disk. Even after reboot, these remain intact. In the previous figure all directories created under <filename>/autohome</filename> are <emphasis>real directories</emphasis>.</para></listitem></varlistentry>
<varlistentry><term><emphasis role="bold">Real base directory</emphasis></term><listitem><para> This is the directory that holds all real directories. In the above figure <filename>/autohome</filename> is <emphasis>real base directory</emphasis>.</para></listitem></varlistentry>
</variablelist>
<para>Each <emphasis>virtual directory</emphasis> is mapped to <emphasis>real directory</emphasis>. Which means whatever written or modified to <emphasis>virtual directory</emphasis> is actually sent to <emphasis>real directory</emphasis>.</para>
<para>On reboot of the system <emphasis>real directories</emphasis> and their content remain intact. But <emphasis>virtual directories</emphasis> are again created on demand as exactly as they were before.</para>
<para><emphasis>Virtual directories</emphasis> are removed if these are not used for a specified time period and created again if necessary. When <emphasis>Virtual directory</emphasis> is removed backup program is started on corresponding <emphasis>real directory</emphasis> if backup is configured.</para>
<important><para>Applications should access only <emphasis>virtual directories</emphasis>. <emphasis>Real directories</emphasis> are hidden from applications except for root. But there is one exception. Backup programs always access only <emphasis>real directories</emphasis>.</para></important>
</sect1>
<sect1 id="dirorg">
<title>Directory organization under real base directory</title>
<para>Why special organization under <emphasis>real base directory</emphasis>? If we just create all <emphasis>real directories</emphasis> in one <emphasis>real base directory</emphasis> there could be performance penalty when there are large number of <emphasis>real directories</emphasis> to be created. File systems like ext2/ext3 are not optimized for this kind of flat directory structure.</para>
<para>It would be much better if <emphasis>real base directory</emphasis> is divided into more subdirectories or even dividing these subdirectories again into more subdirectories. And in the final subdirectories actual home directories are kept!</para>
<para>There are three types of directory organization.</para>
<variablelist>
<varlistentry><term><emphasis role="bold">level 0</emphasis></term><listitem><para>Actually no organization. All home directories are created directly under <emphasis>real base directory</emphasis>.</para></listitem></varlistentry>
<varlistentry><term><emphasis role="bold">level 1</emphasis></term><listitem><para><emphasis>Real base directory</emphasis> is divided into more subdirectories. These subdirectories names are derived from first letter of the final directory to be created. For example, if <filename>user1</filename> directory is to be created, first a directory named 'u' is created under <emphasis>real base directory</emphasis>. Then in that subdirectory actual directory <filename>user1</filename> created as <filename>/&lt;real_base_directory&gt;/u/user1</filename>.</para></listitem></varlistentry>
<varlistentry><term><emphasis role="bold">level 2</emphasis></term><listitem><para>Same as level 1 organization but after first level of subdirectories, second level subdirectories also created. Name for which is derived form starting two letters of the final directory to be created. For example, for user <literal>user1</literal> as with the above example, <filename>/&lt;real_base_directory&gt;/u/us/user1</filename> is created.</para></listitem></varlistentry>
</variablelist>
</sect1>
<sect1 id="vdexp">
<title>Virtual directory expiration</title>
<para>When an application tries to access <emphasis>virtual directory</emphasis> in <emphasis>virtual base directory</emphasis>, <emphasis role="bold">Autodir</emphasis> creates <emphasis>virtual directory</emphasis> in it if it does not exist already and mounts the <emphasis>real directory</emphasis> on it from <emphasis>real base directory</emphasis>. But once this happens and if this <emphasis>virtual directory</emphasis> is not accessed from <emphasis>virtual base directory</emphasis> for a specified time period by any application, this directory is removed and accordingly that corresponding <emphasis>real directory</emphasis> in <emphasis>real base directory</emphasis> is marked for backup.</para>
<para>The time period to wait for expiration can be given through <link linkend="autodir_t_opt">command line option</link> to <emphasis role="bold">Autodir</emphasis>.</para>
</sect1>
<sect1 id="backup">
<title>Backup support</title>
<para> <emphasis role="bold">Autodir</emphasis> supports backup program launching when a <emphasis>virtual directory</emphasis> is removed after a period of inactivity. Removal of <emphasis>virtual directory</emphasis> is itself is an assurance that no other application can access the content and modify it.</para>
<para>Like there is wait duration for expiring <emphasis>virtual directory</emphasis>, for backup also <emphasis role="bold">Autodir</emphasis> waits some more time, after <emphasis>virtual directory</emphasis> expiration, for starting backup. This time period can be configured through <link linkend="autodir_w_opt">command line option</link> to <emphasis role="bold">Autodir</emphasis>.</para>
<para>By design, backup programs are expected to operate on <emphasis>real directory</emphasis> but not on <emphasis>virtual directory</emphasis>. If backup program try to access <emphasis>virtual directory</emphasis> <emphasis role="bold">Autodir</emphasis> assumes some regular application is in need of that directory and backup program is killed even if the <emphasis>virtual directory</emphasis> accessing process is backup program itself.</para>
<para>A separate backup process for each <emphasis>real directory</emphasis> is used. The backup program can be given <link linkend="back_esc_str">arguments</link> of <emphasis>real directory</emphasis> on which to operate.</para>
<note><para>Backup support is independent of any particular module being used. It is applicable to all modules with <emphasis role="bold">Autodir</emphasis>.</para></note>
<important><para>Backup programs should never access <emphasis>virtual directory</emphasis> or <emphasis>virtual base directory</emphasis>.</para></important>
<caution><para>Backup feature is not much useful if <emphasis>virtual directories</emphasis> are accessed all the time by applications.</para></caution>
</sect1>
<sect1 id="backupreq">
<title>Backup program requirements</title>
<para><emphasis role="bold">Autodir</emphasis> demands some extra requirements from backup program being used. The reason for this is that when backup is working on <emphasis>real directory</emphasis> and with corresponding expired <emphasis>virtual directory</emphasis> and that <emphasis>virtual directory</emphasis> is requested again by an application while backup is running, backup is killed. First <literal>SIGTERM</literal> is sent to gracefully stop it. But if it does not shutdown in time -- one second at this moment; <literal>SIGKILL</literal> will be sent which is guaranteed to stop the backup.</para>
<note>When and only when backup stopped, application is given access to the <emphasis>virtual directory</emphasis> requested.</note>
<important><para>Whatever backup is used, it should be able to recover from this signal gracefully, not causing unrecoverable side effects.</para></important>
<para>One more important issue is that the environment under which it is run. All backup programs are run as root user. But at the same time all unnecessary root privileges are taken away using POSIX capabilities. In other words these backup programs can read any file or directory that belongs to any user on the system and nothing more than that. Other than that it is like ordinary user level process.</para>
</sect1>
<sect1>
<title>Module options</title>
<para>There are two kinds of options that can be passed to <emphasis role="bold">Autodir</emphasis>. In the first type, <link linkend="aoptions">options</link> are for <command>autodir</command> itself and are common irrespective of which module is used. There are other type of options which are specific to the module being used. These options called suboptions and are passed to the module being used differently with main option <literal>-o</literal>. This is similar to <command>mount</command> command suboptions.</para>
<para>For example, suboptions to the example module <literal>autohome</literal> can be passed as,</para>
<screen>
-o 'realpath=/tmp/autohome,level=2,noskel'
</screen>
<para>Here <literal>realpath</literal>, <literal>level</literal>, <literal>noskel</literal> are suboptions for <literal>autohome</literal> module.</para>
</sect1>
<sect1>
<title>Autodir requirements</title>
<itemizedlist>
<listitem>
<para>Linux kernel equal to or later version of 2.4. These kernel versions support mounting one directory on another directory. At this moment <emphasis role="bold">Autodir</emphasis> is not ported to other Unices but this may change in future.</para>
</listitem>
<listitem>
<para><emphasis role="bold">Autodir</emphasis> requires autofs kernel module based on protocol version 3. But it does not require autofs user level package. Autofs kernel module is pretty standard and almost all distributions include it.</para>
</listitem>
</itemizedlist>
</sect1>
<sect1 id="autofs_kmod">
<title>Autofs kernel module</title>
<para><emphasis role="bold">Autodir</emphasis> uses autofs kernel module for its operation. Kernel module <literal>autofs</literal> must be loaded before even starting <command>autodir</command> for its proper operation.</para>
<para>This can be done as root user and using <command>modprobe</command> command as follows,</para>
<screen>
# modprobe autofs
</screen>
</sect1>
<sect1>
<title>Importing user and group accounts</title>
<para>If user and group accounts reside in centralized database these must be imported before starting <emphasis role="bold">Autodir</emphasis>. How to do this is out of scope of this HOWTO. But there are number of documents which explain how to do this in clear manner.</para>
</sect1>
<sect1>
<title>Getting it</title>
<para>At this moment <emphasis role="bold">Autodir</emphasis> available in tar, rpm formats. More information can be found at <ulink url="http://www.intraperson.com/autodir/">http://www.intraperson.com/autodir/</ulink>.</para>
<para>If source is downloaded, follow these simple steps to install it.</para>
<itemizedlist>
<listitem>
<para>Unpack the source.</para>
<para><literal>$ tar zxvf &lt;tar file name&gt;</literal></para>
</listitem>
<listitem>
<para>Move to the expanded directory and execute the following.</para>
<para><literal>$ ./configure</literal></para>
<para><literal>$ make</literal></para>
<para><literal># make install</literal></para>
</listitem>
</itemizedlist>
<note><literal>configure</literal> script check for required libraries. If these are not present it will stop from proceeding.</note>
</sect1>
<sect1 id="homedir">
<title>Managing Home directories</title>
<para>This section will explain how to configure <emphasis role="bold">Autodir</emphasis> so that user home directories are created on demand. For this purpose <literal>autohome</literal> module is used which deals with specifics of home directory creation.</para>
<para>To load <literal>autohome</literal> module with <emphasis role="bold">Autodir</emphasis>, use option <literal>-m</literal>. For example, <literal>-m /usr/lib/autodir/autohome.so</literal>.</para>
<note><para>When an application tries to access home directory, that home directory is used to check if there is any user with user name same as the directory being accessed. If user name exist with this criteria then home directory is created. Otherwise no such file or directory is reported back to application.</para></note>
<note><para><literal>autohome</literal> does not deal with creating user accounts on local systems or in ldap or in any other database. It only deals with creating home directories once these accounts exist and imported to local system from databases like ldap, NIS.</para></note>
<important><para>It is worth mentioning one limitation with <literal>autohome</literal> module. It expects that user name and home directory are related to each other. For example, for user <literal>user1</literal> the home directory should be <filename>/home/user1</filename> or <filename>/some/directory/name/user1</filename> but not <filename>/some/directory/name/userhome1</filename>. This can be supported but it will be burden on system resources as each password entry has to be examined from first to last.</para></important>
<note><para>If the existing user password database is such that user home directories are distributed under different base directories, for example <filename>/home/class1/user1</filename>, <filename>/home/class2/user2332</filename>, then <literal>autohome</literal> configuration becomes complicated and it is not recommended.</para></note>
<sect2>
<title>Base directories for autohome</title>
<para>Next step in setup is to decide where will be <emphasis>virtual base directory</emphasis> and <emphasis>real base directory</emphasis> for home directory creation.</para>
<para>What is <emphasis>virtual base directory</emphasis> and what is <emphasis>real base directory</emphasis> in the context of <literal>autohome</literal> module?</para>
<para>It all depends on how user accounts are created. If an user account created for user name user1 with home directory <filename>/home/user1</filename> then <filename>/home</filename> <emphasis>will become Virtual Base Directory</emphasis>.</para>
<para>Then what is <emphasis>real base directory</emphasis>? It can be any directory. Only thing that has to be kept in mind is, there should be enough space as all actual files are stored here instead of in <emphasis>virtual base directory</emphasis>.</para>
<para>In most server configurations <filename>/home</filename> is a separate partition mounted on it. But if <filename>/home</filename> is made <emphasis>virtual base directory</emphasis> files are not stored in that directory! The solution is, do not mount partition on <filename>/home</filename> but instead mount it under somewhere else and make it <emphasis>real base directory</emphasis>.</para>
<para><emphasis role="bold">Autodir</emphasis> option <literal>-d</literal> is used to specify <emphasis>virtual base directory</emphasis>. For example <literal>autodir -d /home</literal> assuming <filename>/home</filename> is <emphasis>virtual base directory</emphasis>.</para>
<para>It is little tricky to specify <emphasis>real base directory</emphasis>. <emphasis>real base directory</emphasis> is managed by <literal>autohome</literal> module so this option must be passed to the module through module suboptions. If the <emphasis>real base directory</emphasis> is <filename>/var/autohome</filename> then it is specified with option <literal>-o</literal> as <literal>-o realpath=/var/autohome</literal>.</para>
</sect2>
<sect2>
<title>Directory organization</title>
<para>Please refer to <link linkend="dirorg">directory organization under real base directory</link> for detailed explanation of this topic.</para>
<para><literal>autohome</literal> does support this kind of organization. The suboption used to specify directory organization desired, is with <literal>level</literal> suboption. For example, <literal>-o level=2</literal>.</para>
</sect2>
<sect2>
<title>Misc suboptions for autohome</title>
<para>Suboption <literal>skel</literal> can be used if skeleton path is not default value <filename>/etc/skel</filename> like <literal> -o skel=/some/other/dir</literal>.</para>
<para>Suboption <literal>noskel</literal> can be used with <literal>-o</literal> to indicate not to copy skeleton files to home directories when created.</para>
</sect2>
<sect2>
<title>Summing up with an example</title>
<para>First, import user accounts from centralized database like, for example, ldap.</para>
<para>Next, <literal>autofs</literal> module must be loaded. This can be done as described in <link linkend="autofs_kmod">autofs kernel module section</link>.</para>
<para>If <filename>/home</filename> is to be used for home directories then <filename>/home</filename> will become <emphasis>virtual directory</emphasis> and specified to <command>autodir</command> with <literal>-d /home</literal> option.</para>
<para>Assuming <literal>autohome</literal> module is located at <filename>/usr/lib/autodir/autohome.so</filename>, this module can be loaded with <command>autodir</command> as <literal>-m /usr/lib/autodir/autohome.so</literal>. Note that full path for module is given.</para>
<para>Where actually real home directories reside is given with <literal>realpath</literal> suboption. If it is <filename>/autohome</filename>, it can be given as <literal>realpath=/autohome</literal>.</para>
<para>With all these options <command>autodir</command> can be started as,</para>
<screen>
# autodir -d /home \
-m /usr/lib/autodir/autohome.so \
-o 'realpath=/autohome' \
</screen>
<para>Once <emphasis role="bold">Autodir</emphasis> is started, <filename>/home</filename> directory will be blank in the beginning. Whether <emphasis role="bold">Autodir</emphasis> working properly or not can be tested by changing directory to one of the home directories as root user or as the owner of the home directory.</para>
</sect2>
</sect1>
<sect1>
<title>Managing group directories</title>
<para><literal>autogroup</literal> module is for creating directories on demand for common group access. It can be used with Samba, for example, to dynamically create shared directories for group of people.</para>
<note><para><literal>autogroup</literal> module check for requested directory with valid groups from system group database.</para></note>
<tip><para><literal>autogroup</literal> can be used to create home directories as well! Provided that there exists user private group for each user. This way all group and home directories can be created at one place with one module. But no skeleton files are copied and the <literal>autogroup</literal> suboption <literal>nopriv</literal> should not be used.</para></tip>
<para><literal>autogroup</literal> configuration is same as <literal>autohome</literal> module but unlike <literal>autohome</literal>, <emphasis>virtual base directory</emphasis> can be placed anywhere and any name can be given to it. It is not dictated by system accounts.</para>
<para>The module <literal>autogroup</literal> can be used with <emphasis role="bold">Autodir</emphasis> using option <literal>-m</literal>. For example, <literal>-m /usr/lib/autodir/autogroup.so</literal>.</para>
<para>All suboptions explained in <link linkend="homedir">managing home directories</link> are same for <literal>autogroup</literal> except <literal>skel</literal>, <literal>noskel</literal> as these are meaningless for <literal>autogroup</literal> module. But there are two other suboptions specific for <literal>autogroup</literal>. These are given below.</para>
<variablelist>
<varlistentry><term><literal>nopriv</literal></term><listitem><para>Some Linux installations use user private groups. If directories for these groups are not to be created, then use this suboption.</para></listitem></varlistentry>
<varlistentry><term><literal>nosetgid</literal></term><listitem><para>By default setgid is set on group directories created. Use this suboption to disable this feature.</para></listitem></varlistentry>
</variablelist>
</sect1>
<sect1 id="aoptions">
<title>Autodir options</title>
<para>In this section some of the options to <emphasis role="bold">Autodir</emphasis> are explained. Backup options are explained in <link linkend="backupopts">backup section</link>.</para>
<variablelist>
<varlistentry><term><literal>-d</literal></term><listitem><para>For specifying <emphasis>virtual base directory</emphasis>. If this path does not exist, it will be created. Absolute path is expected for this option.</para></listitem></varlistentry>
<varlistentry><term id="autodir_t_opt"><literal>-t</literal></term><listitem><para>Expiration timeout for <emphasis>virtual directories</emphasis>. For more details refer to <link linkend="vdexp">virtual directory expiration</link>.</para></listitem></varlistentry>
<varlistentry><term><literal>-m</literal></term><listitem><para>Module to be used with <emphasis role="bold">Autodir</emphasis>. Currently <literal>autohome</literal> and <literal>autogroup</literal> are available. Full path to the module expected.</para></listitem></varlistentry>
<varlistentry><term><literal>-o</literal></term><listitem><para>All options that are to be passed to module are given here. This option passing syntax is similar to <command>mount</command> command with its <literal>-o</literal> option. See specific module sections for more info.</para></listitem></varlistentry>
<varlistentry><term><literal>-f</literal></term><listitem><para>Stay foreground and log all messages to the console. For debugging purpose and to see how <emphasis role="bold">Autodir</emphasis> works.</para></listitem></varlistentry>
<varlistentry><term><literal>-l</literal></term><listitem><para>This option expects path name to filename to which <emphasis role="bold">Autodir</emphasis> will write its process id.</para></listitem></varlistentry>
<varlistentry><term><literal>-h</literal></term><listitem><para>Help about all options supported.</para></listitem></varlistentry>
<varlistentry><term><literal>-v</literal></term><listitem><para>Version information about <emphasis role="bold">Autodir</emphasis>.</para></listitem></varlistentry>
</variablelist>
</sect1>
<sect1 id="backupopts">
<title>Backup options</title>
<para>These options are passed to <emphasis role="bold">Autodir</emphasis> to request backup services.</para>
<variablelist>
<varlistentry><term><literal>-b</literal></term><listitem><para>This is the main option to specify backup program path and arguments to it. The path given should be absolute path otherwise <emphasis role="bold">Autodir</emphasis> does not accept it.</para></listitem></varlistentry>
<varlistentry><term id="autodir_w_opt"><literal>-w</literal></term><listitem><para>Whenever a <emphasis>virtual directory</emphasis> is not used for a period of time, it is assumed inactive and it is unmounted. After unmounting directory, whether to launch backup immediately or to wait some more time is decided with this option. It takes arguments in seconds. It is the <emphasis>minimum</emphasis> time to wait before starting backup after <emphasis>virtual directory</emphasis> expiration. It should not exceed more then one day.</para></listitem></varlistentry>
<varlistentry><term><literal>-p</literal></term><listitem><para>This is the priority to be given to backup process. <emphasis>This is in the range of 1 to 40 inclusive</emphasis>. Lower value mean higher priority and vice versa. Default value is 30.</para></listitem></varlistentry>
<varlistentry><term><literal>-c</literal></term><listitem><para>This restricts maximum number of backup process at any given time. Default is 150.</para></listitem></varlistentry>
</variablelist>
<caution>Argument for <literal>-b</literal> is inclusive of absolute backup program path as well as its own arguments. Therefore it is recommended to use single quotes around this argument</caution>
<para>Option <literal>-b</literal> takes path to executable file as well as arguments to it. But the arguments to it are interpreted for %x character sequences and replaced with predefined strings as follows.</para>
<variablelist>
<varlistentry><term><literal>%N</literal></term><listitem><para>Replaced with <emphasis>virtual directory</emphasis> name.</para></listitem></varlistentry>
<varlistentry id="back_esc_str"><term><literal>%L</literal></term><listitem><para>Replaced with absolute path to <emphasis>real directory</emphasis>.</para></listitem></varlistentry>
<varlistentry><term><literal>%K</literal></term><listitem><para>Replaced with host name.</para></listitem></varlistentry>
<varlistentry><term>Others</term><listitem><para>Others are fed to <literal>strftime</literal>. See man page for <literal>strftime</literal> for more information.</para></listitem></varlistentry>
</variablelist>
</sect1>
<sect1>
<title>Examples</title>
<screen>
# autodir -d /home \
-m /usr/lib/autodir/autohome.so \
-t 1 \
-f \
-o 'realpath=/autohome,level=1,skel=/etc/skel' \
-l /var/lock/autodir
</screen>
<screen>
# autodir -d /home \
-m /usr/lib/autodir/autohome.so \
-t 300 \
-b '/bin/tar cf /tmp/%N%F.tar %L' \
-w 600 \
-o 'realpath=/tmp/autohome,level=2,noskel' \
-l /var/lock/autodir
</screen>
<screen>
# autodir -d /var/abase/ \
-m /usr/lib/autodir/autogroup.so \
-t 300 \
-b '/bin/tar cf /tmp/%N%F.tar %L' \
-w 86400 \
-o 'nopriv,nosetgid,realpath=/var/realbase,level=0'
</screen>
</sect1>
<sect1>
<title>RPM specific</title>
<para><emphasis role="bold">Autodir</emphasis> can be installed from rpms as,</para>
<screen>
# rpm -ivh autodir-0.28-4.i386.rpm
</screen>
<para>When installed from rpms, two startup scripts are provided namely <filename>/etc/rc.d/init.d/autohome</filename> and <filename>/etc/rc.d/init.d/autogroup</filename>. One for starting <emphasis role="bold">Autodir</emphasis> with <literal>autohome</literal> module and another for starting with <literal>autogroup</literal> module.</para>
<para>Script configuration files <filename>/etc/sysconfig/autohome</filename>, <filename>/etc/sysconfig/autogroup</filename> can be used to specify what options can be passed to <emphasis role="bold">Autodir</emphasis>.</para>
</sect1>
<sect1 id="moreinfo">
<title>Further Information</title>
<para><emphasis role="bold">Mailing list for autodir </emphasis><ulink url="http://lists.sourceforge.net/mailman/listinfo/intraperson-autodir">http://lists.sourceforge.net/mailman/listinfo/intraperson-autodir</ulink>.</para>
<para>Official website is at <ulink url="http://www.intraperson.com/autodir/">http://www.intraperson.com/autodir/</ulink>.</para>
<para>Autofs mailing list <ulink url="http://linux.kernel.org/mailman/listinfo/autofs">http://linux.kernel.org/mailman/listinfo/autofs</ulink>.</para>
<para>Automount HOWTO can be found at <ulink url="http://www.tldp.org">http://www.tldp.org</ulink></para>
<para>Autofs Hacking <ulink url="http://www.goop.org/~jeremy/autofs/">http://www.goop.org/~jeremy/autofs</ulink>.</para>
</sect1>
</article>