summaryrefslogtreecommitdiffstats
path: root/os-plugins/plugins/vmgrid/XX_vmgrid.sh
blob: 16f5fbd1d510b3f6e9abf1c322b0a5d1c6d65c8e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# Copyright (c) 2010 - RZ Uni Freiburg
# Copyright (c) 2010 - OpenSLX GmbH
#
# This program/file is free software distributed under the GPL version 2.
# See http://openslx.org/COPYING
#
# If you have any feedback please consult http://openslx.org/feedback and
# send your feedback to feedback@openslx.org
#
# General information about OpenSLX can be found at http://openslx.org
#
# script is included from init via the "." load function - thus it has all
# variables and functions available

# include default directories
. /etc/openslx.conf

CONFFILE="/initramfs/plugin-conf/vmgrid.conf"
PLUGINCONFDIR=/mnt/${OPENSLX_DEFAULT_CONFDIR}/plugins/vmgrid
VIRTUALIZATIONPLUGIN=/mnt/${OPENSLX_DEFAULT_CONFDIR}/plugins/virtualization
#RWSHARE=/mnt/${OPENSLX_DEFAULT_VARDIR}/plugins/vmgrid/share
RWSHARE=/mnt/var/opt/openslx/plugins/vmgrid/share
RWSHAREMNT=/mnt/var/opt/openslx/mnt/vmgrid
BINDIR=/mnt/${OPENSLX_DEFAULT_BINDIR}
PLUGINDIR=${OPENSLX_DEFAULT_DIR}/plugin-repo/vmgrid
VIRTDIR=/mnt/${OPENSLX_DEFAULT_VIRTDIR}/vmgrid

if [ -f $CONFFILE ]; then

  # load needed variables
  . $CONFFILE

  if [ ${vmgrid_active} -ne 0 ] ; then
    [ ${DEBUGLEVEL} -gt 0 ] && echo "executing the 'vmgrid' os-plugin ..."

    # load general configuration
    . /etc/initramfs-setup
    # include functions
    . /etc/functions

    testmkd ${PLUGINCONFDIR}
    testmkd ${VIRTDIR}
    cp $CONFFILE ${PLUGINCONFDIR}/vmgrid.conf
    # create link to binpath
    ln -fs ${PLUGINDIR}/vmgrid ${BINDIR}/vmgrid
    ln -fs ${PLUGINDIR}/run-vmgrid.sh ${BINDIR}/run-vmgrid.sh

    # mount nfs virt ro share
    if strinstr "nfs://" "${vmgrid_roshare}"; then
      virtsrcprot=$(uri_token ${vmgrid_roshare} prot)
      virtsrcserv=$(uri_token ${vmgrid_roshare} server)
      virtsrcpath="$(uri_token ${vmgrid_roshare} path)"
      if [ -n "${virtsrcprot}" -a -n "${virtsrcserv}" -a -n "${virtsrcpath}" ];
        then
        virtsrctarget=${VIRTDIR}
        # mount the vmgrid source ro
        fsmount ${virtsrcprot} ${virtsrcserv} ${virtsrcpath} ${virtsrctarget} \
          ro
      fi
    fi

    # create rw share
    testmkd ${RWSHARE}
    # bind mount id 45 to ${RWSHARE}
    if strinstr "id45" "${vmgrid_rwshare}" ; then
      id45part=$(grep " 45 " /etc/disk.partition | awk '{print $1}' | \
        cut -f 3,3 -d /)
      if [ -n "${id45part}" ]; then
        testmkd /mnt/media/${id45part}/vmgrid
        mount --bind -n /mnt/media/${id45part}/vmgrid ${RWSHARE} \
          >>/tmp/vmgrid.log 2>&1
      fi
    # mount nfs rw share
    elif strinstr "nfs://" "${vmgrid_rwshare}" ; then
      rwshareprot=$(uri_token ${vmgrid_rwshare} prot)
      rwshareserv=$(uri_token ${vmgrid_rwshare} server)
      rwsharepath="$(uri_token ${vmgrid_rwshare} path)"
      if [ -n "${rwshareprot}" -a -n "${rwshareserv}" -a -n "${rwsharepath}" ];
      then
        # mount to a dir fist to create spec host dir, then bind mount
        testmkd ${RWSHAREMNT}
        rwtarget=${RWSHAREMNT}
        # mount the vmgrid source rw
        fsmount ${rwshareprot} ${rwshareserv} ${rwsharepath} ${rwtarget} rw
        # hostname?
        host_name=${host_name:=$clientip}
        testmkd ${RWSHAREMNT}/${host_name}
        mount --bind ${RWSHAREMNT}/${host_name} ${RWSHARE} \
          >>/tmp/vmgrid.log 2>&1
      fi
    else
      testmkd /mnt/tmp/vmgrid
      mount --bind -n /mnt/tmp/vmgrid ${RWSHARE} >>/tmp/vmgrid.log 2>&1
    fi
    # chmod so that everybody can write
    chmod 1777 ${RWSHARE}
    echo "vmgrid_rwmnt=${RWSHARE#/mnt}" >> ${PLUGINCONFDIR}/vmgrid.conf

    # finished ...
    [ $DEBUGLEVEL -gt 0 ] && echo "done with 'vmgrid' os-plugin ..."
  fi
else
  [ $DEBUGLEVEL -gt 0 ] && echo "  * configuration of 'vmgrid' os-plugin failed"
fi