#!/bin/bash # # Copyrights : CNRS # Author : Oleg Lodygensky # Acknowledgment : XtremWeb-HEP is based on XtremWeb 1.8.0 by inria : http://www.xtremweb.net/ # Web : http://www.xtremweb-hep.org # # This file is part of XtremWeb-HEP. # # XtremWeb-HEP is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # XtremWeb-HEP is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with XtremWeb-HEP. If not, see . # # # ****************************************************************** # File : xwcontext_prologue # Date : August 31st, 2012 # Author : Oleg Lodygensky # # OS : Linux # Arch : noarch # # Purpose : this brings up/down contextualization # contextualization disk is mounted on /mnt/xwcontext # this is HEPiX compliant contextualisation epilog # this is based on http://grid.desy.de/vm/hepix/vwg/doc/html/start/contextualisation-principles-cern-status.shtml # # Changelog: # $Log: vmcontext,v $ # Revision 0.1 2012/08/30 Oleg Lodygensky # Initial version # # chkconfig: 2345 2 99 # description: XWHEP contextualization prolog LOGFILE=/var/log/xwcontext_prologue.log start() { touch $LOGFILE echo -n $"XWHEP contextualization prolog: " /usr/sbin/groupadd -f vmuser >> $LOGFILE 2>&1 /usr/sbin/adduser -d /home/vmuser -g vmuser -m -s /bin/bash vmuser >> $LOGFILE 2>&1 # # randomize passwords # dd if=/dev/urandom count=50|md5sum|passwd --stdin vmuser >> $LOGFILE 2>&1 dd if=/dev/urandom count=50|md5sum|passwd --stdin root >> $LOGFILE 2>&1 # # mount xwscratch # if [ -b /dev/sdb ] ; then /bin/mkdir -p /mnt/xwscratch >> $LOGFILE 2>&1 /bin/mount /dev/sdb /mnt/xwscratch >> $LOGFILE 2>&1 if [ $? -ne 0 ] ; then if [ ! -b /dev/sdb1 ] ; then /sbin/fdisk /dev/sdb << FDISKEOF n p 1 w FDISKEOF /sbin/mkfs.ext3 /dev/sdb1 >> $LOGFILE 2>&1 fi /bin/mount /dev/sdb1 /mnt/xwscratch >> $LOGFILE 2>&1 RETVAL=$? fi elif [ -b /dev/hdd ] ; then /bin/mkdir -p /mnt/xwscratch >> $LOGFILE 2>&1 /bin/mount /dev/hdd /mnt/xwscratch >> $LOGFILE 2>&1 if [ $? -ne 0 ] ; then if [ ! -b /dev/hdd1 ] ; then /sbin/fdisk /dev/hdd << FDISKEOF n p 1 w FDISKEOF /sbin/mkfs.ext3 /dev/hdd1 >> $LOGFILE 2>&1 fi /bin/mount /dev/hdd1 /mnt/xwscratch >> $LOGFILE 2>&1 RETVAL=$? fi fi /bin/chown -R vmuser:vmuser /mnt/xwscratch >> $LOGFILE 2>&1 # # configure iptables # if [ -f /root/iptables_rules.sh ] ; then chmod +x /root/iptables_rules.sh >> $LOGFILE 2>&1 /root/iptables_rules.sh >> $LOGFILE 2>&1 RETVAL=$? else echo "No iptables rules : LAN access allowed" >> $LOGFILE 2>&1 fi # # start XWHEP server, if installed # [ -x /etc/init.d/xtremweb.server ] && /etc/init.d/xtremweb.server restart >> $LOGFILE 2>&1 # # start XWHEP worker, if installed # [ -x /etc/init.d/xtremweb.worker ] && /etc/init.d/xtremweb.worker restart >> $LOGFILE 2>&1 if [ -e /dev/xvdb ] ; then disk="/dev/xvdb" elif [ -e /dev/vdb ] ; then disk="/dev/vdb" elif [ -e /dev/hdb ]; then disk="/dev/hdb" if [ -e /dev/hdb1 ]; then disk="/dev/hdb1" fi elif [ -e /dev/sda ]; then disk="/dev/sda" if [ -e /dev/sda1 ]; then disk="/dev/sda1" fi else echo "No context disk found." >> $LOGFILE 2>&1 echo [ OK ] return 0; fi echo "Trying to mount context disk $disk" >> $LOGFILE 2>&1 # mount -t iso9660 $disk /mnt/xwcontext mkdir -p /mnt/xwcontext >> $LOGFILE 2>&1 mount $disk /mnt/xwcontext >> $LOGFILE 2>&1 RETVAL=$? if [ 0 -eq $RETVAL ] ; then if [ -e /mnt/xwcontext/prolog.sh ]; then # . /mnt/xwcontext/prolog.sh # # In XWHEP, users are not allowed to run as root # We solve this, by the appropriate /etc/suders # echo "Found /mnt/xwcontext/prolog.sh" >> $LOGFILE 2>&1 chmod +x /mnt/xwcontext/prolog.sh >> $LOGFILE 2>&1 /bin/su -l vmuser bash -c /mnt/xwcontext/prolog.sh >> $LOGFILE 2>&1 RETVAL=$? else # . /mnt/xwcontext/init.sh # # In XWHEP, users are not allowed to run as root # We solve this, by the appropriate /etc/suders # if [ -e /mnt/xwcontext/init.sh ]; then echo "Found /mnt/xwcontext/init.sh" >> $LOGFILE 2>&1 chmod +x /mnt/xwcontext/init.sh >> $LOGFILE 2>&1 /bin/su -l vmuser bash -c /mnt/xwcontext/init.sh >> $LOGFILE 2>&1 RETVAL=$? else echo "No contextualization prolog found" >> $LOGFILE 2>&1 RETVAL=0 fi fi fi if [ 0 -eq $RETVAL ]; then echo "[ OK ]" else echo "[ FAILED ]" fi echo "RETVAL=$RETVAL" >> $LOGFILE 2>&1 return $RETVAL } stop() { echo "xwcontext_prologue does nothing" return 0 } case "$1" in start) # [ $running -eq 0 ] && exit 0 start RETVAL=$? ;; stop) # [ $running -eq 0 ] || exit 0 stop RETVAL=$? ;; status) echo "This does nothing" RETVAL=0 ;; *) echo $"Usage: $0 {start|stop}" RETVAL=2 esac exit $RETVAL