On Wed, 2011-02-16 at 17:55 -0500, William L. Thomson Jr. wrote:
>
> Therefore I think a better approach is to script it, make an init
> script, with both start/mount and stop/unmount. Maybe even a config file
> in Gentoo's /etc/conf.d/diskless to contain a variable for the amount of
> diskless systems. Otherwise can hard code that into the init script, but
> probably not the best approach.

Ah yes much better :)

Still a work in process, need to adapt it so like the two examples below
could be on the same system. Heres a sample

cat /etc/conf.d/disklessmount
# Config file for local bind mounts for diskless systems
# Requires an additional file, make sure to edit disklessmounts

# Number of diskless systems
DS_COUNT=200

# Host name/loop Starting point, usually 0 or 1
DS_START=1

/etc/conf.d/disklessmounts
# Array to hold mount points and options similar format to fstab
# Use the variable ${DSN} for the diskless system # where necessary
# <fs>  <mountpoint>    <type>  <opts>

DS_MOUNTS=(
"/xen/common"                           "/xen/node${DSN}/export"                
        "none"  "rw,bind"
"/xen/node${DSN}/local/etc/xen/auto"    "/xen/node${DSN}/export/etc/xen/auto"   
        "none"  "rw,bind"
"/xen/node${DSN}/local/var/log"         "/xen/node${DSN}/export/var/log"        
        "none"  "rw,bind"
"/etc/xen/configs"                      
"/xen/node${DSN}/export/etc/xen/configs"        "none"  "rw,bind"
"/vms/base/boot"                        "/xen/node${DSN}/export/vms/base/boot"  
        "none"  "rw,bind"
"/usr/portage"                          "/xen/node${DSN}/export/usr/portage"    
        "none"  "rw,bind"
"/tmp/hosts/node${DSN}"                 "/xen/node${DSN}/export/tmp"            
        "tmpfs" "rw,bind"
)

Or if doing workstations vs xen host nodes

/etc/conf.d/disklessmounts 
# Array to hold mount points and options similar format to fstab
# Use the variable ${DSN} for the diskless system # where necessary
# <fs>  <mountpoint>    <type>  <opts>

DS_MOUNTS=(
"/ws/common"                    "/ws/ws${DSN}/export"                   "none"  
"rw,bind"
"/ws/ws${DSN}/local/var/log"    "/ws/ws${DSN}/export/var/log"           "none"  
"rw,bind"
"/usr/portage"                  "/ws/ws${DSN}/export/usr/portage"       "none"  
"rw,bind"
"/tmp/hosts/ws${DSN}"           "/ws/ws${DSN}/export/tmp"               "tmpfs" 
"rw,bind"
)

And now for the beef :)

/etc/init.d/disklessmount 
#!/sbin/runscript

description="Mounts local bind mounts for diskless systems from conf.d file"

depend() {
        after localmount
        before *
}

start() {
        ebegin "Mounting remote diskless system local bind mounts"
        for (( DSN=${DS_START}; DSN<${DS_COUNT}; DSN++ )); do
                source /etc/conf.d/disklessmounts
                for (( i=0; i<${#DS_MOUNTS[@]}; i=$((${i}+4)) )); do
                        fs=${DS_MOUNTS[${i}]} # local storage easier for reuse
                        [ "${fs:0:11}" = "/tmp/hosts/" -a ! -d ${fs} ] &&
                                mkdir -p ${fs}
                        mount -t ${DS_MOUNTS[$((${i}+2))]} \
                                -o ${DS_MOUNTS[$((${i}+3))]} \
                                ${fs} ${DS_MOUNTS[$((${i}+1))]}
                done
        done
        eend $?
        return 0
}

stop() {
        ebegin "Unmounting remote diskless system local bind mounts"
        for (( DSN=${DS_START}; DSN<${DS_COUNT}; DSN++ )); do
                source /etc/conf.d/disklessmounts
                for (( i=${#DS_MOUNTS[@]}; i>=0; i=$((${i}-4)) )); do
                        [ -n "${DS_MOUNTS[$((${i}+1))]}" ] &&
                                umount ${DS_MOUNTS[$((${i}+1))]}
                done
        done
        eend $?
        return 0
}


Note the reverse order of unmount in the stop. Loop starts with an empty
part of the array for some reason, thus the if statement.

Also would be nice to not have to keep sourcing the file or have two
conf.d files. But that seemed to be the only way to get variables in the
array to have values, the host/node number.

Much more to come, till then enjoy! :)

-- 
William L. Thomson Jr.
Obsidian-Studios, Inc.
http://www.obsidian-studios.com


---------------------------------------------------------------------
Archive      http://marc.info/?l=jaxlug-list&r=1&w=2
RSS Feed     http://www.mail-archive.com/[email protected]/maillist.xml
Unsubscribe  [email protected]

Reply via email to