Back to the main page
Script for creating ClearCase layout
I do not work with ClearCase but support operational environment for them.
I use ZFS for both data and as boot file system, so after system is installed I setup ZFS datasets and hand over to ClearCase people to install applications, etc.
To speed up dataset creation process, here is configuration file and shell script (that reads the config file) .
# zfs create -p -o mountpoint=/vobadm -o quota=5G -o compression=on -o sharenfs=off space1/primary/cc-pri/vobadm
# chown vobadm:ccusers /vobadm
# /usr/local/bin/chmod 0755 /vobadm
# ==========================================================================================================
# Name Pool* Gparent Parent Mountpoint Quota* Owner Perm NFS Compression
# ==========================================================================================================
# cc-pri (primary storage)
# -----------------------------------------------------------------------------------------------------------
var_adm_rational space1 primary cc-pri /var/adm/rational 1 root:other 0755 off on
vobstore space1 primary cc-pri /vobstore 400 vobadm:ccusers 2750 rw=usershosts off
viewstore space1 primary cc-pri /viewstore 20 vobadm:ccusers 2770 rw=usershosts off
vobadm space1 primary cc-pri /vobadm 5 vobadm:ccusers 0755 off on
# -----------------------------------------------------------------------------------------------------------
# cc-sec (secondary storage)
# ----------------------------------------------------------------------------------------------------------
buildstore space1 primary cc-sec /buildstore 20 vobadm:ccusers 2770 rw=usershosts on
ccase_rls space1 primary cc-sec /ccase_rls 20 vobadm:ccusers 0755 ro on
# -----------------------------------------------------------------------------------------------------------
# cc-alt (alternative separate storage for shipping)
# ------------------------------------------------------------------------------------------------------------
shipping space1 primary cc-alt /shipping 20 vobadm:ccusers 0555 off on
|
Basically, the awk reads config file, remove blank lines and comments, and create new temp file with 'zfs create' commands.
The new temp file is also shell script that created datasets, etc.
#!/bin/sh
#set -x
awk_utility=/usr/bin/awk
input_file=cc-init.conf
output_script=create_cc_layout.sh
err() {
echo "\n ERROR: $* \n"
exit 1
}
tmp_file_cleaning() {
[ -f ${output_script} ] && rm ${output_script}
[ -f /tmp/tmpfile ] && rm /tmp/tmpfile
}
# cleaning in case of script termination and regular exit
trap tmp_file_cleaning HUP INT QUIT ABRT EXIT
# check is system is NIS client
ypwhich >/dev/null || err "System is not NIS client"
domain=`domainname`
[ -z "${domain}" ] && err "NIS domain is not setup"
[ "${domain}" != mycompany.com ] && err "NIS domain is not mycompany.com"
umask 022
echo "#!/bin/sh \n#set -x" > ${output_script}
# awk starts processing
${awk_utility} '\
BEGIN {print "... Processing input file "}
{
if (NF > 0 && $1 !~ /^#/) #delete blank lines and comments
print "# " $5 "\n" \
"echo Creating dataset : " $1 "\n" \
"zfs create -p -o mountpoint="\
$5 \
" -o quota="\
$6\
"G -o compression="\
$10 \
" -o sharenfs="\
$9 " " \
$2"/"$3"/"$4"/"$1 \
"\n" \
"echo Changing ownership for " $1 "\n" \
"chown " $7 " " $5 \
"\n" \
"echo Changing permissions for " $1 "\n" \
"/usr/local/bin/chmod " $8 " " $5 "\n" \
"echo ... ... ... \n" \
>> "create_cc_layout.sh"
}
END {print "... The End of awk"}
' \
${input_file}
${awk_utility} '\
{
if (NF > 0 && $1 !~ /^#/) #delete blank lines and comments
print $2, $3 >> "/tmp/tmpfile"
}
' \
${input_file}
to_be_unmount=`cat /tmp/tmpfile | sort | uniq | ${awk_utility} '{print $1"/"$2}'`
for dataset in ${to_be_unmount}
do
echo "echo un-mounting ${dataset}" >> ${output_script}
echo zfs set mountpoint=none ${dataset} >> ${output_script}
done
echo "exit 0" >> ${output_script}
echo "Executing ${output_script} ... \n" ; sh ${output_script} || err "Cannot execute ${output_script}"
exit 0
|
And script does something like:
... Processing input file
... The End of awk
Executing create_cc_layout.sh ...
Creating dataset : var_adm_rational
Changing ownership for var_adm_rational
Changing permissions for var_adm_rational
... ... ...
Creating dataset : vobstore
Changing ownership for vobstore
Changing permissions for vobstore
... ... ...
Creating dataset : viewstore
Changing ownership for viewstore
Changing permissions for viewstore
... ... ...
Creating dataset : vobadm
Changing ownership for vobadm
Changing permissions for vobadm
... ... ...
Creating dataset : buildstore
Changing ownership for buildstore
Changing permissions for buildstore
... ... ...
Creating dataset : ccase_rls
Changing ownership for ccase_rls
Changing permissions for ccase_rls
... ... ...
Creating dataset : shipping
Changing ownership for shipping
Changing permissions for shipping
... ... ...
un-mounting space1/primary
|
Back to the main page