github.com/midokura/kubeedge@v1.2.0-mido.0/build/edge/run_daemon.sh (about) 1 #!/bin/bash 2 set -e 3 4 QEMU_VERSION="${QEMU_VERSION:-v3.0.0}" 5 6 main(){ 7 case $1 in 8 "prepare") 9 docker_prepare 10 ;; 11 "set") 12 docker_set $@ 13 ;; 14 "build") 15 docker_build 16 ;; 17 "save") 18 docker_save 19 ;; 20 "up") 21 docker_up 22 ;; 23 "down") 24 docker_down 25 ;; 26 "only_run_edge") 27 docker_only_run_edge $@ 28 ;; 29 *) 30 usage 31 exit 1 32 ;; 33 esac 34 } 35 36 usage() { 37 echo "Usage:" 38 echo "$0 prepare | set | build | save | up | down " 39 } 40 41 docker_prepare(){ 42 if [ ! -d /etc/kubeedge/certs ] || [ ! -e /etc/kubeedge/certs/edge.crt ] || [ ! -e /etc/kubeedge/certs/edge.key ]; then 43 mkdir -p /etc/kubeedge/certs 44 echo "Certificate does not exist" 45 exit -1 46 fi 47 48 if [ ! -d /var/lib/kubeedge ]; then 49 mkdir -p /var/lib/kubeedge 50 fi 51 52 if [ ! -d /var/lib/edged ]; then 53 mkdir -p /var/lib/edged 54 fi 55 56 if [ ! -S /var/run/docker.sock ]; then 57 echo "docker engine not found" 58 exit -1 59 fi 60 61 eval $(sed -n '/CERTPATH/p' .env) 62 eval $(sed -n '/CERTFILE/p' .env) 63 eval $(sed -n '/KEYFILE/p' .env) 64 if [ ! -d ${CERTPATH} ] || [ ! -e ${CERTFILE} ] || [ ! -e ${KEYFILE} ]; then 65 mkdir -p ${CERTPATH} 66 echo "Certificate does not exist" 67 exit -1 68 fi 69 70 if [[ -z $(which docker-compose) ]]; then 71 curl -L "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose 72 chmod +x /usr/local/bin/docker-compose 73 fi 74 echo "Container runtime environment check passed." 75 } 76 77 docker_set(){ 78 # This script accepts the following parameters: 79 # 80 # * cloudhub 81 # * edgename 82 # * edgecore_image 83 # * arch 84 # * qemu_arch 85 # * certpath 86 # * certfile 87 # * keyfile 88 # 89 # Example 90 # 91 # ./run_daemon.sh set \ 92 # cloudhub=0.0.0.0:10000 \ 93 # edgename=edge-node \ 94 # edgecore_image="kubeedge/edgecore:latest" \ 95 # arch=amd64 \ 96 # qemu_arch=x86_64 \ 97 # certpath=/etc/kubeedge/certs \ 98 # certfile=/etc/kubeedge/certs/edge.crt \ 99 # keyfile=/etc/kubeedge/certs/edge.key 100 101 ARGS=$@ 102 103 CONFIG=${ARGS#* } 104 105 for line in $CONFIG; do 106 eval "$line" 107 done 108 109 [[ ! -z $cloudhub ]] && sed -i "/CLOUDHUB=/c\CLOUDHUB=${cloudhub}" .env && echo "set cloudhub success" 110 [[ ! -z $edgename ]] && sed -i "/EDGENAME=/c\EDGENAME=${edgename}" .env && echo "set edgename success" 111 [[ ! -z $edgecore_image ]] && sed -i "/EDGECOREIMAGE=/c\EDGECOREIMAGE=${edgecore_image}" .env && echo "set edgecore_image success" 112 [[ ! -z $arch ]] && sed -i "/\<ARCH\>/c\ARCH=${arch}" .env && echo "set arch success" 113 [[ ! -z $qemu_arch ]] && sed -i "/QEMU_ARCH=/c\QEMU_ARCH=${qemu_arch}" .env && echo "set qemu_arch success" 114 [[ ! -z $certpath ]] && sed -i "/CERTPATH=/c\CERTPATH=${certpath}" .env && echo "set certpath success" 115 [[ ! -z $certfile ]] && sed -i "/CERTFILE=/c\CERTFILE=${certfile}" .env && echo "set certfile success" 116 [[ ! -z $keyfile ]] && sed -i "/KEYFILE=/c\KEYFILE=${keyfile}" .env && echo "set keyfile success" 117 } 118 119 docker_build(){ 120 eval $(sed -n '/QEMU_ARCH/p' .env) 121 122 # Prepare qemu to build images other then x86_64 on travis 123 prepare_qemu ${QEMU_ARCH} 124 125 docker-compose build 126 } 127 128 docker_save(){ 129 eval $(sed -n '/EDGECOREIMAGE/p' .env) 130 docker save -o edgecore_image.tar $EDGECOREIMAGE 131 } 132 133 docker_up(){ 134 docker-compose up -d 135 } 136 137 docker_down(){ 138 docker-compose down 139 } 140 141 docker_only_run_edge(){ 142 # This script accepts the following parameters: 143 # 144 # * mqtt 145 # * edgename 146 # * cloudhub 147 # * image 148 # 149 # Example 150 # 151 # ./run_daemon.sh only_run_edge mqtt=0.0.0.0:1883 cloudhub=0.0.0.0:10000 edgename=edge-node image="kubeedge/edgecore:latest" 152 153 ARGS=$@ 154 155 CONFIG=${ARGS#* } 156 157 for line in $CONFIG; do 158 eval "$line" 159 done 160 161 mqtt=${mqtt:-"0.0.0.0:1883"} 162 cloudhub=${cloudhub:-"0.0.0.0:10000"} 163 edgename=${edgename:-$(hostname)} 164 edgehubWebsocketUrl=wss://${cloudhub}/e632aba927ea4ac2b575ec1603d56f10/${edgename}/events 165 image=${image:-"kubeedge/edgecore:latest"} 166 containername=${containername:-"edgecore"} 167 168 docker run -d --name ${containername} --restart always \ 169 --cpu-period=50000 --cpu-quota=100000 --memory=1g --privileged \ 170 -e edgehub.websocket.certfile=/etc/kubeedge/certs/edge.crt \ 171 -e edgehub.websocket.keyfile=/etc/kubeedge/certs/edge.key \ 172 -e mqtt.server=${mqtt} \ 173 -e edgehub.websocket.url=${edgehubWebsocketUrl} \ 174 -e edged.hostname-override=${edgename} \ 175 -e edgehub.controller.node-id=${edgename} \ 176 -v /etc/kubeedge/certs:/etc/kubeedge/certs:ro \ 177 -v /var/lib/edged:/var/lib/edged \ 178 -v /var/lib/kubeedge:/var/lib/kubeedge \ 179 -v /var/run/docker.sock:/var/run/docker.sock \ 180 ${image} 181 } 182 183 prepare_qemu(){ 184 echo "PREPARE: Qemu" 185 QEMU_ARCH=${1} 186 # Prepare qemu to build non amd64 / x86_64 images 187 docker run --rm --privileged multiarch/qemu-user-static:register --reset 188 189 rm -rf tmp 190 mkdir -p tmp 191 192 pushd tmp && 193 curl -L -o qemu-${QEMU_ARCH}-static.tar.gz https://github.com/multiarch/qemu-user-static/releases/download/$QEMU_VERSION/qemu-${QEMU_ARCH}-static.tar.gz && tar xzf qemu-${QEMU_ARCH}-static.tar.gz && 194 popd 195 } 196 197 main $@