github.com/alibaba/sealer@v0.8.6-0.20220430115802-37a2bdaa8173/applications/nydus/nydusdfile/serverfile/serverstart.sh (about) 1 #!/bin/bash 2 # Copyright © 2022 Alibaba Group Holding Ltd. 3 # 4 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # you may not use this file except in compliance with the License. 6 # You may obtain a copy of the License at 7 # 8 # http://www.apache.org/licenses/LICENSE-2.0 9 # 10 # Unless required by applicable law or agreed to in writing, software 11 # distributed under the License is distributed on an "AS IS" BASIS, 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 # See the License for the specific language governing permissions and 14 # limitations under the License. 15 16 set -e 17 set -x 18 19 helpfunc() { 20 echo "Usage:" 21 echo " serverstart.sh [-i HOST] [-d DIR_LIST]" 22 echo "Description:" 23 echo " HOST: the IP of nydusdserver." 24 echo " DIR_LIST: the list of dir need to be converted to nydus blobs." 25 echo "examples:" 26 echo " serverstart.sh -i 192.168.0.2 -d /converdir/1,/converdir/2,/converdir/2" 27 exit -1 28 } 29 30 while getopts 'i:d:h' OPT; do 31 case $OPT in 32 i) HOST="$OPTARG";; 33 d) DIR_LIST="$OPTARG";; 34 h) helpfunc;; 35 ?) helpfunc;; 36 esac 37 done 38 39 nydusdconfig=' 40 {\n 41 "device": {\n 42 "backend": {\n 43 "type": "registry",\n 44 "config": {\n 45 "scheme": "http",\n 46 "host": "'${HOST}':8000",\n 47 "repo": "sealer"\n 48 }\n 49 },\n 50 "cache": {\n 51 "type": "blobcache",\n 52 "config": {\n 53 "work_dir": "./cache"\n 54 }\n 55 }\n 56 },\n 57 "mode": "direct",\n 58 "digest_validate": false,\n 59 "enable_xattr": true,\n 60 "fs_prefetch": {\n 61 "enable": true,\n 62 "threads_count": 1,\n 63 "merging_size": 131072,\n 64 "bandwidth_rate":10485760\n 65 }\n 66 }\n 67 ' 68 echo -e ${nydusdconfig} > ./httpserver.json 69 70 for DIR in $(echo "${DIR_LIST}"|sed 's/,/ /g') 71 do 72 # create nydusimages 73 F_NAME=$(basename "${DIR}") 74 echo $F_NAME 75 mkdir -p ../${F_NAME} 76 ./nydus-image create --blob-dir ./nydusblobs --bootstrap ../${F_NAME}/rootfs.meta $DIR 77 cp ./httpserver.json ../${F_NAME} 78 done 79 80 rm -rf /usr/bin/nydus-backend-proxy 81 cp -u nydus-backend-proxy /usr/bin/nydus-backend-proxy 82 # nydusd_http_server.service 83 service="[Unit]\n 84 Description=A simple HTTP server to serve a local directory as blob backend for nydusd\n 85 [Service]\n 86 TimeoutStartSec=3\n 87 Environment=\"ROCKET_CONFIG=$(pwd)/Rocket.toml\"\n 88 ExecStart=/usr/bin/nydus-backend-proxy --blobsdir $(pwd)/nydusblobs\n 89 Restart=always\n 90 [Install]\n 91 WantedBy=multi-user.target\n" 92 echo -e ${service} > /etc/systemd/system/nydusd_http_server.service 93 # start nydusd_http_server.service 94 systemctl enable nydusd_http_server.service 95 systemctl restart nydusd_http_server.service 96 97