2 # copyright (C) 2013-2014 FUJITSU LIMITED All Rights Reserved
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; version 2
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 mkdir -p /etc/lxcf/rsc
27 chmod 755 /etc/lxcf/rsc
30 if [ ! -e /etc/lxcf/lxcf.conf ] ; then
31 cp -p /usr/lib/lxcf/lxcf.conf /etc/lxcf/lxcf.conf
34 # check default separate mdoel
35 /usr/lib/lxcf/lxcf-config
36 if [ -e /etc/lxcf/separate ] ; then
50 while getopts sjc:p: OPT
53 "s" ) FLG_S=1 ; VAL_SEPARATE="-s" ;;
54 "j" ) FLG_S=0 ; VAL_SEPARATE="-j" ;;
55 "c" ) FLG_C=1 ; JSONFILE=$OPTARG ;;
56 "p" ) FLG_P=1 ; FILEPATH=$OPTARG ;;
60 shift `expr $OPTIND - 1`
64 echo "usage lxcf sysgen [-s][-j][-c configfile] LXCNAME"
69 if [ ${FLG_C} -eq 1 ] ; then
70 /usr/lib/lxcf/lxcf-check-json ${JSONFILE}
71 if [ $? -ne 0 ] ; then
72 echo "error: illegal format json file :" ${JSONFILE}
78 if [ ${FLG_P} -eq 1 ] ; then
79 if [ ! -d $FILEPATH ] ; then
80 echo "error:" $FILEPATH "is not a directory"
83 if echo $FILEPATH | grep "^/opt/lxcf" ; then
84 echo "error:" $FILEPATH "overlaps with passing other containers. "
85 echo " " $FILEPATH "contains /opt/lxcf."
90 apath=`readlink -f $i`
91 if echo $FILEPATH | grep "^${apath}" ; then
92 echo "error:" $FILEPATH "overlaps with passing other containers. "
93 echo " " $FILEPATH "contains $apath."
99 # generate one container
103 VNAME=`virsh list --all | \
104 awk '{if ((NR > 2) && (NF == 3) && ($2 == "'${LXCNAME}'")) print $2}'`
105 if [ x${LXCNAME} == x${VNAME} ] ; then
106 echo "error: The same VM name already exists:" ${LXCNAME}
110 LNAME=`virsh -c lxc:/// list --all | \
111 awk '{if ((NR > 2) && (NF == 3) && ($2 == "'${LXCNAME}'")) print $2}'`
113 if [ x${LXCNAME} == x${LNAME} ] ; then
114 echo "error: The same LXC name already exists:" ${LXCNAME}
118 if ! /usr/lib/lxcf/lxcf-parmchk-cname $LXCNAME ; then
119 echo "error:" $LXCNAME "is not a container name"
123 PREFIX=/opt/lxcf/${LXCNAME}
126 if [ -e /${PREFIX} ] ; then
127 echo "error: There is already " ${LXCNAME}
131 echo "Generate" ${LXCNAME}
132 trap '/usr/lib/lxcf/lxcf-erase ${LXCNAME};exit 1' 2
134 # set symbolic link for -p option
135 if [ $FLG_P -eq 1 ] ; then
136 mkdir -p ${FILEPATH}/${LXCNAME}
137 ln -s ${FILEPATH}/${LXCNAME} ${PREFIX}
141 /usr/lib/lxcf/lxcf-createfile ${VAL_SEPARATE} ${LXCNAME}
142 /usr/lib/lxcf/lxcf-setup ${VAL_SEPARATE} ${LXCNAME}
143 /usr/lib/lxcf/lxcf-define ${LXCNAME}
145 # disable lxcf.service
146 rm /opt/lxcf/${LXCNAME}/etc/systemd/system/multi-user.target.wants/lxcf.service
148 # create an initial rsc file
149 /usr/lib/lxcf/lxcf-resource1 initrsc ${LXCNAME} > /etc/lxcf/rsc/${LXCNAME}/resource.val
151 /usr/lib/lxcf/lxcf-start ${LXCNAME}
153 # create known_hosts entry
154 sed -i "/^${LXCNAME}[ |,]/d" /root/.ssh/known_hosts
155 ssh-keyscan localhost |& egrep "ssh-rsa" >> /root/.ssh/known_hosts
156 LXCIPADR=`awk '{if ($2 == "'${LXCNAME}'") printf "%s",$1}' /etc/hosts`
157 sed -i "s/localhost/${LXCNAME},${LXCIPADR}/" /root/.ssh/known_hosts
160 if [ $FLG_C -eq 1 ] ; then
161 echo "load json file :" $JSONFILE
162 /usr/lib/lxcf/lxcf-load $LXCNAME $JSONFILE
164 #/usr/lib/lxcf/lxcf-resource show ${LXCNAME}
168 yum clean packages >& /dev/null &
169 yum clean all >& /dev/null &
172 if [ ! -e /etc/hosts ] ; then
173 echo "127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4" > /etc/hosts
174 echo "::1 localhost localhost.localdomain localhost6 localhost6.localdomain6" >> /etc/hosts
177 # generate containers of args