Merge pull request #284 from zhongyehong/master
fix a bug of update base image
This commit is contained in:
commit
bb3412014f
|
@ -85,9 +85,11 @@ pre_start () {
|
|||
iptables -t nat -A POSTROUTING -s $CLUSTER_NET -j MASQUERADE
|
||||
|
||||
if [ ! -d $FS_PREFIX/local/basefs ]; then
|
||||
log_daemon_msg "create basefs ..."
|
||||
[ ! -f $tempdir/basefs.tar.bz ] && log_daemon_msg "$tempdir/basefs.tar.bz not exist, run prepare.sh first" && exit 1
|
||||
tar xvf $tempdir/basefs.tar.bz -C $FS_PREFIX/local > /dev/null
|
||||
log_daemon_msg "basefs does not exist, run prepare.sh first" && exit 1
|
||||
fi
|
||||
|
||||
if [ ! -d $FS_PREFIX/local/packagefs ]; then
|
||||
mkdir -p $FS_PREFIX/local/packagefs
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
23
prepare.sh
23
prepare.sh
|
@ -51,9 +51,20 @@ echo ""
|
|||
[[ -f web/templates/home.html ]] || { echo "Generating HomePage from home.template" && cp web/templates/home.template web/templates/home.html; }
|
||||
|
||||
mkdir -p /opt/docklet/global
|
||||
mkdir -p /opt/docklet/local
|
||||
mkdir -p /opt/docklet/local/
|
||||
|
||||
echo "directory /opt/docklet have been created"
|
||||
|
||||
if [ ! -d /opt/docklet/local/basefs ]; then
|
||||
mkdir -p /opt/docklet/local/basefs
|
||||
echo "Generating basefs"
|
||||
wget -P /opt/docklet/local http://iwork.pku.edu.cn:1616/basefs-0.11.tar.bz2 && tar xvf /opt/docklet/local/basefs-0.11.tar.bz2 -C /opt/docklet/local/ > /dev/null
|
||||
[ $? != "0" ] && echo "Generate basefs failed, please download it from http://unias.github.io/docklet/download to FS_PREFIX/local and then extract it using root. (defalut FS_PRERIX is /opt/docklet)"
|
||||
fi
|
||||
|
||||
echo "Some packagefs can be downloaded from http://unias.github.io/docklet.download"
|
||||
echo "you can download the packagefs and extract it to FS_PREFIX/local using root. (default FS_PREFIX is /opt/docklet"
|
||||
|
||||
echo ""
|
||||
echo "All preparation installations are done."
|
||||
echo "****************************************"
|
||||
|
@ -61,14 +72,6 @@ echo "* Please Read Lines Below Before Start *"
|
|||
echo "****************************************"
|
||||
echo ""
|
||||
|
||||
echo "Before staring : you need a basefs image. "
|
||||
echo "basefs images are provided at: "
|
||||
echo " http://unias.github.io/docklet/download"
|
||||
echo "please download it to FS_PREFIX/local and then extract it using root. (defalut FS_PRERIX is /opt/docklet)"
|
||||
echo "you will get a directory structure like"
|
||||
echo " /opt/docklet/local/basefs/etc "
|
||||
echo " /opt/docklet/local/basefs/bin "
|
||||
echo " /opt/docklet/local/basefs/..."
|
||||
echo "you may want to custom home page of docklet. Please modify web/templates/home.html"
|
||||
|
||||
echo "Next, make sure exim4 can deliver mail out. To enable, run:"
|
||||
|
@ -76,6 +79,4 @@ echo "dpkg-reconfigure exim4-config"
|
|||
echo "select internet site"
|
||||
|
||||
echo ""
|
||||
|
||||
|
||||
echo "Then start docklet as described in README.md"
|
||||
|
|
|
@ -154,7 +154,7 @@ class ImageMgr():
|
|||
#self.prepareImage(user,image,layer+"/overlay")
|
||||
self.prepareImage(user,image,layer)
|
||||
logger.info("image has been prepared")
|
||||
sys_run("mount -t aufs -o br=%s=rw:%s/local/basefs=ro+wh -o udba=reval none %s/" % (layer,self.NFS_PREFIX,rootfs),True)
|
||||
sys_run("mount -t aufs -o br=%s=rw:%s/local/packagefs=ro+wh:%s/local/basefs=ro+wh -o udba=reval none %s/" % (layer,self.NFS_PREFIX,self.NFS_PREFIX,rootfs),True)
|
||||
sys_run("mkdir -m 777 -p %s/local/temp/%s" % (self.NFS_PREFIX,lxc))
|
||||
|
||||
except Exception as e:
|
||||
|
@ -204,7 +204,7 @@ class ImageMgr():
|
|||
sys_run("mount /dev/%s/%s %s" % (vgname,lxc,layer))
|
||||
Ret = sys_run("mountpoint %s" % rootfs)
|
||||
if Ret.returncode != 0:
|
||||
sys_run("mount -t aufs -o br=%s=rw:%s/local/basefs=ro+wh -o udba=reval none %s/" % (layer,self.NFS_PREFIX,rootfs))
|
||||
sys_run("mount -t aufs -o br=%s=rw:%s/local/packagefs=ro+wh:%s/local/basefs=ro+wh -o udba=reval none %s/" % (layer,self.NFS_PREFIX,self.NFS_PREFIX,rootfs))
|
||||
return True
|
||||
|
||||
|
||||
|
@ -256,44 +256,10 @@ class ImageMgr():
|
|||
sys_run("rm -f %s" % public_imgpath+"."+image+".description", True)
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
"""
|
||||
def update_basefs(self,image):
|
||||
imgpath = self.imgpath + "private/root/"
|
||||
layer = self.NFS_PREFIX + "/local/volume/update_base"
|
||||
mountpoint = self.NFS_PREFIX + "/local/basefs_mp"
|
||||
tmpdir = self.NFS_PREFIX + "/local/basefs_tmp"
|
||||
olddir = self.NFS_PREFIX + "/local/basefs_old"
|
||||
try:
|
||||
logger.info("create directory %s, %s, %s" % (layer,mountpoint,tmpdir))
|
||||
sys_run("mkdir -p %s" % layer)
|
||||
sys_run("mkdir -p %s" % mountpoint)
|
||||
sys_run("mkdir -p %s" % tmpdir)
|
||||
logger.info("load image from %s" % imgpath+image)
|
||||
sys_run("rsync -a --delete --exclude=lost+found/ --exclude=root/nfs/ --exclude=dev/ --exclude=mnt/ --exclude=tmp/ --exclude=media/ --exclude=proc/ --exclude=sys/ %s/ %s/" % (imgpath+image,self.dealpath(layer)),True)
|
||||
logger.info("mount old base image and new image by aufs")
|
||||
sys_run("mount -t aufs -o br=%s=rw:%s/local/basefs=ro+wh -o udba=reval none %s/" % (layer,self.NFS_PREFIX,mountpoint),True)
|
||||
logger.info("save new image to %s" % tmpdir)
|
||||
sys_run("rsync -a --delete %s/ %s/" % (self.dealpath(mountpoint),self.dealpath(tmpdir)),True)
|
||||
logger.info("umount %s" % mountpoint)
|
||||
sys_run("umount %s" % mountpoint)
|
||||
logger.info("remove directory %s, %s" % (layer,mountpoint))
|
||||
sys_run("rm -rf %s/" % mountpoint)
|
||||
sys_run("rm -rf %s/" % layer)
|
||||
logger.info("move old base image to an tmp directory")
|
||||
sys_run("mv %s %s" % (self.NFS_PREFIX + "/local/basefs",olddir))
|
||||
logger.info("move new base image from %s to %s" % (tmpdir, self.NFS_PREFIX+"/local/basefs"))
|
||||
sys_run("mv %s %s" % (tmpdir, self.NFS_PREFIX+"/local/basefs"))
|
||||
logger.info("remove old base image")
|
||||
sys_run("rm -rf %s/" % olddir)
|
||||
logger.info("update base image success")
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
return True
|
||||
"""
|
||||
|
||||
def update_basefs(self,image):
|
||||
imgpath = self.imgpath + "private/root/"
|
||||
basefs = self.NFS_PREFIX+"/local/basefs/"
|
||||
basefs = self.NFS_PREFIX+"/local/packagefs/"
|
||||
tmppath = self.NFS_PREFIX + "/local/tmpimg/"
|
||||
tmpimage = str(random.randint(0,10000000))
|
||||
try:
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import json, sys, netifaces
|
||||
import json, sys, netifaces, threading
|
||||
from nettools import netcontrol,ovscontrol
|
||||
|
||||
from log import logger
|
||||
|
@ -386,9 +386,11 @@ class NetworkMgr(object):
|
|||
[status, userdata] = self.etcd.getkey("network/users/"+username)
|
||||
usercopy = json.loads(userdata)
|
||||
user = UserPool(copy = usercopy)
|
||||
logger.debug("load user into dict")
|
||||
self.users[username] = user
|
||||
|
||||
def dump_user(self, username):
|
||||
logger.debug("dump user into etcd")
|
||||
self.etcd.setkey("network/users/"+username, json.dumps({'info':self.users[username].info, 'gateway':self.users[username].gateway, 'pool':self.users[username].pool}))
|
||||
|
||||
def load_usrgw(self,username):
|
||||
|
@ -586,6 +588,7 @@ class NetworkMgr(object):
|
|||
result = self.users[username].acquire_cidr(num)
|
||||
self.dump_user(username)
|
||||
del self.users[username]
|
||||
|
||||
return result
|
||||
|
||||
# ip_or_ips : one IP address or a list of IPs
|
||||
|
|
|
@ -241,15 +241,15 @@
|
|||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
|
||||
<i class="fa fa-save modal-icon"></i>
|
||||
<h4 class="modal-title">Update Base Image</h4>
|
||||
<small class="font-bold">Update Base Image From Chosen Image</small>
|
||||
<h4 class="modal-title">Update Package Image</h4>
|
||||
<small class="font-bold">Update Package Image From Chosen Image</small>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<strong>Warning: This operation will update the base image. Maybe it will cause some error and then the base image will be destroyed. Please make sure you have the backup of base image.</strong>
|
||||
<strong>Warning: This operation will update the package image. Maybe it will cause some error and then the package image will be destroyed. Please make sure you have the backup of package image.</strong>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-white" data-dismiss="modal">Close</button>
|
||||
<a href="/image/updatebase/{{image['name']}}/"><button type="button" class="btn btn-success">Update</button></a>
|
||||
<a href="/image/0.0.0.0/updatebase/{{image['name']}}/"><button type="button" class="btn btn-success">Update</button></a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue